Class PersistentNode
java.lang.Object
org.apache.curator.framework.recipes.nodes.PersistentNode
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
PersistentEphemeralNode
A persistent node is a node that attempts to stay present in ZooKeeper, even through connection and session interruptions.
Thanks to bbeck (https://github.com/bbeck) for the initial coding and design
-
Constructor Summary
ConstructorDescriptionPersistentNode
(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData) PersistentNode
(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData, boolean useParentCreation) PersistentNode
(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData, long ttl, boolean useParentCreation) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
protected void
Returns the currently set path or null if the node does not existbyte[]
getData()
Return the current value of our dataReturns the listenablevoid
setData
(byte[] data) Set data that node should set in ZK also writes the data to the node.void
start()
You must call start() to initiate the persistent node.boolean
waitForInitialCreate
(long timeout, TimeUnit unit) Block until the either initial node creation initiated bystart()
succeeds or the timeout elapses.
-
Constructor Details
-
PersistentNode
public PersistentNode(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData) - Parameters:
givenClient
- client instancemode
- creation modeuseProtection
- if true, callCreateBuilderMain.withProtection()
basePath
- the base path for the nodeinitData
- data for the node
-
PersistentNode
public PersistentNode(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData, boolean useParentCreation) - Parameters:
givenClient
- client instancemode
- creation modeuseProtection
- if true, callCreateBuilderMain.withProtection()
basePath
- the base path for the nodeinitData
- data for the nodeuseParentCreation
- if true, callCreateBuilderMain.creatingParentContainersIfNeeded()
-
PersistentNode
public PersistentNode(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData, long ttl, boolean useParentCreation) - Parameters:
givenClient
- client instancemode
- creation modeuseProtection
- if true, callCreateBuilderMain.withProtection()
basePath
- the base path for the nodeinitData
- data for the nodettl
- for ttl modes, the ttl to useuseParentCreation
- if true, callCreateBuilderMain.creatingParentContainersIfNeeded()
-
-
Method Details
-
start
public void start()You must call start() to initiate the persistent node. An attempt to create the node in the background will be started -
waitForInitialCreate
Block until the either initial node creation initiated bystart()
succeeds or the timeout elapses.- Parameters:
timeout
- the maximum time to waitunit
- time unit- Returns:
- if the node was created before timeout
- Throws:
InterruptedException
- if the thread is interrupted
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getListenable
Returns the listenable- Returns:
- listenable
-
getActualPath
Returns the currently set path or null if the node does not exist- Returns:
- node path or null
-
setData
Set data that node should set in ZK also writes the data to the node. NOTE: it is an error to call this method afterstart()
but before the initial create has completed. UsewaitForInitialCreate(long, TimeUnit)
to ensure initial creation.- Parameters:
data
- new data value- Throws:
Exception
- errors
-
getData
public byte[] getData()Return the current value of our data- Returns:
- our data
-
deleteNode
- Throws:
Exception
-