You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2017/07/11 14:59:53 UTC
[1/2] curator git commit: close was double closing things. Also
introduce an ExceptionAccumulator
Repository: curator
Updated Branches:
refs/heads/master 34be09a44 -> 4909f57c1
close was double closing things. Also introduce an ExceptionAccumulator
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/e158bbc7
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/e158bbc7
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/e158bbc7
Branch: refs/heads/master
Commit: e158bbc75affef29828b98373e864b2c460c1f4d
Parents: 34be09a
Author: randgalt <ra...@apache.org>
Authored: Tue Jul 11 09:57:54 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue Jul 11 09:57:54 2017 -0500
----------------------------------------------------------------------
.../curator/utils/ExceptionAccumulator.java | 51 ++++++++++++++++++++
.../discovery/details/ServiceDiscoveryImpl.java | 21 +++++---
2 files changed, 64 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/e158bbc7/curator-client/src/main/java/org/apache/curator/utils/ExceptionAccumulator.java
----------------------------------------------------------------------
diff --git a/curator-client/src/main/java/org/apache/curator/utils/ExceptionAccumulator.java b/curator-client/src/main/java/org/apache/curator/utils/ExceptionAccumulator.java
new file mode 100644
index 0000000..2be2ee8
--- /dev/null
+++ b/curator-client/src/main/java/org/apache/curator/utils/ExceptionAccumulator.java
@@ -0,0 +1,51 @@
+package org.apache.curator.utils;
+
+import com.google.common.base.Throwables;
+
+/**
+ * Utility to accumulate multiple potential exceptions into one that
+ * is thrown at the end
+ */
+public class ExceptionAccumulator
+{
+ private volatile Throwable mainEx = null;
+
+ /**
+ * If there is an accumulated exception, throw it
+ */
+ public void propagate()
+ {
+ if ( mainEx != null )
+ {
+ Throwables.propagate(mainEx);
+ }
+ }
+
+ /**
+ * Add an exception into the accumulated exceptions. Note:
+ * if the exception is {@link java.lang.InterruptedException}
+ * then <code>Thread.currentThread().interrupt()</code> is called.
+ *
+ * @param e the exception
+ */
+ public void add(Throwable e)
+ {
+ if ( e instanceof InterruptedException )
+ {
+ if ( mainEx != null )
+ {
+ e.addSuppressed(mainEx);
+ }
+ Thread.currentThread().interrupt();
+ }
+
+ if ( mainEx == null )
+ {
+ mainEx = e;
+ }
+ else
+ {
+ mainEx.addSuppressed(e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/curator/blob/e158bbc7/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
index 762c9a8..476705c 100644
--- a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
+++ b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/details/ServiceDiscoveryImpl.java
@@ -31,6 +31,7 @@ import org.apache.curator.framework.recipes.cache.NodeCacheListener;
import org.apache.curator.framework.state.ConnectionState;
import org.apache.curator.framework.state.ConnectionStateListener;
import org.apache.curator.utils.CloseableUtils;
+import org.apache.curator.utils.ExceptionAccumulator;
import org.apache.curator.utils.ThreadUtils;
import org.apache.curator.utils.ZKPaths;
import org.apache.curator.x.discovery.ServiceCache;
@@ -39,7 +40,6 @@ import org.apache.curator.x.discovery.ServiceDiscovery;
import org.apache.curator.x.discovery.ServiceInstance;
import org.apache.curator.x.discovery.ServiceProvider;
import org.apache.curator.x.discovery.ServiceProviderBuilder;
-import org.apache.curator.x.discovery.ServiceType;
import org.apache.curator.x.discovery.strategies.RoundRobinStrategy;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
@@ -77,9 +77,12 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
log.debug("Re-registering due to reconnection");
reRegisterServices();
}
+ catch (InterruptedException ex)
+ {
+ Thread.currentThread().interrupt();
+ }
catch ( Exception e )
{
- ThreadUtils.checkInterrupted(e);
log.error("Could not re-register instances after reconnection", e);
}
}
@@ -140,10 +143,7 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
@Override
public void close() throws IOException
{
- for ( ServiceCache<T> cache : Lists.newArrayList(caches) )
- {
- CloseableUtils.closeQuietly(cache);
- }
+ ExceptionAccumulator accumulator = new ExceptionAccumulator();
for ( ServiceProvider<T> provider : Lists.newArrayList(providers) )
{
CloseableUtils.closeQuietly(provider);
@@ -161,12 +161,13 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
}
catch ( Exception e )
{
- ThreadUtils.checkInterrupted(e);
+ accumulator.add(e);
log.error("Could not unregister instance: " + entry.service.getName(), e);
}
}
client.getConnectionStateListenable().removeListener(connectionStateListener);
+ accumulator.propagate();
}
/**
@@ -469,9 +470,13 @@ public class ServiceDiscoveryImpl<T> implements ServiceDiscovery<T>
{
nodeCache.start(true);
}
+ catch ( InterruptedException e)
+ {
+ Thread.currentThread().interrupt();
+ return null;
+ }
catch ( Exception e )
{
- ThreadUtils.checkInterrupted(e);
log.error("Could not start node cache for: " + instance, e);
}
NodeCacheListener listener = new NodeCacheListener()
[2/2] curator git commit: Add comment to close to make clear that the
provider should close its caches
Posted by ra...@apache.org.
Add comment to close to make clear that the provider should close its caches
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/4909f57c
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/4909f57c
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/4909f57c
Branch: refs/heads/master
Commit: 4909f57c172c3f90f9aedeac07772d228a9c948c
Parents: e158bbc
Author: randgalt <ra...@apache.org>
Authored: Tue Jul 11 09:59:36 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Tue Jul 11 09:59:36 2017 -0500
----------------------------------------------------------------------
.../java/org/apache/curator/x/discovery/ServiceProvider.java | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/4909f57c/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
----------------------------------------------------------------------
diff --git a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
index d606649..f542ed3 100644
--- a/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
+++ b/curator-x-discovery/src/main/java/org/apache/curator/x/discovery/ServiceProvider.java
@@ -21,6 +21,7 @@ package org.apache.curator.x.discovery;
import org.apache.curator.x.discovery.details.InstanceProvider;
import java.io.Closeable;
+import java.io.IOException;
import java.util.Collection;
/**
@@ -61,4 +62,10 @@ public interface ServiceProvider<T> extends Closeable
* @param instance instance that had an error
*/
public void noteError(ServiceInstance<T> instance);
+
+ /**
+ * Close the provider. Note: it's the provider's responsibility to close any caches it manages
+ */
+ @Override
+ void close() throws IOException;
}