Interface CuratorFramework

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Subinterfaces:
    WatcherRemoveCuratorFramework
    All Known Implementing Classes:
    CuratorFrameworkImpl

    public interface CuratorFramework
    extends java.io.Closeable
    Zookeeper framework-style client
    • Method Detail

      • 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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • 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
      • 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​(java.lang.String path,
                  java.lang.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​(java.lang.String path)
                       throws java.lang.Exception
        Create all nodes in the specified path as containers if they don't already exist
        Parameters:
        path - path to create
        Throws:
        java.lang.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
      • 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​(java.lang.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

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

        org.apache.curator.CuratorZookeeperClient getZookeeperClient()
        Return the managed zookeeper client
        Returns:
        client
      • 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,
                                    java.util.concurrent.TimeUnit units)
                             throws java.lang.InterruptedException
        Block until a connection to ZooKeeper is available or the maxWaitTime has been exceeded
        Parameters:
        maxWaitTime - The maximum wait time. Specify a value <= 0 to wait indefinitely
        units - The time units for the maximum wait time.
        Returns:
        True if connection has been established, false otherwise.
        Throws:
        java.lang.InterruptedException - If interrupted while waiting
      • blockUntilConnected

        void blockUntilConnected()
                          throws java.lang.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:
        java.lang.InterruptedException - If interrupted while waiting
      • 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
      • isZk34CompatibilityMode

        boolean isZk34CompatibilityMode()
        Return true if this instance is running in ZK 3.4.x compatibility mode
        Returns:
        true/false
      • postSafeNotify

        default java.util.concurrent.CompletableFuture<java.lang.Void> postSafeNotify​(java.lang.Object monitorHolder)
        Calls #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

        java.util.concurrent.CompletableFuture<java.lang.Void> runSafe​(java.lang.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