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(org.apache.curator.framework.CuratorFramework client,
org.apache.zookeeper.CreateMode mode,
boolean useProtection,
String basePath,
byte[] initData) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
String |
getActualPath()
Returns the currently set path or null if the node does not exist
|
byte[] |
getData()
Return the current value of our data
|
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(org.apache.curator.framework.CuratorFramework client,
org.apache.zookeeper.CreateMode mode,
boolean useProtection,
String basePath,
byte[] initData)
client - client instancemode - creation modeuseProtection - if true, call CreateBuilder.withProtection()basePath - the base path for the nodeinitData - data for the nodepublic 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 Closeableclose in interface AutoCloseableIOExceptionpublic 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–2018 The Apache Software Foundation. All rights reserved.