camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7085 close the zookeeper connection when the endpoint is closed
Date Fri, 20 Dec 2013 13:13:07 GMT
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/c321cb88
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c321cb88
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c321cb88

Branch: refs/heads/camel-2.11.x
Commit: c321cb881422b2cb2b359c06bab5afc909db8448
Parents: 30786f5
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Dec 20 21:09:39 2013 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Dec 20 21:12:46 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/c321cb88/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 f5f7839..12fd0ed 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/c321cb88/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 369d699..a7c9ca1 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
@@ -187,5 +187,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/c321cb88/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 e7cdb1d..98d99af 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)
{


Mime
View raw message