java.io.Closeable, java.lang.AutoCloseablePersistentEphemeralNodepublic class PersistentNode
extends java.lang.Object
implements java.io.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 | Description |
|---|---|
PersistentNode(org.apache.curator.framework.CuratorFramework givenClient,
org.apache.zookeeper.CreateMode mode,
boolean useProtection,
java.lang.String basePath,
byte[] initData) |
|
PersistentNode(org.apache.curator.framework.CuratorFramework givenClient,
org.apache.zookeeper.CreateMode mode,
boolean useProtection,
java.lang.String basePath,
byte[] initData,
long ttl) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
protected void |
deleteNode() |
|
java.lang.String |
getActualPath() |
Returns the currently set path or null if the node does not exist
|
byte[] |
getData() |
Return the current value of our data
|
org.apache.curator.framework.listen.ListenerContainer<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,
java.util.concurrent.TimeUnit unit) |
Block until the either initial node creation initiated by
start() succeeds or
the timeout elapses. |
public PersistentNode(org.apache.curator.framework.CuratorFramework givenClient,
org.apache.zookeeper.CreateMode mode,
boolean useProtection,
java.lang.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(org.apache.curator.framework.CuratorFramework givenClient,
org.apache.zookeeper.CreateMode mode,
boolean useProtection,
java.lang.String basePath,
byte[] initData,
long ttl)
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 usepublic void start()
public boolean waitForInitialCreate(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
start() succeeds or
the timeout elapses.timeout - the maximum time to waitunit - time unitjava.lang.InterruptedException - if the thread is interruptedpublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.io.IOExceptionpublic org.apache.curator.framework.listen.ListenerContainer<PersistentNodeListener> getListenable()
public java.lang.String getActualPath()
public void setData(byte[] data)
throws java.lang.Exception
start() but before the initial create
has completed. Use waitForInitialCreate(long, TimeUnit) to ensure initial
creation.data - new data valuejava.lang.Exception - errorspublic byte[] getData()
protected void deleteNode()
throws java.lang.Exception
java.lang.ExceptionCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.