zookeeper-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] BELUGABEHR commented on a change in pull request #823: ZOOKEEPER-2694:sync CLI command does not wait for result from server
Date Thu, 04 Apr 2019 13:32:33 GMT
BELUGABEHR commented on a change in pull request #823: ZOOKEEPER-2694:sync CLI command does
not wait for result from server
URL: https://github.com/apache/zookeeper/pull/823#discussion_r272180091
 
 

 ##########
 File path: zookeeper-server/src/main/java/org/apache/zookeeper/cli/SyncCommand.java
 ##########
 @@ -55,18 +61,27 @@ public CliCommand parse(String[] cmdArgs) throws CliParseException {
     @Override
     public boolean exec() throws CliException {
         String path = args[1];
+        CompletableFuture<Integer> cf = new CompletableFuture<>();
+
         try {
             zk.sync(path, new AsyncCallback.VoidCallback() {
-
                 public void processResult(int rc, String path, Object ctx) {
-                    out.println("Sync returned " + rc);
+                    cf.complete(rc);
                 }
             }, null);
+
+            try {
+                int resultCode = cf.get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+                out.println("Sync returned " + resultCode);
+            } catch (TimeoutException ex) {
+                out.println("Sync is timeout within " +  CONNECTION_TIMEOUT + " ms");
+            }
         } catch (IllegalArgumentException ex) {
             throw new MalformedPathException(ex.getMessage());
+        } catch (InterruptedException | ExecutionException ex) {
 
 Review comment:
   I think it's always best to do it the "right" way... it will insulate the code from changes
later when it may become needed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message