This is an automated email from the ASF dual-hosted git repository.
ayegorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 3b53b6f Use try with resource to optimize code
3b53b6f is described below
commit 3b53b6f671d08a4545249933e442475e142cca11
Author: Wenjun Ruan <[email protected]>
AuthorDate: Tue Sep 28 04:35:08 2021 +0800
Use try with resource to optimize code
Descriptions of the changes in this PR:
### Motivation
Optimize code
### Changes
1. Use try with resource to optimize close
2. remove isDebugEnabled
Reviewers: Enrico Olivelli <[email protected]>, Andrey Yegorov <None>
This closes #2783 from ruanwenjun/dev_wenjun_optimizeClosable
---
.../apache/bookkeeper/util/LocalBookKeeper.java | 31 +++++++---------------
1 file changed, 10 insertions(+), 21 deletions(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
index 0e87e01..67cf0fa 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
@@ -497,27 +497,16 @@ public class LocalBookKeeper {
String host = split[0];
int port = Integer.parseInt(split[1]);
while (true) {
- try {
- Socket sock = new Socket(host, port);
- BufferedReader reader = null;
- try {
- OutputStream outstream = sock.getOutputStream();
- outstream.write("stat".getBytes(UTF_8));
- outstream.flush();
-
- reader =
- new BufferedReader(
- new InputStreamReader(sock.getInputStream(),
UTF_8));
- String line = reader.readLine();
- if (line != null && line.startsWith("Zookeeper version:"))
{
- LOG.info("Server UP");
- return true;
- }
- } finally {
- sock.close();
- if (reader != null) {
- reader.close();
- }
+ try (Socket sock = new Socket(host, port);
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(sock.getInputStream(), UTF_8))) {
+ OutputStream outstream = sock.getOutputStream();
+ outstream.write("stat".getBytes(UTF_8));
+ outstream.flush();
+
+ String line = reader.readLine();
+ if (line != null && line.startsWith("Zookeeper version:")) {
+ LOG.info("Server UP");
+ return true;
}
} catch (IOException e) {
// ignore as this is expected