renamed to clarify meaning
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/7aa371e9 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/7aa371e9 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/7aa371e9 Branch: refs/heads/CURATOR-3.0 Commit: 7aa371e9514e1a8227d1ed93833bd9e6238c60ed Parents: 940e845 Author: randgalt <randg...@apache.org> Authored: Sun Sep 6 23:51:26 2015 -0700 Committer: randgalt <randg...@apache.org> Committed: Sun Sep 6 23:51:26 2015 -0700 ---------------------------------------------------------------------- .../curator/framework/CuratorFramework.java | 4 ++-- .../framework/CuratorFrameworkFactory.java | 18 +++++++++--------- .../framework/imps/CuratorFrameworkImpl.java | 12 ++++++------ .../state/ConnectionStateErrorPolicy.java | 20 ++++++++++++++++++++ .../curator/framework/state/ErrorPolicy.java | 20 -------------------- .../SessionConnectionStateErrorPolicy.java | 13 +++++++++++++ .../framework/state/SessionErrorPolicy.java | 13 ------------- .../StandardConnectionStateErrorPolicy.java | 14 ++++++++++++++ .../framework/state/StandardErrorPolicy.java | 14 -------------- .../framework/recipes/leader/LeaderLatch.java | 4 ++-- .../leader/LeaderSelectorListenerAdapter.java | 2 +- .../recipes/leader/TestLeaderLatch.java | 10 +++++----- .../recipes/leader/TestLeaderSelector.java | 9 ++++----- 13 files changed, 76 insertions(+), 77 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java index d755d28..3d197a0 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFramework.java @@ -28,7 +28,7 @@ import org.apache.curator.framework.api.transaction.TransactionOp; import org.apache.curator.framework.imps.CuratorFrameworkState; import org.apache.curator.framework.listen.Listenable; import org.apache.curator.framework.state.ConnectionStateListener; -import org.apache.curator.framework.state.ErrorPolicy; +import org.apache.curator.framework.state.ConnectionStateErrorPolicy; import org.apache.curator.utils.EnsurePath; import org.apache.zookeeper.Watcher; @@ -304,5 +304,5 @@ public interface CuratorFramework extends Closeable * * @return error policy */ - public ErrorPolicy getErrorPolicy(); + public ConnectionStateErrorPolicy getConnectionStateErrorPolicy(); } http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java index 2b01b30..4db6d36 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java @@ -34,8 +34,8 @@ import org.apache.curator.framework.imps.CuratorFrameworkImpl; import org.apache.curator.framework.imps.CuratorTempFrameworkImpl; import org.apache.curator.framework.imps.DefaultACLProvider; import org.apache.curator.framework.imps.GzipCompressionProvider; -import org.apache.curator.framework.state.ErrorPolicy; -import org.apache.curator.framework.state.StandardErrorPolicy; +import org.apache.curator.framework.state.ConnectionStateErrorPolicy; +import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.utils.DefaultZookeeperFactory; import org.apache.curator.utils.ZookeeperFactory; @@ -123,7 +123,7 @@ public class CuratorFrameworkFactory private ACLProvider aclProvider = DEFAULT_ACL_PROVIDER; private boolean canBeReadOnly = false; private boolean useContainerParentsIfAvailable = true; - private ErrorPolicy errorPolicy = new StandardErrorPolicy(); + private ConnectionStateErrorPolicy connectionStateErrorPolicy = new StandardConnectionStateErrorPolicy(); private ConnectionHandlingPolicy connectionHandlingPolicy = Boolean.getBoolean("curator-use-classic-connection-handling") ? new ClassicConnectionHandlingPolicy() : new StandardConnectionHandlingPolicy(); /** @@ -353,15 +353,15 @@ public class CuratorFrameworkFactory } /** - * Set the error policy to use. The default is {@link StandardErrorPolicy} + * Set the error policy to use. The default is {@link StandardConnectionStateErrorPolicy} * * @since 3.0.0 - * @param errorPolicy new error policy + * @param connectionStateErrorPolicy new error policy * @return this */ - public Builder errorPolicy(ErrorPolicy errorPolicy) + public Builder errorPolicy(ConnectionStateErrorPolicy connectionStateErrorPolicy) { - this.errorPolicy = errorPolicy; + this.connectionStateErrorPolicy = connectionStateErrorPolicy; return this; } @@ -467,9 +467,9 @@ public class CuratorFrameworkFactory return useContainerParentsIfAvailable; } - public ErrorPolicy getErrorPolicy() + public ConnectionStateErrorPolicy getConnectionStateErrorPolicy() { - return errorPolicy; + return connectionStateErrorPolicy; } public ConnectionHandlingPolicy getConnectionHandlingPolicy() http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java index 7651731..848ccf2 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java @@ -40,7 +40,7 @@ import org.apache.curator.framework.listen.ListenerContainer; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.curator.framework.state.ConnectionStateManager; -import org.apache.curator.framework.state.ErrorPolicy; +import org.apache.curator.framework.state.ConnectionStateErrorPolicy; import org.apache.curator.utils.DebugUtils; import org.apache.curator.utils.EnsurePath; import org.apache.curator.utils.ThreadUtils; @@ -85,7 +85,7 @@ public class CuratorFrameworkImpl implements CuratorFramework private final NamespaceFacadeCache namespaceFacadeCache; private final NamespaceWatcherMap namespaceWatcherMap = new NamespaceWatcherMap(this); private final boolean useContainerParentsIfAvailable; - private final ErrorPolicy errorPolicy; + private final ConnectionStateErrorPolicy connectionStateErrorPolicy; private final AtomicLong currentInstanceIndex = new AtomicLong(-1); private final InternalConnectionHandler internalConnectionHandler; @@ -140,7 +140,7 @@ public class CuratorFrameworkImpl implements CuratorFramework aclProvider = builder.getAclProvider(); state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT); useContainerParentsIfAvailable = builder.useContainerParentsIfAvailable(); - errorPolicy = Preconditions.checkNotNull(builder.getErrorPolicy(), "errorPolicy cannot be null"); + connectionStateErrorPolicy = Preconditions.checkNotNull(builder.getConnectionStateErrorPolicy(), "errorPolicy cannot be null"); byte[] builderDefaultData = builder.getDefaultData(); defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0]; @@ -214,7 +214,7 @@ public class CuratorFrameworkImpl implements CuratorFramework state = parent.state; authInfos = parent.authInfos; useContainerParentsIfAvailable = parent.useContainerParentsIfAvailable; - errorPolicy = parent.errorPolicy; + connectionStateErrorPolicy = parent.connectionStateErrorPolicy; internalConnectionHandler = parent.internalConnectionHandler; } @@ -260,9 +260,9 @@ public class CuratorFrameworkImpl implements CuratorFramework } @Override - public ErrorPolicy getErrorPolicy() + public ConnectionStateErrorPolicy getConnectionStateErrorPolicy() { - return errorPolicy; + return connectionStateErrorPolicy; } @Override http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateErrorPolicy.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateErrorPolicy.java b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateErrorPolicy.java new file mode 100644 index 0000000..1b77995 --- /dev/null +++ b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateErrorPolicy.java @@ -0,0 +1,20 @@ +package org.apache.curator.framework.state; + +/** + * Recipes should use the configured error policy to decide how to handle + * errors such as {@link ConnectionState} changes. + * + * @since 3.0.0 + */ +public interface ConnectionStateErrorPolicy +{ + /** + * Returns true if the given state should cause the recipe to + * act as though the connection has been lost. i.e. locks should + * exit, etc. + * + * @param state the state + * @return true/false + */ + boolean isErrorState(ConnectionState state); +} http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/state/ErrorPolicy.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/ErrorPolicy.java b/curator-framework/src/main/java/org/apache/curator/framework/state/ErrorPolicy.java deleted file mode 100644 index 73fc99d..0000000 --- a/curator-framework/src/main/java/org/apache/curator/framework/state/ErrorPolicy.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apache.curator.framework.state; - -/** - * Recipes should use the configured error policy to decide how to handle - * errors such as {@link ConnectionState} changes. - * - * @since 3.0.0 - */ -public interface ErrorPolicy -{ - /** - * Returns true if the given state should cause the recipe to - * act as though the connection has been lost. i.e. locks should - * exit, etc. - * - * @param state the state - * @return true/false - */ - boolean isErrorState(ConnectionState state); -} http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/state/SessionConnectionStateErrorPolicy.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/SessionConnectionStateErrorPolicy.java b/curator-framework/src/main/java/org/apache/curator/framework/state/SessionConnectionStateErrorPolicy.java new file mode 100644 index 0000000..f893a50 --- /dev/null +++ b/curator-framework/src/main/java/org/apache/curator/framework/state/SessionConnectionStateErrorPolicy.java @@ -0,0 +1,13 @@ +package org.apache.curator.framework.state; + +/** + * This policy treats only {@link ConnectionState#LOST} as an error + */ +public class SessionConnectionStateErrorPolicy implements ConnectionStateErrorPolicy +{ + @Override + public boolean isErrorState(ConnectionState state) + { + return state == ConnectionState.LOST; + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/state/SessionErrorPolicy.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/SessionErrorPolicy.java b/curator-framework/src/main/java/org/apache/curator/framework/state/SessionErrorPolicy.java deleted file mode 100644 index 3f68fe4..0000000 --- a/curator-framework/src/main/java/org/apache/curator/framework/state/SessionErrorPolicy.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.apache.curator.framework.state; - -/** - * This policy treats only {@link ConnectionState#LOST} as an error - */ -public class SessionErrorPolicy implements ErrorPolicy -{ - @Override - public boolean isErrorState(ConnectionState state) - { - return state == ConnectionState.LOST; - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/state/StandardConnectionStateErrorPolicy.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/StandardConnectionStateErrorPolicy.java b/curator-framework/src/main/java/org/apache/curator/framework/state/StandardConnectionStateErrorPolicy.java new file mode 100644 index 0000000..49c0739 --- /dev/null +++ b/curator-framework/src/main/java/org/apache/curator/framework/state/StandardConnectionStateErrorPolicy.java @@ -0,0 +1,14 @@ +package org.apache.curator.framework.state; + +/** + * This policy treats {@link ConnectionState#SUSPENDED} and {@link ConnectionState#LOST} + * as errors + */ +public class StandardConnectionStateErrorPolicy implements ConnectionStateErrorPolicy +{ + @Override + public boolean isErrorState(ConnectionState state) + { + return ((state == ConnectionState.SUSPENDED) || (state == ConnectionState.LOST)); + } +} http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-framework/src/main/java/org/apache/curator/framework/state/StandardErrorPolicy.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/StandardErrorPolicy.java b/curator-framework/src/main/java/org/apache/curator/framework/state/StandardErrorPolicy.java deleted file mode 100644 index ea0c668..0000000 --- a/curator-framework/src/main/java/org/apache/curator/framework/state/StandardErrorPolicy.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.curator.framework.state; - -/** - * This policy treats {@link ConnectionState#SUSPENDED} and {@link ConnectionState#LOST} - * as errors - */ -public class StandardErrorPolicy implements ErrorPolicy -{ - @Override - public boolean isErrorState(ConnectionState state) - { - return ((state == ConnectionState.SUSPENDED) || (state == ConnectionState.LOST)); - } -} http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java index aa4dd9f..1141e36 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderLatch.java @@ -604,7 +604,7 @@ public class LeaderLatch implements Closeable { try { - if ( client.getErrorPolicy().isErrorState(ConnectionState.SUSPENDED) || !hasLeadership.get() ) + if ( client.getConnectionStateErrorPolicy().isErrorState(ConnectionState.SUSPENDED) || !hasLeadership.get() ) { reset(); } @@ -619,7 +619,7 @@ public class LeaderLatch implements Closeable case SUSPENDED: { - if ( client.getErrorPolicy().isErrorState(ConnectionState.SUSPENDED) ) + if ( client.getConnectionStateErrorPolicy().isErrorState(ConnectionState.SUSPENDED) ) { setLeadership(false); } http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelectorListenerAdapter.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelectorListenerAdapter.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelectorListenerAdapter.java index 1b0070a..19c0e92 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelectorListenerAdapter.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/leader/LeaderSelectorListenerAdapter.java @@ -30,7 +30,7 @@ public abstract class LeaderSelectorListenerAdapter implements LeaderSelectorLis @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { - if ( client.getErrorPolicy().isErrorState(newState) ) + if ( client.getConnectionStateErrorPolicy().isErrorState(newState) ) { throw new CancelLeadershipException(); } http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java index fcebae4..ac88fe7 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java @@ -28,8 +28,8 @@ import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.imps.TestCleanState; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; -import org.apache.curator.framework.state.SessionErrorPolicy; -import org.apache.curator.framework.state.StandardErrorPolicy; +import org.apache.curator.framework.state.SessionConnectionStateErrorPolicy; +import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy; import org.apache.curator.retry.RetryNTimes; import org.apache.curator.retry.RetryOneTime; import org.apache.curator.test.BaseClassForTests; @@ -73,7 +73,7 @@ public class TestLeaderLatch extends BaseClassForTests .connectionTimeoutMs(10000) .sessionTimeoutMs(60000) .retryPolicy(new RetryOneTime(1)) - .errorPolicy(isSessionIteration ? new SessionErrorPolicy() : new StandardErrorPolicy()) + .errorPolicy(isSessionIteration ? new SessionConnectionStateErrorPolicy() : new StandardConnectionStateErrorPolicy()) .build(); final BlockingQueue<String> states = Queues.newLinkedBlockingQueue(); ConnectionStateListener stateListener = new ConnectionStateListener() @@ -143,7 +143,7 @@ public class TestLeaderLatch extends BaseClassForTests .connectionTimeoutMs(1000) .sessionTimeoutMs(timing.session()) .retryPolicy(new RetryOneTime(1)) - .errorPolicy(new StandardErrorPolicy()) + .errorPolicy(new StandardConnectionStateErrorPolicy()) .build(); try { @@ -195,7 +195,7 @@ public class TestLeaderLatch extends BaseClassForTests .connectionTimeoutMs(1000) .sessionTimeoutMs(timing.session()) .retryPolicy(new RetryOneTime(1)) - .errorPolicy(new SessionErrorPolicy()) + .errorPolicy(new SessionConnectionStateErrorPolicy()) .build(); client.getConnectionStateListenable().addListener(stateListener); client.start(); http://git-wip-us.apache.org/repos/asf/curator/blob/7aa371e9/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java index cd76bc1..510e515 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderSelector.java @@ -21,13 +21,12 @@ package org.apache.curator.framework.recipes.leader; import com.google.common.collect.Lists; import com.google.common.collect.Queues; -import org.apache.curator.connection.StandardConnectionHandlingPolicy; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; -import org.apache.curator.framework.state.SessionErrorPolicy; -import org.apache.curator.framework.state.StandardErrorPolicy; +import org.apache.curator.framework.state.SessionConnectionStateErrorPolicy; +import org.apache.curator.framework.state.StandardConnectionStateErrorPolicy; import org.apache.curator.retry.RetryOneTime; import org.apache.curator.test.BaseClassForTests; import org.apache.curator.test.KillSession; @@ -65,7 +64,7 @@ public class TestLeaderSelector extends BaseClassForTests .connectionTimeoutMs(timing.connection()) .sessionTimeoutMs(timing.session()) .retryPolicy(new RetryOneTime(1)) - .errorPolicy(new StandardErrorPolicy()) + .errorPolicy(new StandardConnectionStateErrorPolicy()) .build(); try { @@ -122,7 +121,7 @@ public class TestLeaderSelector extends BaseClassForTests .connectionTimeoutMs(timing.connection()) .sessionTimeoutMs(timing.session()) .retryPolicy(new RetryOneTime(1)) - .errorPolicy(new SessionErrorPolicy()) + .errorPolicy(new SessionConnectionStateErrorPolicy()) .build(); client.getConnectionStateListenable().addListener(stateListener); client.start();