org.apache.curator.framework.recipes.nodes
Class PersistentEphemeralNode

java.lang.Object
  extended by org.apache.curator.framework.recipes.nodes.PersistentEphemeralNode
All Implemented Interfaces:
Closeable

public class PersistentEphemeralNode
extends Object
implements Closeable

A persistent ephemeral node is an ephemeral 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


Nested Class Summary
static class PersistentEphemeralNode.Mode
          The mode for node creation
 
Constructor Summary
PersistentEphemeralNode(org.apache.curator.framework.CuratorFramework client, PersistentEphemeralNode.Mode mode, String basePath, byte[] data)
           
 
Method Summary
 void close()
           
 String getActualPath()
          Returns the currently set path or null if the node does not exist
 void setData(byte[] data)
          Set data that ephemeral node should set in ZK also writes the data to the node
 void start()
          You must call start() to initiate the persistent ephemeral node.
 boolean waitForInitialCreate(long timeout, TimeUnit unit)
          Block until the either initial node creation initiated by start() succeeds or the timeout elapses.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistentEphemeralNode

public PersistentEphemeralNode(org.apache.curator.framework.CuratorFramework client,
                               PersistentEphemeralNode.Mode mode,
                               String basePath,
                               byte[] data)
Parameters:
client - client instance
mode - creation/protection mode
basePath - the base path for the node
data - data for the node
Method Detail

start

public void start()
You must call start() to initiate the persistent ephemeral node. An attempt to create the node in the background will be started


waitForInitialCreate

public boolean waitForInitialCreate(long timeout,
                                    TimeUnit unit)
                             throws InterruptedException
Block until the either initial node creation initiated by start() succeeds or the timeout elapses.

Parameters:
timeout - the maximum time to wait
unit - time unit
Returns:
if the node was created before timeout
Throws:
InterruptedException - if the thread is interrupted

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

getActualPath

public String getActualPath()
Returns the currently set path or null if the node does not exist

Returns:
node path or null

setData

public void setData(byte[] data)
             throws Exception
Set data that ephemeral node should set in ZK also writes the data to the node

Parameters:
data - new data value
Throws:
Exception - errors


Copyright © 2011–2014 The Apache Software Foundation. All rights reserved.