com.twitter.common.zookeeper
Class ZooKeeperUtils

java.lang.Object
  extended by com.twitter.common.zookeeper.ZooKeeperUtils

public final class ZooKeeperUtils
extends Object

Utilities for dealing with zoo keeper.


Field Summary
static int ANY_VERSION
          The magic version number that allows any mutation to always succeed regardless of actual version number.
static Amount<Integer,Time> DEFAULT_ZK_SESSION_TIMEOUT
          An appropriate default session timeout for Twitter ZooKeeper clusters.
static ImmutableList<org.apache.zookeeper.data.ACL> EVERYONE_READ_CREATOR_ALL
          An ACL that gives all permissions to node creators and read permissions only to everyone else.
 
Method Summary
static void ensurePath(ZooKeeperClient zkClient, List<org.apache.zookeeper.data.ACL> acl, String path)
          Ensures the given path exists in the ZK cluster accessed by zkClient.
static boolean isRetryable(org.apache.zookeeper.KeeperException e)
          Returns true if the given exception indicates an error that can be resolved by retrying the operation without modification.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ZK_SESSION_TIMEOUT

public static final Amount<Integer,Time> DEFAULT_ZK_SESSION_TIMEOUT
An appropriate default session timeout for Twitter ZooKeeper clusters.


ANY_VERSION

public static final int ANY_VERSION
The magic version number that allows any mutation to always succeed regardless of actual version number.

See Also:
Constant Field Values

EVERYONE_READ_CREATOR_ALL

public static final ImmutableList<org.apache.zookeeper.data.ACL> EVERYONE_READ_CREATOR_ALL
An ACL that gives all permissions to node creators and read permissions only to everyone else.

Method Detail

isRetryable

public static boolean isRetryable(org.apache.zookeeper.KeeperException e)
Returns true if the given exception indicates an error that can be resolved by retrying the operation without modification.

Parameters:
e - the exception to check
Returns:
true if the causing operation is strictly retryable

ensurePath

public static void ensurePath(ZooKeeperClient zkClient,
                              List<org.apache.zookeeper.data.ACL> acl,
                              String path)
                       throws ZooKeeperClient.ZooKeeperConnectionException,
                              InterruptedException,
                              org.apache.zookeeper.KeeperException
Ensures the given path exists in the ZK cluster accessed by zkClient. If the path already exists, nothing is done; however if any portion of the path is missing, it will be created with the given acl as a persistent zookeeper node. The given path must be a valid zookeeper absolute path.

Parameters:
zkClient - the client to use to access the ZK cluster
acl - the acl to use if creating path nodes
path - the path to ensure exists
Throws:
ZooKeeperClient.ZooKeeperConnectionException - if there was a problem accessing the ZK cluster
InterruptedException - if we were interrupted attempting to connect to the ZK cluster
org.apache.zookeeper.KeeperException - if there was a problem in ZK