You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2013/12/20 14:10:03 UTC

git commit: CAMEL-7085 close the zookeeper connection when the endpoint is closed

Updated Branches:
  refs/heads/master ab39bdab3 -> cb79f67ba


CAMEL-7085 close the zookeeper connection when the endpoint is closed


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

Branch: refs/heads/master
Commit: cb79f67baa6e6e50f585bf6f6c3c82b9f45bfca5
Parents: ab39bda
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Dec 20 21:09:39 2013 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Dec 20 21:09:39 2013 +0800

----------------------------------------------------------------------
 .../camel/component/zookeeper/ZooKeeperConsumer.java |  2 --
 .../camel/component/zookeeper/ZooKeeperEndpoint.java |  8 ++++++++
 .../camel/component/zookeeper/ZookeeperProducer.java | 15 ++++++++++++---
 3 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cb79f67b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
index 8b9be64..0c43de1 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperConsumer.java
@@ -78,12 +78,10 @@ public class ZooKeeperConsumer extends DefaultConsumer {
     protected void doStop() throws Exception {
         super.doStop();
         shuttingDown = true;
-        connection = connectionManager.getConnection();
         if (log.isTraceEnabled()) {
             log.trace(String.format("Shutting down zookeeper consumer of '%s'", configuration.getPath()));
         }
         executor.shutdown();
-        connectionManager.shutdown();
     }
 
     private void initializeConsumer() {

http://git-wip-us.apache.org/repos/asf/camel/blob/cb79f67b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperEndpoint.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperEndpoint.java
index 5200366..8233dee 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperEndpoint.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZooKeeperEndpoint.java
@@ -204,5 +204,13 @@ public class ZooKeeperEndpoint extends DefaultEndpoint {
     public void setSendEmptyMessageOnDelete(boolean sendEmptyMessageOnDelete) {
         getConfiguration().setSendEmptyMessageOnDelete(sendEmptyMessageOnDelete);
     }
+    
+    @Override
+    protected void doStop() throws Exception {
+        if (connectionManager != null) {
+            // It releases the zookeeper connection when calling the shutdown method
+            connectionManager.shutdown();
+        }
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/cb79f67b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZookeeperProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZookeeperProducer.java b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZookeeperProducer.java
index f3e77d9..a9b84dc 100644
--- a/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZookeeperProducer.java
+++ b/components/camel-zookeeper/src/main/java/org/apache/camel/component/zookeeper/ZookeeperProducer.java
@@ -55,6 +55,8 @@ public class ZookeeperProducer extends DefaultProducer {
     private ZooKeeperConfiguration configuration;
 
     private ZooKeeperConnectionManager zkm;
+    
+    private ZooKeeper connection;
 
     public ZookeeperProducer(ZooKeeperEndpoint endpoint) {
         super(endpoint);
@@ -63,8 +65,7 @@ public class ZookeeperProducer extends DefaultProducer {
     }
 
     public void process(Exchange exchange) throws Exception {
-
-        ZooKeeper connection = zkm.getConnection();
+        
         ProductionContext context = new ProductionContext(connection, exchange);
 
         String operation = exchange.getIn().getHeader(ZooKeeperMessage.ZOOKEEPER_OPERATION, String.class);
@@ -99,6 +100,15 @@ public class ZookeeperProducer extends DefaultProducer {
                 asynchronouslySetDataOnNode(connection, context);
             }
         }
+        
+    }
+    
+    @Override
+    protected void doStart() throws Exception {
+        connection = zkm.getConnection();
+        if (log.isTraceEnabled()) {
+            log.trace(String.format("Starting zookeeper producer of '%s'", configuration.getPath()));
+        }
     }
 
     @Override
@@ -107,7 +117,6 @@ public class ZookeeperProducer extends DefaultProducer {
         if (log.isTraceEnabled()) {
             log.trace(String.format("Shutting down zookeeper producer of '%s'", configuration.getPath()));
         }
-        zkm.shutdown();
     }
 
     private void asynchronouslyDeleteNode(ZooKeeper connection, ProductionContext context) {