zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject zookeeper git commit: ZOOKEEPER-2697: Handle graceful stop of ZookKeeper client
Date Mon, 01 May 2017 15:19:19 GMT
Repository: zookeeper
Updated Branches:
  refs/heads/master 017ca1a24 -> acfc471ec


ZOOKEEPER-2697: Handle graceful stop of ZookKeeper client

Add a ZooKeeper.close(int timeout) method which waits for internal resources to be released

Author: eolivelli <eolivelli@apache.org>

Reviewers: Michael Han <hanm@apache.org>

Closes #222 from eolivelli/ZOOKEEPER-2697-close-with-timeout


Project: http://git-wip-us.apache.org/repos/asf/zookeeper/repo
Commit: http://git-wip-us.apache.org/repos/asf/zookeeper/commit/acfc471e
Tree: http://git-wip-us.apache.org/repos/asf/zookeeper/tree/acfc471e
Diff: http://git-wip-us.apache.org/repos/asf/zookeeper/diff/acfc471e

Branch: refs/heads/master
Commit: acfc471eca0aab57707b59ed8d19221360d19b85
Parents: 017ca1a
Author: eolivelli <eolivelli@apache.org>
Authored: Mon May 1 08:19:15 2017 -0700
Committer: Michael Han <hanm@apache.org>
Committed: Mon May 1 08:19:15 2017 -0700

----------------------------------------------------------------------
 .../main/org/apache/zookeeper/ZooKeeper.java    | 21 ++++++++++++++++++++
 .../apache/zookeeper/test/AsyncHammerTest.java  |  3 +--
 .../org/apache/zookeeper/test/ClientTest.java   |  7 +++----
 3 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/acfc471e/src/java/main/org/apache/zookeeper/ZooKeeper.java
----------------------------------------------------------------------
diff --git a/src/java/main/org/apache/zookeeper/ZooKeeper.java b/src/java/main/org/apache/zookeeper/ZooKeeper.java
index 193ceb9..38eb032 100644
--- a/src/java/main/org/apache/zookeeper/ZooKeeper.java
+++ b/src/java/main/org/apache/zookeeper/ZooKeeper.java
@@ -1298,6 +1298,11 @@ public class ZooKeeper implements AutoCloseable {
      * <p>
      * Added in 3.5.3: <a href="https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html">try-with-resources</a>
      * may be used instead of calling close directly.
+     * </p>
+     * <p>
+     * This method does not wait for all internal threads to exit.
+     * Use the {@link #close(int) } method to wait for all resources to be released
+     * </p>
      *
      * @throws InterruptedException
      */
@@ -1325,6 +1330,22 @@ public class ZooKeeper implements AutoCloseable {
     }
 
     /**
+     * Close this client object as the {@link #close() } method.
+     * This method will wait for internal resources to be released.
+     *
+     * @param waitForShutdownTimeoutMs timeout (in milliseconds) to wait for resources to
be released.
+     * Use zero or a negative value to skip the wait
+     * @throws InterruptedException
+     * @return true if waitForShutdownTimeout is greater than zero and all of the resources
have been released
+     *
+     * @since 3.5.4
+     */
+    public boolean close(int waitForShutdownTimeoutMs) throws InterruptedException {
+        close();
+        return testableWaitForShutdown(waitForShutdownTimeoutMs);
+    }
+
+    /**
      * Prepend the chroot to the client path (if present). The expectation of
      * this function is that the client path has been validated before this
      * function is called

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/acfc471e/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java b/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
index ebfc963..1ccdc0b 100644
--- a/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
+++ b/src/java/test/org/apache/zookeeper/test/AsyncHammerTest.java
@@ -103,8 +103,7 @@ public class AsyncHammerTest extends ZKTestCase
             } finally {
                 if (zk != null) {
                     try {
-                        zk.close();
-                        if (!zk.testableWaitForShutdown(CONNECTION_TIMEOUT)) {
+                        if (!zk.close(CONNECTION_TIMEOUT)) {
                             failed = true;
                             LOG.error("Client did not shutdown");
                         }

http://git-wip-us.apache.org/repos/asf/zookeeper/blob/acfc471e/src/java/test/org/apache/zookeeper/test/ClientTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/test/ClientTest.java b/src/java/test/org/apache/zookeeper/test/ClientTest.java
index d33223d..1aaef75 100644
--- a/src/java/test/org/apache/zookeeper/test/ClientTest.java
+++ b/src/java/test/org/apache/zookeeper/test/ClientTest.java
@@ -47,6 +47,7 @@ import org.apache.zookeeper.proto.ReplyHeader;
 import org.apache.zookeeper.proto.RequestHeader;
 import org.apache.zookeeper.server.PrepRequestProcessor;
 import org.apache.zookeeper.server.util.OSMXBean;
+import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
 import org.junit.Assert;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -113,8 +114,7 @@ public class ClientTest extends ClientBase {
             LOG.info("{}",zk.testableRemoteSocketAddress());
             LOG.info("{}",zk.toString());
         } finally {
-            zk.close();
-            zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
+            zk.close(CONNECTION_TIMEOUT);
             LOG.info("{}",zk.testableLocalSocketAddress());
             LOG.info("{}",zk.testableRemoteSocketAddress());
             LOG.info("{}",zk.toString());
@@ -759,11 +759,10 @@ public class ClientTest extends ClientBase {
             try {
                 for (; current < count; current++) {
                     TestableZooKeeper zk = createClient();
-                    zk.close();
                     // we've asked to close, wait for it to finish closing
                     // all the sub-threads otw the selector may not be
                     // closed when we check (false positive on test Assert.failure
-                    zk.testableWaitForShutdown(CONNECTION_TIMEOUT);
+                    zk.close(CONNECTION_TIMEOUT);
                 }
             } catch (Throwable t) {
                 LOG.error("test Assert.failed", t);


Mime
View raw message