Package org.apache.curator.framework
Interface CuratorFramework
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Subinterfaces:
WatcherRemoveCuratorFramework
- All Known Implementing Classes:
CuratorFrameworkImpl
Zookeeper framework-style client
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Block until a connection to ZooKeeper is available.boolean
blockUntilConnected
(int maxWaitTime, TimeUnit units) Block until a connection to ZooKeeper is available or the maxWaitTime has been exceededStart an exists buildervoid
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.void
close()
Stop the clientcreate()
Start a create buildervoid
createContainers
(String path) Create all nodes in the specified path as containers if they don't already existdelete()
Start a delete buildergetACL()
Start a get ACL builderStart a get children builderStart a getConfig builderReturn the configured error policyReturns the listenable interface for the Connect StateReturns the listenable interface for eventsorg.apache.zookeeper.server.quorum.flexible.QuorumVerifier
Current maintains a cached view of the Zookeeper quorum config.getData()
Start a get data builderReturn the current namespace or "" if noneReturn this instance's schema setgetState()
Returns the state of this instanceReturns the listenable interface for unhandled errorsReturn the managed zookeeper clientReturn zookeeper server compatibilityDeprecated.usetransaction()
insteadboolean
Deprecated.usegetState()
insteadDeprecated.Returns a facade of the current instance that tracks watchers created and allows a one-shot removal of all watchers viaWatcherRemoveCuratorFramework.removeWatchers()
Deprecated.Since 2.9.0 - useusingNamespace(java.lang.String)
passingnull
default CompletableFuture
<Void> postSafeNotify
(Object monitorHolder) Callsinvalid reference
#notifyAll()
reconfig()
Start a reconfig builderCurator (and user) recipes can use this to run notifyAll and other blocking calls that might normally block ZooKeeper's event thread.setACL()
Start a set ACL buildersetData()
Start a set data buildervoid
start()
Start the client.sync()
Start a sync builder.void
Deprecated.usesync()
insteadStart a transaction builderAllocate an operation that can be used withtransaction()
.usingNamespace
(String newNamespace) Returns a facade of the current instance that uses the specified namespace or no namespace ifnewNamespace
isnull
.watchers()
Start a watch builder.watches()
Deprecated.usewatchers()
in ZooKeeper 3.6+
-
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getState
CuratorFrameworkState getState()Returns the state of this instance- Returns:
- state
-
isStarted
Deprecated.usegetState()
insteadReturn 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 builderThe 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.usetransaction()
insteadStart a transaction builder- Returns:
- builder object
-
transaction
CuratorMultiTransaction transaction()Start a transaction builder- Returns:
- builder object
-
transactionOp
TransactionOp transactionOp()Allocate an operation that can be used withtransaction()
. NOTE:CuratorOp
instances created by this builder are reusable.- Returns:
- operation builder
-
sync
Deprecated.usesync()
insteadPerform a sync on the given path - syncs are always in the background- Parameters:
path
- the pathbackgroundContextObject
- optional context
-
createContainers
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
RemoveWatchesBuilder watches()Deprecated.usewatchers()
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, throwsIllegalStateException
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.Since 2.9.0 - useusingNamespace(java.lang.String)
passingnull
Returns a facade of the current instance that does _not_ automatically pre-pend the namespace to all paths- Returns:
- facade
-
usingNamespace
Returns a facade of the current instance that uses the specified namespace or no namespace ifnewNamespace
isnull
.- 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.Allocates an ensure path instance that is namespace aware- Parameters:
path
- path to ensure- Returns:
- new EnsurePath instance
-
clearWatcherReferences
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 usenewWatcherRemoveCuratorFramework()
callingWatcherRemoveCuratorFramework.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
Block until a connection to ZooKeeper is available or the maxWaitTime has been exceeded- Parameters:
maxWaitTime
- The maximum wait time. 1.value <= 0
andunits != null
to return immediately; 2.value <= 0
andunits == null
to wait indefinitely, which is same asblockUntilConnected()
.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
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 viaWatcherRemoveCuratorFramework.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
Callsinvalid reference
#notifyAll()
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
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
-