Repository: curator
Updated Branches:
  refs/heads/master 5cb22be3d -> d4547b4f4


CURATOR-408 Handle graceful close of ZookKeeper client waiting for all 
resources to be released


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

Branch: refs/heads/master
Commit: fe2c7c4cd606c0cf4bc4fab15deedc0f4c33ea0e
Parents: 9383aa3
Author: Enrico Olivelli <eolive...@apache.org>
Authored: Mon Jun 11 21:28:30 2018 +0200
Committer: Enrico Olivelli <eolive...@apache.org>
Committed: Mon Jun 11 21:28:30 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/curator/ConnectionState.java |  9 ++++++---
 .../apache/curator/CuratorZookeeperClient.java   | 19 +++++++++++++++----
 .../java/org/apache/curator/HandleHolder.java    | 10 +++++-----
 .../state/TestConnectionStateManager.java        | 18 ++++++++++++++++++
 pom.xml                                          |  2 +-
 5 files changed, 45 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/fe2c7c4c/curator-client/src/main/java/org/apache/curator/ConnectionState.java
----------------------------------------------------------------------
diff --git 
a/curator-client/src/main/java/org/apache/curator/ConnectionState.java 
b/curator-client/src/main/java/org/apache/curator/ConnectionState.java
index b5af9f2..24b9948 100644
--- a/curator-client/src/main/java/org/apache/curator/ConnectionState.java
+++ b/curator-client/src/main/java/org/apache/curator/ConnectionState.java
@@ -112,14 +112,17 @@ class ConnectionState implements Watcher, Closeable
     }
 
     @Override
-    public void close() throws IOException
-    {
+    public void close() throws IOException {
+        close(0);
+    }
+    
+    public void close(int waitForShutdownTimeoutMs) throws IOException {
         log.debug("Closing");
 
         CloseableUtils.closeQuietly(ensembleProvider);
         try
         {
-            zooKeeper.closeAndClear();
+            zooKeeper.closeAndClear(waitForShutdownTimeoutMs);
         }
         catch ( Exception e )
         {

http://git-wip-us.apache.org/repos/asf/curator/blob/fe2c7c4c/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
----------------------------------------------------------------------
diff --git 
a/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java 
b/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
index b7bb33a..dd3ae82 100644
--- 
a/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
+++ 
b/curator-client/src/main/java/org/apache/curator/CuratorZookeeperClient.java
@@ -213,18 +213,29 @@ public class CuratorZookeeperClient implements Closeable
 
         state.start();
     }
-
+    
     /**
      * Close the client
      */
-    public void close()
+    public void close() {
+        close(0);
+    }
+            
+    /**
+     * 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.
+     */
+    public void close(int waitForShutdownTimeoutMs)
     {
-        log.debug("Closing");
+        log.debug("Closing, waitForShutdownTimeoutMs {}", 
waitForShutdownTimeoutMs);
 
         started.set(false);
         try
         {
-            state.close();
+            state.close(waitForShutdownTimeoutMs);
         }
         catch ( IOException e )
         {

http://git-wip-us.apache.org/repos/asf/curator/blob/fe2c7c4c/curator-client/src/main/java/org/apache/curator/HandleHolder.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/HandleHolder.java 
b/curator-client/src/main/java/org/apache/curator/HandleHolder.java
index 98b39ce..33250d8 100644
--- a/curator-client/src/main/java/org/apache/curator/HandleHolder.java
+++ b/curator-client/src/main/java/org/apache/curator/HandleHolder.java
@@ -73,15 +73,15 @@ class HandleHolder
         return ((helperConnectionString != null) && 
!ensembleProvider.getConnectionString().equals(helperConnectionString)) ? 
helperConnectionString : null;
     }
 
-    void closeAndClear() throws Exception
+    void closeAndClear(int timeout) throws Exception
     {
-        internalClose();
+        internalClose(timeout);
         helper = null;
     }
 
     void closeAndReset() throws Exception
     {
-        internalClose();
+        internalClose(0);
 
         // first helper is synchronized when getZooKeeper is called. 
Subsequent calls
         // are not synchronized.
@@ -140,7 +140,7 @@ class HandleHolder
         };
     }
 
-    private void internalClose() throws Exception
+    private void internalClose(int waitForShutdownTimeoutMs) throws Exception
     {
         try
         {
@@ -155,7 +155,7 @@ class HandleHolder
                     }
                 };
                 zooKeeper.register(dummyWatcher);   // clear the default 
watcher so that no new events get processed by mistake
-                zooKeeper.close();
+                zooKeeper.close(waitForShutdownTimeoutMs);
             }
         }
         catch ( InterruptedException dummy )

http://git-wip-us.apache.org/repos/asf/curator/blob/fe2c7c4c/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
----------------------------------------------------------------------
diff --git 
a/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
 
b/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
index e313c56..97ea941 100644
--- 
a/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
+++ 
b/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
@@ -1,3 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.curator.framework.state;
 
 import com.google.common.collect.Queues;

http://git-wip-us.apache.org/repos/asf/curator/blob/fe2c7c4c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c75912b..dd4abdd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,7 +59,7 @@
         <jdk-version>1.7</jdk-version>
 
         <!-- versions -->
-        <zookeeper-version>3.5.3-beta</zookeeper-version>
+        <zookeeper-version>3.5.4-beta</zookeeper-version>
         
<maven-project-info-reports-plugin-version>2.9</maven-project-info-reports-plugin-version>
         <maven-bundle-plugin-version>3.2.0</maven-bundle-plugin-version>
         <maven-javadoc-plugin-version>2.10.4</maven-javadoc-plugin-version>

Reply via email to