java.io.Closeable, java.lang.AutoCloseablepublic class PersistentTtlNode
extends java.lang.Object
implements java.io.Closeable
Manages a PersistentNode that uses CreateMode.CONTAINER. Asynchronously
it creates or updates a child on the persistent node that is marked with a provided TTL.
The effect of this is to have a node that can be watched, etc. The child node serves as a method of having the parent node deleted if the TTL expires. i.e. if the process that is running the PersistentTtlNode crashes and the TTL elapses, first the child node will be deleted due to the TTL expiration and then the parent node will be deleted as it's a container node with no children.
PersistentTtlNode is useful when you need to create a TTL node but don't want to keep it alive manually by periodically setting data - PersistentTtlNode does that for you. Further the keep-alive is done in a way that does not generate watch triggers on the parent node.
| Modifier and Type | Field | Description |
|---|---|---|
static java.lang.String |
DEFAULT_CHILD_NODE_NAME |
|
static int |
DEFAULT_TOUCH_SCHEDULE_FACTOR |
| Constructor | Description |
|---|---|
PersistentTtlNode(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
long ttlMs,
byte[] initData) |
|
PersistentTtlNode(org.apache.curator.framework.CuratorFramework client,
java.util.concurrent.ScheduledExecutorService executorService,
java.lang.String path,
long ttlMs,
byte[] initData,
java.lang.String childNodeName,
int touchScheduleFactor) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
Call when you are done with the PersistentTtlNode.
|
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 ttl 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 static final java.lang.String DEFAULT_CHILD_NODE_NAME
public static final int DEFAULT_TOUCH_SCHEDULE_FACTOR
public PersistentTtlNode(org.apache.curator.framework.CuratorFramework client,
java.lang.String path,
long ttlMs,
byte[] initData)
client - the clientpath - path for the parent ZNodettlMs - max ttl for the node in millisecondsinitData - data for the nodepublic PersistentTtlNode(org.apache.curator.framework.CuratorFramework client,
java.util.concurrent.ScheduledExecutorService executorService,
java.lang.String path,
long ttlMs,
byte[] initData,
java.lang.String childNodeName,
int touchScheduleFactor)
client - the clientexecutorService - ExecutorService to use for background thread. This service should be single threaded, otherwise you may see inconsistent results.path - path for the parent ZNodettlMs - max ttl for the node in millisecondsinitData - data for the nodechildNodeName - name to use for the child node of the node created at pathtouchScheduleFactor - how ofter to set/create the child node as a factor of the ttlMs. i.e.
the child is touched every (ttlMs / touchScheduleFactor)public 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 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()
public void close()
close in interface java.lang.AutoCloseableclose in interface java.io.CloseableCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.