Fork me on GitHub

Persistent TTL Node


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. It also provides similar guarantees that a Persistent Node does: the node attempts to stay present in ZooKeeper, even through connection and session interruptions.

Participating Classes

  • PersistentNode
  • PersistentTtlNode


Creating a PersistentTtlNode

public PersistentTtlNode(CuratorFramework client,
                               String path,
                               long ttlMs,
                               byte[] initData)
client - client instance
path path for the parent ZNode
ttlMs max ttl for the node in milliseconds
initData - initData for the node

General Usage

PersistentTtlNode must be started:


When you are through with the PersistentTtlNode instance, you should call close:


NOTE: this will NOT delete the node immediately. The node will get deleted based on the ttl.

Error Handling

PersistentTtlNode instances internally handle all error states recreating the node as necessary.