Class CuratorFrameworkFactory.Builder

java.lang.Object
org.apache.curator.framework.CuratorFrameworkFactory.Builder
Enclosing class:
CuratorFrameworkFactory

public static class CuratorFrameworkFactory.Builder extends Object
  • Method Details

    • 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 from CuratorTempFramework are limited. Further, the connection will be closed after 3 minutes of inactivity.
      Returns:
      temp instance
    • buildTemp

      public CuratorTempFramework buildTemp(long inactiveThreshold, 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 from CuratorTempFramework are limited. Further, the connection will be closed after inactiveThresholdMs milliseconds of inactivity.
      Parameters:
      inactiveThreshold - number of milliseconds of inactivity to cause connection close
      unit - threshold unit
      Returns:
      temp instance
    • authorization

      public CuratorFrameworkFactory.Builder authorization(String scheme, byte[] auth)
      Add connection authorization Subsequent calls to this method overwrite the prior calls.
      Parameters:
      scheme - the scheme
      auth - the auth bytes
      Returns:
      this
    • authorization

      public CuratorFrameworkFactory.Builder authorization(List<AuthInfo> authInfos)
      Add connection authorization. The supplied authInfos are appended to those added via call to authorization(java.lang.String, byte[]) for backward compatibility.

      Subsequent calls to this method overwrite the prior calls.

      Parameters:
      authInfos - list of AuthInfo objects with scheme and auth
      Returns:
      this
    • connectString

      public CuratorFrameworkFactory.Builder connectString(String connectString)
      Set the list of servers to connect to. IMPORTANT: use either this or ensembleProvider(EnsembleProvider) but not both.
      Parameters:
      connectString - list of servers to connect to
      Returns:
      this
    • ensembleProvider

      public CuratorFrameworkFactory.Builder ensembleProvider(EnsembleProvider ensembleProvider)
      Set the list ensemble provider. IMPORTANT: use either this or connectString(String) but not both.
      Parameters:
      ensembleProvider - the ensemble provider to use
      Returns:
      this
    • ensembleTracker

      public CuratorFrameworkFactory.Builder ensembleTracker(boolean withEnsembleTracker)
      Allows to configure if the ensemble configuration changes will be watched. The default value is true.
      IMPORTANT: Use this method in combination with ensembleProvider(EnsembleProvider) to provide an instance that returns false on EnsembleProvider.updateServerListEnabled() in order to fully achieve that ensemble server list changes are ignored
      Parameters:
      withEnsembleTracker - use false if you want to avoid following ensemble configuration changes
      Returns:
      this
    • withEnsembleTracker

      public boolean withEnsembleTracker()
      Returns:
      true if ensemble configuration changes MUST be watched
    • defaultData

      public CuratorFrameworkFactory.Builder defaultData(byte[] defaultData)
      Sets the data to use when PathAndBytesable.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(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(RetryPolicy retryPolicy)
      Parameters:
      retryPolicy - retry policy to use
      Returns:
      this
    • threadFactory

      public CuratorFrameworkFactory.Builder threadFactory(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(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. See ZooKeeper(String, int, Watcher, long, byte[], boolean) for details
      Returns:
      this
    • dontUseContainerParents

      public CuratorFrameworkFactory.Builder dontUseContainerParents()
      By default, Curator uses CreateBuilderMain.creatingParentContainersIfNeeded() if the ZK JAR supports CreateMode.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 is StandardConnectionStateErrorPolicy
      Parameters:
      connectionStateErrorPolicy - new error policy
      Returns:
      this
      Since:
      3.0.0
    • waitForShutdownTimeoutMs

      public CuratorFrameworkFactory.Builder waitForShutdownTimeoutMs(int waitForShutdownTimeoutMs)
      Set a timeout for CuratorZookeeperClient.close(int) }. The default is 0, which means that this feature is disabled.
      Parameters:
      waitForShutdownTimeoutMs - default timeout
      Returns:
      this
      Since:
      4.0.2
    • simulatedSessionExpirationPercent

      public CuratorFrameworkFactory.Builder simulatedSessionExpirationPercent(int simulatedSessionExpirationPercent)

      Prior to 3.0.0, Curator did not try to manage session expiration other than the functionality provided by ZooKeeper itself. Starting with 3.0.0, Curator has the option of attempting to monitor session expiration above what is provided by ZooKeeper. The percentage set by this method determines how and if Curator will check for session expiration.

      The default percentage is 100.

      If it is set to 0, Curator does not do any additional checking for session expiration.

      If a positive number is set, Curator will check for session expiration as follows: when ZooKeeper sends a Disconnect event, Curator will start a timer. If re-connection is not achieved before the elapsed time exceeds the negotiated session time multiplied by the session expiration percent, Curator will simulate a session expiration. Due to timing/network issues, it is not possible for a client to match the server's session timeout with complete accuracy. Thus, the need for a session expiration percentage.

      Parameters:
      simulatedSessionExpirationPercent - new simulated session expiration percentage
      Returns:
      this
      Since:
      5.0
    • zkClientConfig

      public CuratorFrameworkFactory.Builder zkClientConfig(org.apache.zookeeper.client.ZKClientConfig zkClientConfig)
    • 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(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
    • connectionStateListenerManagerFactory

      public CuratorFrameworkFactory.Builder connectionStateListenerManagerFactory(ConnectionStateListenerManagerFactory connectionStateListenerManagerFactory)
      Sets the connection state listener manager factory. For example, you can set ConnectionStateListenerManagerFactory.circuitBreaking(org.apache.curator.RetryPolicy)
      Parameters:
      connectionStateListenerManagerFactory - manager factory to use
      Returns:
      this
      Since:
      4.2.0
    • getRunSafeService

      public Executor getRunSafeService()
    • getAclProvider

      public ACLProvider getAclProvider()
    • getZookeeperFactory

      public ZookeeperFactory getZookeeperFactory()
    • getCompressionProvider

      public CompressionProvider getCompressionProvider()
    • getThreadFactory

      public ThreadFactory getThreadFactory()
    • getEnsembleProvider

      public EnsembleProvider getEnsembleProvider()
    • getSessionTimeoutMs

      public int getSessionTimeoutMs()
    • getConnectionTimeoutMs

      public int getConnectionTimeoutMs()
    • getWaitForShutdownTimeoutMs

      public int getWaitForShutdownTimeoutMs()
    • getMaxCloseWaitMs

      public int getMaxCloseWaitMs()
    • getRetryPolicy

      public RetryPolicy getRetryPolicy()
    • getNamespace

      public String getNamespace()
    • useContainerParentsIfAvailable

      public boolean useContainerParentsIfAvailable()
    • getConnectionStateErrorPolicy

      public ConnectionStateErrorPolicy getConnectionStateErrorPolicy()
    • getSimulatedSessionExpirationPercent

      public int getSimulatedSessionExpirationPercent()
    • getZkClientConfig

      public org.apache.zookeeper.client.ZKClientConfig getZkClientConfig()
    • getSchemaSet

      public SchemaSet getSchemaSet()
    • getAuthScheme

      @Deprecated public String getAuthScheme()
      Deprecated.
    • getAuthValue

      @Deprecated public byte[] getAuthValue()
      Deprecated.
    • getAuthInfos

      public List<AuthInfo> getAuthInfos()
    • getDefaultData

      public byte[] getDefaultData()
    • canBeReadOnly

      public boolean canBeReadOnly()
    • getConnectionStateListenerManagerFactory

      public ConnectionStateListenerManagerFactory getConnectionStateListenerManagerFactory()