public class PersistentNode extends Object implements Closeable
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 and Description |
---|
PersistentNode(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) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
deleteNode() |
String |
getActualPath()
Returns the currently set path or null if the node does not exist
|
byte[] |
getData()
Return the current value of our data
|
Listenable<PersistentNodeListener> |
getListenable()
Returns the listenable
|
void |
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 by
start() succeeds or
the timeout elapses. |
public PersistentNode(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData)
givenClient
- client instancemode
- creation modeuseProtection
- if true, call CreateBuilderMain.withProtection()
basePath
- the base path for the nodeinitData
- data for the nodepublic PersistentNode(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData, boolean useParentCreation)
givenClient
- client instancemode
- creation modeuseProtection
- if true, call CreateBuilderMain.withProtection()
basePath
- the base path for the nodeinitData
- data for the nodeuseParentCreation
- if true, call CreateBuilderMain.creatingParentContainersIfNeeded()
public PersistentNode(CuratorFramework givenClient, org.apache.zookeeper.CreateMode mode, boolean useProtection, String basePath, byte[] initData, long ttl, boolean useParentCreation)
givenClient
- client instancemode
- creation modeuseProtection
- if true, call CreateBuilderMain.withProtection()
basePath
- the base path for the nodeinitData
- data for the nodettl
- for ttl modes, the ttl to useuseParentCreation
- if true, call CreateBuilderMain.creatingParentContainersIfNeeded()
public void start()
public boolean waitForInitialCreate(long timeout, TimeUnit unit) throws InterruptedException
start()
succeeds or
the timeout elapses.timeout
- the maximum time to waitunit
- time unitInterruptedException
- if the thread is interruptedpublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public Listenable<PersistentNodeListener> getListenable()
public String getActualPath()
public void setData(byte[] data) throws Exception
start()
but before the initial create
has completed. Use waitForInitialCreate(long, TimeUnit)
to ensure initial
creation.data
- new data valueException
- errorspublic byte[] getData()
Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.