Interface CuratorFramework

All Superinterfaces:
AutoCloseable, Closeable
All Known Subinterfaces:
WatcherRemoveCuratorFramework
All Known Implementing Classes:
CuratorFrameworkImpl

public interface CuratorFramework extends Closeable
Zookeeper framework-style client
  • Method Details

    • start

      void start()
      Start the client. Most mutator methods will not work until the client is started
    • close

      void close()
      Stop the client
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • getState

      Returns the state of this instance
      Returns:
      state
    • isStarted

      @Deprecated boolean isStarted()
      Deprecated.
      use getState() instead
      Return true if the client is started, not closed, etc.
      Returns:
      true/false
    • create

      CreateBuilder create()
      Start a create builder
      Returns:
      builder object
    • delete

      DeleteBuilder delete()
      Start a delete builder
      Returns:
      builder object
    • checkExists

      ExistsBuilder checkExists()
      Start an exists builder

      The builder will return a Stat object as if org.apache.zookeeper.ZooKeeper.exists() were called. Thus, a null means that it does not exist and an actual Stat object means it does exist.

      Returns:
      builder object
    • getData

      GetDataBuilder getData()
      Start a get data builder
      Returns:
      builder object
    • setData

      SetDataBuilder setData()
      Start a set data builder
      Returns:
      builder object
    • getChildren

      GetChildrenBuilder getChildren()
      Start a get children builder
      Returns:
      builder object
    • getACL

      GetACLBuilder getACL()
      Start a get ACL builder
      Returns:
      builder object
    • setACL

      SetACLBuilder setACL()
      Start a set ACL builder
      Returns:
      builder object
    • reconfig

      ReconfigBuilder reconfig()
      Start a reconfig builder
      Returns:
      builder object
    • getConfig

      GetConfigBuilder getConfig()
      Start a getConfig builder
      Returns:
      builder object
    • inTransaction

      CuratorTransaction inTransaction()
      Deprecated.
      use transaction() instead
      Start a transaction builder
      Returns:
      builder object
    • transaction

      Start a transaction builder
      Returns:
      builder object
    • transactionOp

      TransactionOp transactionOp()
      Allocate an operation that can be used with transaction(). NOTE: CuratorOp instances created by this builder are reusable.
      Returns:
      operation builder
    • sync

      @Deprecated void sync(String path, Object backgroundContextObject)
      Deprecated.
      use sync() instead
      Perform a sync on the given path - syncs are always in the background
      Parameters:
      path - the path
      backgroundContextObject - optional context
    • createContainers

      void createContainers(String path) throws Exception
      Create all nodes in the specified path as containers if they don't already exist
      Parameters:
      path - path to create
      Throws:
      Exception - errors
    • sync

      SyncBuilder sync()
      Start a sync builder. Note: sync is ALWAYS in the background even if you don't use one of the background() methods
      Returns:
      builder object
    • watches

      Deprecated.
      use watchers() in ZooKeeper 3.6+
      Start a remove watches builder.
      Returns:
      builder object
    • watchers

      WatchesBuilder watchers()
      Start a watch builder. Supported only when ZooKeeper JAR of version 3.6 or above is used, throws IllegalStateException for ZooKeeper JAR 3.5 or below
      Returns:
      builder object
      Throws:
      IllegalStateException - ZooKeeper JAR is 3.5 or below
    • getConnectionStateListenable

      Listenable<ConnectionStateListener> getConnectionStateListenable()
      Returns the listenable interface for the Connect State
      Returns:
      listenable
    • getCuratorListenable

      Listenable<CuratorListener> getCuratorListenable()
      Returns the listenable interface for events
      Returns:
      listenable
    • getUnhandledErrorListenable

      Listenable<UnhandledErrorListener> getUnhandledErrorListenable()
      Returns the listenable interface for unhandled errors
      Returns:
      listenable
    • nonNamespaceView

      @Deprecated CuratorFramework nonNamespaceView()
      Deprecated.
      Since 2.9.0 - use usingNamespace(java.lang.String) passing null
      Returns a facade of the current instance that does _not_ automatically pre-pend the namespace to all paths
      Returns:
      facade
    • usingNamespace

      CuratorFramework usingNamespace(String newNamespace)
      Returns a facade of the current instance that uses the specified namespace or no namespace if newNamespace is null.
      Parameters:
      newNamespace - the new namespace or null for none
      Returns:
      facade
    • getNamespace

      String getNamespace()
      Return the current namespace or "" if none
      Returns:
      namespace
    • getZookeeperClient

      CuratorZookeeperClient getZookeeperClient()
      Return the managed zookeeper client
      Returns:
      client
    • getZookeeperCompatibility

      ZookeeperCompatibility getZookeeperCompatibility()
      Return zookeeper server compatibility
      Returns:
      compatibility
    • newNamespaceAwareEnsurePath

      @Deprecated EnsurePath newNamespaceAwareEnsurePath(String path)
      Allocates an ensure path instance that is namespace aware
      Parameters:
      path - path to ensure
      Returns:
      new EnsurePath instance
    • clearWatcherReferences

      @Deprecated void clearWatcherReferences(org.apache.zookeeper.Watcher watcher)
      Deprecated.
      As of ZooKeeper 3.5 Curators recipes will handle removing watcher references when they are no longer used. If you write your own recipe, follow the example of Curator recipes and use newWatcherRemoveCuratorFramework() calling WatcherRemoveCuratorFramework.removeWatchers() when closing your instance.
      Curator can hold internal references to watchers that may inhibit garbage collection. Call this method on watchers you are no longer interested in.
      Parameters:
      watcher - the watcher
    • blockUntilConnected

      boolean blockUntilConnected(int maxWaitTime, TimeUnit units) throws InterruptedException
      Block until a connection to ZooKeeper is available or the maxWaitTime has been exceeded
      Parameters:
      maxWaitTime - The maximum wait time. 1. value <= 0 and units != null to return immediately; 2. value <= 0 and units == null to wait indefinitely, which is same as blockUntilConnected().
      units - The time units for the maximum wait time.
      Returns:
      True if connection has been established, false otherwise.
      Throws:
      InterruptedException - If interrupted while waiting
    • blockUntilConnected

      void blockUntilConnected() throws InterruptedException
      Block until a connection to ZooKeeper is available. This method will not return until a connection is available, or it is interrupted, in which case an InterruptedException will be thrown
      Throws:
      InterruptedException - If interrupted while waiting
    • newWatcherRemoveCuratorFramework

      WatcherRemoveCuratorFramework newWatcherRemoveCuratorFramework()
      Returns a facade of the current instance that tracks watchers created and allows a one-shot removal of all watchers via WatcherRemoveCuratorFramework.removeWatchers()
      Returns:
      facade
    • getConnectionStateErrorPolicy

      ConnectionStateErrorPolicy getConnectionStateErrorPolicy()
      Return the configured error policy
      Returns:
      error policy
    • getCurrentConfig

      org.apache.zookeeper.server.quorum.flexible.QuorumVerifier getCurrentConfig()
      Current maintains a cached view of the Zookeeper quorum config.
      Returns:
      the current config
    • getSchemaSet

      SchemaSet getSchemaSet()
      Return this instance's schema set
      Returns:
      schema set
    • postSafeNotify

      default CompletableFuture<Void> postSafeNotify(Object monitorHolder)
      Calls
      invalid reference
      #notifyAll()
      on the given object after first synchronizing on it. This is done from the runSafe(Runnable) thread.
      Parameters:
      monitorHolder - object to sync on and notify
      Returns:
      a CompletableFuture that can be used to monitor when the call is complete
      Since:
      4.1.0
    • runSafe

      CompletableFuture<Void> runSafe(Runnable runnable)
      Curator (and user) recipes can use this to run notifyAll and other blocking calls that might normally block ZooKeeper's event thread.
      Parameters:
      runnable - proc to call from a safe internal thread
      Returns:
      a CompletableFuture that can be used to monitor when the call is complete
      Since:
      4.1.0