Package org.apache.curator.framework
Class CuratorFrameworkFactory.Builder
- java.lang.Object
-
- org.apache.curator.framework.CuratorFrameworkFactory.Builder
-
- Enclosing class:
- CuratorFrameworkFactory
public static class CuratorFrameworkFactory.Builder extends java.lang.Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CuratorFrameworkFactory.BuilderaclProvider(ACLProvider aclProvider)CuratorFrameworkFactory.Builderauthorization(java.lang.String scheme, byte[] auth)Add connection authorization Subsequent calls to this method overwrite the prior calls.CuratorFrameworkFactory.Builderauthorization(java.util.List<AuthInfo> authInfos)Add connection authorization.CuratorFrameworkbuild()Apply the current values and build a new CuratorFrameworkCuratorTempFrameworkbuildTemp()Apply the current values and build a new temporary CuratorFramework.CuratorTempFrameworkbuildTemp(long inactiveThreshold, java.util.concurrent.TimeUnit unit)Apply the current values and build a new temporary CuratorFramework.booleancanBeReadOnly()CuratorFrameworkFactory.BuildercanBeReadOnly(boolean canBeReadOnly)CuratorFrameworkFactory.BuildercompressionProvider(CompressionProvider compressionProvider)CuratorFrameworkFactory.BuilderconnectionHandlingPolicy(org.apache.curator.connection.ConnectionHandlingPolicy connectionHandlingPolicy)Change the connection handling policy.CuratorFrameworkFactory.BuilderconnectionStateErrorPolicy(ConnectionStateErrorPolicy connectionStateErrorPolicy)Set the error policy to use.CuratorFrameworkFactory.BuilderconnectionStateListenerDecorator(ConnectionStateListenerDecorator connectionStateListenerDecorator)Sets the connection state listener decorator.CuratorFrameworkFactory.BuilderconnectionTimeoutMs(int connectionTimeoutMs)CuratorFrameworkFactory.BuilderconnectString(java.lang.String connectString)Set the list of servers to connect to.CuratorFrameworkFactory.BuilderdefaultData(byte[] defaultData)Sets the data to use whenPathAndBytesable.forPath(String)is used.CuratorFrameworkFactory.BuilderdontUseContainerParents()By default, Curator usesCreateBuilderMain.creatingParentContainersIfNeeded()if the ZK JAR supportsCreateMode.CONTAINER.CuratorFrameworkFactory.BuilderensembleProvider(org.apache.curator.ensemble.EnsembleProvider ensembleProvider)Set the list ensemble provider.ACLProvidergetAclProvider()java.util.List<AuthInfo>getAuthInfos()java.lang.StringgetAuthScheme()Deprecated.byte[]getAuthValue()Deprecated.CompressionProvidergetCompressionProvider()org.apache.curator.connection.ConnectionHandlingPolicygetConnectionHandlingPolicy()ConnectionStateErrorPolicygetConnectionStateErrorPolicy()ConnectionStateListenerDecoratorgetConnectionStateListenerDecorator()intgetConnectionTimeoutMs()byte[]getDefaultData()org.apache.curator.ensemble.EnsembleProvidergetEnsembleProvider()intgetMaxCloseWaitMs()java.lang.StringgetNamespace()org.apache.curator.RetryPolicygetRetryPolicy()java.util.concurrent.ExecutorgetRunSafeService()SchemaSetgetSchemaSet()intgetSessionTimeoutMs()java.util.concurrent.ThreadFactorygetThreadFactory()intgetWaitForShutdownTimeoutMs()org.apache.curator.utils.ZookeeperFactorygetZookeeperFactory()booleanisZk34CompatibilityMode()CuratorFrameworkFactory.BuildermaxCloseWaitMs(int maxCloseWaitMs)CuratorFrameworkFactory.Buildernamespace(java.lang.String namespace)As ZooKeeper is a shared space, users of a given cluster should stay within a pre-defined namespace.CuratorFrameworkFactory.BuilderretryPolicy(org.apache.curator.RetryPolicy retryPolicy)CuratorFrameworkFactory.BuilderrunSafeService(java.util.concurrent.Executor runSafeService)Curator (and user) recipes will use this executor to call notifyAll and other blocking calls that might normally block ZooKeeper's event thread.CuratorFrameworkFactory.BuilderschemaSet(SchemaSet schemaSet)Add an enforced schema setCuratorFrameworkFactory.BuildersessionTimeoutMs(int sessionTimeoutMs)CuratorFrameworkFactory.BuilderthreadFactory(java.util.concurrent.ThreadFactory threadFactory)booleanuseContainerParentsIfAvailable()CuratorFrameworkFactory.BuilderwaitForShutdownTimeoutMs(int waitForShutdownTimeoutMs)Set a timeout forCuratorZookeeperClient.close(int)}.CuratorFrameworkFactory.Builderzk34CompatibilityMode(boolean mode)If mode is true, create a ZooKeeper 3.4.x compatible client.CuratorFrameworkFactory.BuilderzookeeperFactory(org.apache.curator.utils.ZookeeperFactory zookeeperFactory)
-
-
-
Method Detail
-
build
public CuratorFramework build()
Apply the current values and build a new CuratorFramework- Returns:
- new CuratorFramework
-
buildTemp
public CuratorTempFramework buildTemp()
Apply the current values and build a new temporary CuratorFramework. Temporary CuratorFramework instances are meant for single requests to ZooKeeper ensembles over a failure prone network such as a WAN. The APIs available fromCuratorTempFrameworkare limited. Further, the connection will be closed after 3 minutes of inactivity.- Returns:
- temp instance
-
buildTemp
public CuratorTempFramework buildTemp(long inactiveThreshold, java.util.concurrent.TimeUnit unit)
Apply the current values and build a new temporary CuratorFramework. Temporary CuratorFramework instances are meant for single requests to ZooKeeper ensembles over a failure prone network such as a WAN. The APIs available fromCuratorTempFrameworkare limited. Further, the connection will be closed afterinactiveThresholdMsmilliseconds of inactivity.- Parameters:
inactiveThreshold- number of milliseconds of inactivity to cause connection closeunit- threshold unit- Returns:
- temp instance
-
authorization
public CuratorFrameworkFactory.Builder authorization(java.lang.String scheme, byte[] auth)
Add connection authorization Subsequent calls to this method overwrite the prior calls.- Parameters:
scheme- the schemeauth- the auth bytes- Returns:
- this
-
authorization
public CuratorFrameworkFactory.Builder authorization(java.util.List<AuthInfo> authInfos)
Add connection authorization. The supplied authInfos are appended to those added via call toauthorization(java.lang.String, byte[])for backward compatibility. Subsequent calls to this method overwrite the prior calls.- Parameters:
authInfos- list ofAuthInfoobjects with scheme and auth- Returns:
- this
-
connectString
public CuratorFrameworkFactory.Builder connectString(java.lang.String connectString)
Set the list of servers to connect to. IMPORTANT: use either this orensembleProvider(EnsembleProvider)but not both.- Parameters:
connectString- list of servers to connect to- Returns:
- this
-
ensembleProvider
public CuratorFrameworkFactory.Builder ensembleProvider(org.apache.curator.ensemble.EnsembleProvider ensembleProvider)
Set the list ensemble provider. IMPORTANT: use either this orconnectString(String)but not both.- Parameters:
ensembleProvider- the ensemble provider to use- Returns:
- this
-
defaultData
public CuratorFrameworkFactory.Builder defaultData(byte[] defaultData)
Sets the data to use whenPathAndBytesable.forPath(String)is used. This is useful for debugging purposes. For example, you could set this to be the IP of the client.- Parameters:
defaultData- new default data to use- Returns:
- this
-
namespace
public CuratorFrameworkFactory.Builder namespace(java.lang.String namespace)
As ZooKeeper is a shared space, users of a given cluster should stay within a pre-defined namespace. If a namespace is set here, all paths will get pre-pended with the namespace- Parameters:
namespace- the namespace- Returns:
- this
-
sessionTimeoutMs
public CuratorFrameworkFactory.Builder sessionTimeoutMs(int sessionTimeoutMs)
- Parameters:
sessionTimeoutMs- session timeout- Returns:
- this
-
connectionTimeoutMs
public CuratorFrameworkFactory.Builder connectionTimeoutMs(int connectionTimeoutMs)
- Parameters:
connectionTimeoutMs- connection timeout- Returns:
- this
-
maxCloseWaitMs
public CuratorFrameworkFactory.Builder maxCloseWaitMs(int maxCloseWaitMs)
- Parameters:
maxCloseWaitMs- time to wait during close to join background threads- Returns:
- this
-
retryPolicy
public CuratorFrameworkFactory.Builder retryPolicy(org.apache.curator.RetryPolicy retryPolicy)
- Parameters:
retryPolicy- retry policy to use- Returns:
- this
-
threadFactory
public CuratorFrameworkFactory.Builder threadFactory(java.util.concurrent.ThreadFactory threadFactory)
- Parameters:
threadFactory- thread factory used to create Executor Services- Returns:
- this
-
compressionProvider
public CuratorFrameworkFactory.Builder compressionProvider(CompressionProvider compressionProvider)
- Parameters:
compressionProvider- the compression provider- Returns:
- this
-
zookeeperFactory
public CuratorFrameworkFactory.Builder zookeeperFactory(org.apache.curator.utils.ZookeeperFactory zookeeperFactory)
- Parameters:
zookeeperFactory- the zookeeper factory to use- Returns:
- this
-
aclProvider
public CuratorFrameworkFactory.Builder aclProvider(ACLProvider aclProvider)
- Parameters:
aclProvider- a provider for ACLs- Returns:
- this
-
canBeReadOnly
public CuratorFrameworkFactory.Builder canBeReadOnly(boolean canBeReadOnly)
- Parameters:
canBeReadOnly- if true, allow ZooKeeper client to enter read only mode in case of a network partition. SeeZooKeeper(String, int, Watcher, long, byte[], boolean)for details- Returns:
- this
-
dontUseContainerParents
public CuratorFrameworkFactory.Builder dontUseContainerParents()
By default, Curator usesCreateBuilderMain.creatingParentContainersIfNeeded()if the ZK JAR supportsCreateMode.CONTAINER. Call this method to turn off this behavior.- Returns:
- this
-
connectionStateErrorPolicy
public CuratorFrameworkFactory.Builder connectionStateErrorPolicy(ConnectionStateErrorPolicy connectionStateErrorPolicy)
Set the error policy to use. The default isStandardConnectionStateErrorPolicy- Parameters:
connectionStateErrorPolicy- new error policy- Returns:
- this
- Since:
- 3.0.0
-
zk34CompatibilityMode
public CuratorFrameworkFactory.Builder zk34CompatibilityMode(boolean mode)
If mode is true, create a ZooKeeper 3.4.x compatible client. IMPORTANT: If the client library used is ZooKeeper 3.4.xzk34CompatibilityModeis enabled by default.- Parameters:
mode- true/false- Returns:
- this
- Since:
- 3.5.0
-
waitForShutdownTimeoutMs
public CuratorFrameworkFactory.Builder waitForShutdownTimeoutMs(int waitForShutdownTimeoutMs)
Set a timeout forCuratorZookeeperClient.close(int)}. The default is 0, which means that this feature is disabled.- Parameters:
waitForShutdownTimeoutMs- default timeout- Returns:
- this
- Since:
- 4.0.2
-
connectionHandlingPolicy
public CuratorFrameworkFactory.Builder connectionHandlingPolicy(org.apache.curator.connection.ConnectionHandlingPolicy connectionHandlingPolicy)
Change the connection handling policy. The default policy is
StandardConnectionHandlingPolicy.IMPORTANT: StandardConnectionHandlingPolicy has different behavior than the connection policy handling prior to version 3.0.0.
Major differences from the older behavior are:
- Session/connection timeouts are no longer managed by the low-level client. They are managed by the CuratorFramework instance. There should be no noticeable differences.
- Prior to 3.0.0, each iteration of the retry policy would allow the connection timeout to elapse if the connection hadn't yet succeeded. This meant that the true connection timeout was the configured value times the maximum retries in the retry policy. This longstanding issue has been address. Now, the connection timeout can elapse only once for a single API call.
-
MOST IMPORTANTLY! Prior to 3.0.0,
ConnectionState.LOSTdid not imply a lost session (much to the confusion of users). Now, Curator will set the LOST state only when it believes that the ZooKeeper session has expired. ZooKeeper connections have a session. When the session expires, clients must take appropriate action. In Curator, this is complicated by the fact that Curator internally manages the ZooKeeper connection. Now, Curator will set the LOST state when any of the following occurs: a) ZooKeeper returns aWatcher.Event.KeeperState.ExpiredorKeeperException.Code.SESSIONEXPIRED; b) Curator closes the internally managed ZooKeeper instance; c) The session timeout elapses during a network partition.
- Parameters:
connectionHandlingPolicy- the policy- Returns:
- this
- Since:
- 3.0.0
-
schemaSet
public CuratorFrameworkFactory.Builder schemaSet(SchemaSet schemaSet)
Add an enforced schema set- Parameters:
schemaSet- the schema set- Returns:
- this
- Since:
- 3.2.0
-
runSafeService
public CuratorFrameworkFactory.Builder runSafeService(java.util.concurrent.Executor runSafeService)
Curator (and user) recipes will use this executor to call notifyAll and other blocking calls that might normally block ZooKeeper's event thread. By default, an executor is allocated internally using the provided (or default)threadFactory(java.util.concurrent.ThreadFactory). Use this method to set a custom executor.- Parameters:
runSafeService- executor to use for calls to notifyAll from Watcher callbacks etc- Returns:
- this
- Since:
- 4.1.0
-
connectionStateListenerDecorator
public CuratorFrameworkFactory.Builder connectionStateListenerDecorator(ConnectionStateListenerDecorator connectionStateListenerDecorator)
Sets the connection state listener decorator. For example, you can setCircuitBreakingConnectionStateListeners via this mechanism by usingConnectionStateListenerDecorator.circuitBreaking(org.apache.curator.RetryPolicy)orConnectionStateListenerDecorator.circuitBreaking(org.apache.curator.RetryPolicy, java.util.concurrent.ScheduledExecutorService)- Parameters:
connectionStateListenerDecorator- decorator to use- Returns:
- this
- Since:
- 4.2.0
-
getRunSafeService
public java.util.concurrent.Executor getRunSafeService()
-
getAclProvider
public ACLProvider getAclProvider()
-
getZookeeperFactory
public org.apache.curator.utils.ZookeeperFactory getZookeeperFactory()
-
getCompressionProvider
public CompressionProvider getCompressionProvider()
-
getThreadFactory
public java.util.concurrent.ThreadFactory getThreadFactory()
-
getEnsembleProvider
public org.apache.curator.ensemble.EnsembleProvider getEnsembleProvider()
-
getSessionTimeoutMs
public int getSessionTimeoutMs()
-
getConnectionTimeoutMs
public int getConnectionTimeoutMs()
-
getWaitForShutdownTimeoutMs
public int getWaitForShutdownTimeoutMs()
-
getMaxCloseWaitMs
public int getMaxCloseWaitMs()
-
getRetryPolicy
public org.apache.curator.RetryPolicy getRetryPolicy()
-
getNamespace
public java.lang.String getNamespace()
-
useContainerParentsIfAvailable
public boolean useContainerParentsIfAvailable()
-
getConnectionStateErrorPolicy
public ConnectionStateErrorPolicy getConnectionStateErrorPolicy()
-
getConnectionHandlingPolicy
public org.apache.curator.connection.ConnectionHandlingPolicy getConnectionHandlingPolicy()
-
getSchemaSet
public SchemaSet getSchemaSet()
-
isZk34CompatibilityMode
public boolean isZk34CompatibilityMode()
-
getAuthScheme
@Deprecated public java.lang.String getAuthScheme()
Deprecated.
-
getAuthValue
@Deprecated public byte[] getAuthValue()
Deprecated.
-
getAuthInfos
public java.util.List<AuthInfo> getAuthInfos()
-
getDefaultData
public byte[] getDefaultData()
-
canBeReadOnly
public boolean canBeReadOnly()
-
getConnectionStateListenerDecorator
public ConnectionStateListenerDecorator getConnectionStateListenerDecorator()
-
-