cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amic...@apache.org
Subject svn commit: r1539983 - /cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
Date Fri, 08 Nov 2013 11:16:44 GMT
Author: amichai
Date: Fri Nov  8 11:16:44 2013
New Revision: 1539983

URL: http://svn.apache.org/r1539983
Log:
Fix ZooKeeperDiscovery service and memory leaks due to starting multiple times in a row

Modified:
    cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java

Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java?rev=1539983&r1=1539982&r2=1539983&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
(original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/ZooKeeperDiscovery.java
Fri Nov  8 11:16:44 2013
@@ -49,6 +49,7 @@ public class ZooKeeperDiscovery implemen
     private InterfaceMonitorManager imManager;
     private ZooKeeper zk;
     private boolean closed;
+    private boolean started;
 
     private Dictionary<String , ?> curConfiguration;
 
@@ -73,18 +74,27 @@ public class ZooKeeperDiscovery implemen
         if (closed) {
             return;
         }
+        if (started) {
+            // we must be re-entrant, i.e. can be called when already started
+            LOG.debug("ZookeeperDiscovery already started");
+            return;
+        }
         LOG.debug("starting ZookeeperDiscovery");
         endpointListenerFactory = new PublishingEndpointListenerFactory(zk, bctx);
         endpointListenerFactory.start();
         imManager = new InterfaceMonitorManager(bctx, zk);
         endpointListenerTracker = new EndpointListenerTracker(bctx, imManager); 
         endpointListenerTracker.open();
+        started = true;
     }
 
     public synchronized void stop(boolean close) {
+        if (started) {
+            LOG.debug("stopping ZookeeperDiscovery");
+        }
+        started = false;
         closed |= close;
         if (endpointListenerFactory != null) {
-            LOG.debug("stopping ZookeeperDiscovery");
             endpointListenerFactory.stop();
         }
         if (endpointListenerTracker != null) {
@@ -114,15 +124,18 @@ public class ZooKeeperDiscovery implemen
         try {
             zk = new ZooKeeper(host + ":" + port, timeout, this);
         } catch (IOException e) {
-            LOG.error("Failed to start the Zookeeper Discovery component.", e);
+            LOG.error("Failed to start the ZooKeeper Discovery component.", e);
         }
     }
 
     /* Callback for ZooKeeper */
     public void process(WatchedEvent event) {
+        LOG.debug("got ZooKeeper event " + event);
         switch (event.getState()) {
         case SyncConnected:
             LOG.info("Connection to ZooKeeper established");
+            // this event can be triggered more than once in a row (e.g. after Disconnected
event),
+            // so we must be re-entrant here
             start();
             break;
 



Mime
View raw message