aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] aries-rsa git commit: [ARIES-1778] Improved exception handling
Date Mon, 12 Feb 2018 17:02:51 GMT
Repository: aries-rsa
Updated Branches:
  refs/heads/master 4d8cdecb0 -> d5bfc3769


[ARIES-1778] Improved exception handling


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

Branch: refs/heads/master
Commit: de9f1a4a65f44902da2d1f0c6c370c6db5b0e463
Parents: 4d8cdec
Author: Christian Schneider <cschneid@adobe.com>
Authored: Mon Feb 12 17:57:30 2018 +0100
Committer: Christian Schneider <cschneid@adobe.com>
Committed: Mon Feb 12 17:57:30 2018 +0100

----------------------------------------------------------------------
 .../repository/ZookeeperEndpointRepository.java | 40 ++++++++++----------
 1 file changed, 21 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/de9f1a4a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepository.java
----------------------------------------------------------------------
diff --git a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepository.java
b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepository.java
index 057aff4..dcfab34 100644
--- a/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepository.java
+++ b/discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/repository/ZookeeperEndpointRepository.java
@@ -14,6 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.apache.aries.rsa.discovery.endpoint.EndpointDescriptionParser;
 import org.apache.zookeeper.CreateMode;
 import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.KeeperException.ConnectionLossException;
 import org.apache.zookeeper.KeeperException.NoNodeException;
 import org.apache.zookeeper.KeeperException.NodeExistsException;
 import org.apache.zookeeper.KeeperException.SessionExpiredException;
@@ -129,7 +130,7 @@ public class ZookeeperEndpointRepository implements Closeable, Watcher
{
 
     @Override
     public void close() throws IOException {
-
+        nodes.clear();
     }
 
     private void createBasePath() throws KeeperException, InterruptedException {
@@ -145,10 +146,14 @@ public class ZookeeperEndpointRepository implements Closeable, Watcher
{
         }
     }
 
+    /**
+     * TODO Check if we handle connection losses correctly
+     * @param path
+     */
     private void watchRecursive(String path) {
         LOG.debug("Watching {}", path);
-        handleZNodeChanged(path);
         try {
+            handleZNodeChanged(path);
             List<String> children = zk.getChildren(path, this);
             if (children == null) {
                 return;
@@ -157,8 +162,12 @@ public class ZookeeperEndpointRepository implements Closeable, Watcher
{
                 String childPath = (path.endsWith("/") ? path : path + "/") + child;
                 watchRecursive(childPath);
             }
+        } catch (NoNodeException e) {
+            // Happens when a node was removed
+            LOG.debug(e.getMessage(), e);
+        } catch (ConnectionLossException e) {
+            LOG.debug(e.getMessage(), e);
         } catch (SessionExpiredException e) {
-            // TODO Can we safely ignore these?
             LOG.debug(e.getMessage(), e);
         } catch (Exception e) {
             LOG.info(e.getMessage(), e);
@@ -205,22 +214,15 @@ public class ZookeeperEndpointRepository implements Closeable, Watcher
{
         }
     }
 
-    private void handleZNodeChanged(String path) {
-        try {
-            Stat stat = new Stat();
-            byte[] data = zk.getData(path, false, stat);
-            if (data == null || data.length == 0) {
-                return;
-            }
-            EndpointDescription endpoint = parser.readEndpoint(new ByteArrayInputStream(data));
-            if (endpoint != null) {
-               handleChanged(path, endpoint);
-            }
-        } catch (SessionExpiredException e) {
-            // TODO Can we safely ignore these?
-            LOG.debug(e.getMessage(), e);
-        } catch (Exception e) {
-            LOG.info(e.getMessage(), e);
+    private void handleZNodeChanged(String path) throws KeeperException, InterruptedException
{
+        Stat stat = new Stat();
+        byte[] data = zk.getData(path, false, stat);
+        if (data == null || data.length == 0) {
+            return;
+        }
+        EndpointDescription endpoint = parser.readEndpoint(new ByteArrayInputStream(data));
+        if (endpoint != null) {
+            handleChanged(path, endpoint);
         }
     }
 


Mime
View raw message