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 2015/07/02 01:01:22 UTC
[05/20] curator git commit: Provide a way to override creating
containers
Provide a way to override creating containers
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/35ec01c0
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/35ec01c0
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/35ec01c0
Branch: refs/heads/master
Commit: 35ec01c0898ca40a6912a55ff30cf38525751f09
Parents: 8569763
Author: randgalt <ra...@apache.org>
Authored: Tue May 19 15:10:25 2015 -0700
Committer: randgalt <ra...@apache.org>
Committed: Tue May 19 15:10:25 2015 -0700
----------------------------------------------------------------------
.../framework/CuratorFrameworkFactory.java | 21 ++++++++++++++++++++
.../framework/imps/CreateBuilderImpl.java | 12 +++++++++--
.../framework/imps/CuratorFrameworkImpl.java | 21 +++++++++++++++++++-
3 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/35ec01c0/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 11cee2d..c9c9c10 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
@@ -25,13 +25,16 @@ import org.apache.curator.ensemble.EnsembleProvider;
import org.apache.curator.ensemble.fixed.FixedEnsembleProvider;
import org.apache.curator.framework.api.ACLProvider;
import org.apache.curator.framework.api.CompressionProvider;
+import org.apache.curator.framework.api.CreateBuilder;
import org.apache.curator.framework.api.PathAndBytesable;
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.utils.DefaultZookeeperFactory;
+import org.apache.curator.utils.EnsurePathContainers;
import org.apache.curator.utils.ZookeeperFactory;
+import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import java.net.InetAddress;
@@ -113,6 +116,7 @@ public class CuratorFrameworkFactory
private ZookeeperFactory zookeeperFactory = DEFAULT_ZOOKEEPER_FACTORY;
private ACLProvider aclProvider = DEFAULT_ACL_PROVIDER;
private boolean canBeReadOnly = false;
+ private boolean useContainerParentsIfAvailable = true;
/**
* Apply the current values and build a new CuratorFramework
@@ -328,6 +332,18 @@ public class CuratorFrameworkFactory
return this;
}
+ /**
+ * By default, Curator uses {@link EnsurePathContainers} and {@link CreateBuilder#creatingParentContainersIfNeeded()}
+ * if the ZK JAR supports {@link CreateMode#CONTAINER}. Call this method to turn off this behavior.
+ *
+ * @return this
+ */
+ public Builder dontUseContainerParents()
+ {
+ this.useContainerParentsIfAvailable = false;
+ return this;
+ }
+
public ACLProvider getAclProvider()
{
return aclProvider;
@@ -378,6 +394,11 @@ public class CuratorFrameworkFactory
return namespace;
}
+ public boolean useContainerParentsIfAvailable()
+ {
+ return useContainerParentsIfAvailable;
+ }
+
@Deprecated
public String getAuthScheme()
{
http://git-wip-us.apache.org/repos/asf/curator/blob/35ec01c0/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
index 7b1e855..4a669b2 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CreateBuilderImpl.java
@@ -134,7 +134,7 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
@Override
public ACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded()
{
- createParentsAsContainers = true;
+ setCreateParentsAsContainers();
return creatingParentsIfNeeded();
}
@@ -271,10 +271,18 @@ class CreateBuilderImpl implements CreateBuilder, BackgroundOperation<PathAndByt
@Override
public ProtectACLCreateModePathAndBytesable<String> creatingParentContainersIfNeeded()
{
- createParentsAsContainers = true;
+ setCreateParentsAsContainers();
return creatingParentsIfNeeded();
}
+ private void setCreateParentsAsContainers()
+ {
+ if ( client.useContainerParentsIfAvailable() )
+ {
+ createParentsAsContainers = true;
+ }
+ }
+
@Override
public ProtectACLCreateModePathAndBytesable<String> creatingParentsIfNeeded()
{
http://git-wip-us.apache.org/repos/asf/curator/blob/35ec01c0/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 800b67f..8ddbfb5 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
@@ -78,6 +78,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
private final ACLProvider aclProvider;
private final NamespaceFacadeCache namespaceFacadeCache;
private final NamespaceWatcherMap namespaceWatcherMap = new NamespaceWatcherMap(this);
+ private final boolean useContainerParentsIfAvailable;
private volatile ExecutorService executorService;
private final AtomicBoolean logAsErrorConnectionErrors = new AtomicBoolean(false);
@@ -118,6 +119,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
compressionProvider = builder.getCompressionProvider();
aclProvider = builder.getAclProvider();
state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);
+ useContainerParentsIfAvailable = builder.useContainerParentsIfAvailable();
byte[] builderDefaultData = builder.getDefaultData();
defaultData = (builderDefaultData != null) ? Arrays.copyOf(builderDefaultData, builderDefaultData.length) : new byte[0];
@@ -182,6 +184,7 @@ public class CuratorFrameworkImpl implements CuratorFramework
namespace = new NamespaceImpl(this, null);
state = parent.state;
authInfos = parent.authInfos;
+ useContainerParentsIfAvailable = parent.useContainerParentsIfAvailable;
}
@Override
@@ -461,7 +464,18 @@ public class CuratorFrameworkImpl implements CuratorFramework
@Override
public EnsurePathContainers newNamespaceAwareEnsurePathContainers(String path)
{
- return namespace.newNamespaceAwareEnsurePathContainers(path);
+ if ( useContainerParentsIfAvailable )
+ {
+ return namespace.newNamespaceAwareEnsurePathContainers(path);
+ }
+ return new EnsurePathContainers(path)
+ {
+ @Override
+ protected boolean asContainers()
+ {
+ return false;
+ }
+ };
}
ACLProvider getAclProvider()
@@ -489,6 +503,11 @@ public class CuratorFrameworkImpl implements CuratorFramework
return compressionProvider;
}
+ boolean useContainerParentsIfAvailable()
+ {
+ return useContainerParentsIfAvailable;
+ }
+
<DATA_TYPE> void processBackgroundOperation(OperationAndData<DATA_TYPE> operationAndData, CuratorEvent event)
{
boolean isInitialExecution = (event == null);