org.linkedin.zookeeper.client
Class ZKClient

java.lang.Object
  extended by org.linkedin.zookeeper.client.AbstractZooKeeper
      extended by org.linkedin.zookeeper.client.AbstractZKClient
          extended by org.linkedin.zookeeper.client.ZKClient
All Implemented Interfaces:
org.apache.zookeeper.Watcher, org.linkedin.util.lifecycle.Destroyable, org.linkedin.util.lifecycle.Startable, org.linkedin.util.lifecycle.Terminable, IZKClient, IZooKeeper

public class ZKClient
extends AbstractZKClient
implements org.linkedin.util.lifecycle.Startable, org.linkedin.util.lifecycle.Destroyable, org.apache.zookeeper.Watcher


Nested Class Summary
static class ZKClient.State
           
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event
 
Field Summary
static org.slf4j.Logger log
           
static java.lang.String MODULE
           
 
Constructor Summary
ZKClient(IZooKeeperFactory factory)
          Constructor
ZKClient(IZooKeeperFactory factory, java.lang.String chroot)
          Constructor
ZKClient(java.lang.String connectString, org.linkedin.util.clock.Timespan sessionTimeout, org.apache.zookeeper.Watcher watcher)
          Constructor
 
Method Summary
 IZKClient chroot(java.lang.String path)
           
 void destroy()
           
 org.linkedin.util.clock.Clock getClock()
           
 IZooKeeperFactory getFactory()
           
 java.util.Set<LifecycleListener> getListeners()
           
 org.linkedin.util.clock.Timespan getReconnectTimeout()
           
protected  IZooKeeper getZk()
           
 ZKClient.State getZKClientState()
           
 boolean isConnected()
           
 void process(org.apache.zookeeper.WatchedEvent event)
           
 void registerListener(LifecycleListener listener)
          When the listener is set, it will receive the LifecycleListener.onConnected() callback right away if ZooKeeper is already connected.
 void removeListener(LifecycleListener listener)
          Removes a listener previously set with registerListener(LifecycleListener)
 void setClock(org.linkedin.util.clock.Clock clock)
           
 void setReconnectTimeout(org.linkedin.util.clock.Timespan reconnectTimeout)
           
 void start()
           
 void waitForStart()
          Wait (no longer than timeout if provided) for the client to be started
 void waitForStart(org.linkedin.util.clock.Timespan timeout)
          Wait (no longer than timeout if provided) for the client to be started
 void waitForState(ZKClient.State state, org.linkedin.util.clock.Timespan timeout)
          Wait (no longer than timeout if provided) for the client to be started
 
Methods inherited from class org.linkedin.zookeeper.client.AbstractZKClient
create, createBytesNode, createBytesNodeWithParents, createOrSetWithParents, createWithParents, delete, deleteWithChildren, exists, getAllChildren, getChildren, getData, getStringData, getZKByteData, getZKByteData, getZKChildren, getZKStringData, getZKStringData, setByteData, setData
 
Methods inherited from class org.linkedin.zookeeper.client.AbstractZooKeeper
addAuthInfo, adjustPath, adjustPath, close, create, create, delete, delete, exists, exists, exists, exists, getACL, getACL, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getData, getData, getData, getData, getSessionId, getSessionPasswd, getSessionTimeout, getState, register, setACL, setACL, setData, setData, sync
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.linkedin.zookeeper.client.IZooKeeper
addAuthInfo, close, create, create, delete, delete, exists, exists, exists, exists, getACL, getACL, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getChildren, getData, getData, getData, getData, getSessionId, getSessionPasswd, getSessionTimeout, getState, register, setACL, setACL, setData, setData, sync
 

Field Detail

MODULE

public static final java.lang.String MODULE

log

public static final org.slf4j.Logger log
Constructor Detail

ZKClient

public ZKClient(java.lang.String connectString,
                org.linkedin.util.clock.Timespan sessionTimeout,
                org.apache.zookeeper.Watcher watcher)
Constructor


ZKClient

public ZKClient(IZooKeeperFactory factory)
Constructor


ZKClient

public ZKClient(IZooKeeperFactory factory,
                java.lang.String chroot)
Constructor

Method Detail

getZKClientState

public ZKClient.State getZKClientState()

getFactory

public IZooKeeperFactory getFactory()

getClock

public org.linkedin.util.clock.Clock getClock()

setClock

public void setClock(org.linkedin.util.clock.Clock clock)

getReconnectTimeout

public org.linkedin.util.clock.Timespan getReconnectTimeout()

setReconnectTimeout

public void setReconnectTimeout(org.linkedin.util.clock.Timespan reconnectTimeout)

getListeners

public java.util.Set<LifecycleListener> getListeners()

registerListener

public void registerListener(LifecycleListener listener)
When the listener is set, it will receive the LifecycleListener.onConnected() callback right away if ZooKeeper is already connected. This guarantees that you will never miss the connected event irrelevant of whether you set the listener before or after calling start().

Specified by:
registerListener in interface IZKClient
Parameters:
listener - the listener

removeListener

public void removeListener(LifecycleListener listener)
Removes a listener previously set with registerListener(LifecycleListener)

Specified by:
removeListener in interface IZKClient
Parameters:
listener -

chroot

public IZKClient chroot(java.lang.String path)
Specified by:
chroot in interface IZKClient
Returns:
a new client with the path that has been chrooted... meaning all paths will be relative to the path provided.

start

public void start()
Specified by:
start in interface org.linkedin.util.lifecycle.Startable

isConnected

public boolean isConnected()
Specified by:
isConnected in interface IZKClient
Returns:
true if connected

waitForStart

public void waitForStart()
                  throws java.lang.InterruptedException
Wait (no longer than timeout if provided) for the client to be started

Throws:
java.lang.InterruptedException

waitForStart

public void waitForStart(org.linkedin.util.clock.Timespan timeout)
                  throws java.util.concurrent.TimeoutException,
                         java.lang.InterruptedException
Wait (no longer than timeout if provided) for the client to be started

Throws:
java.util.concurrent.TimeoutException
java.lang.InterruptedException

waitForState

public void waitForState(ZKClient.State state,
                         org.linkedin.util.clock.Timespan timeout)
                  throws java.util.concurrent.TimeoutException,
                         java.lang.InterruptedException
Wait (no longer than timeout if provided) for the client to be started

Throws:
java.util.concurrent.TimeoutException
java.lang.InterruptedException

destroy

public void destroy()
Specified by:
destroy in interface org.linkedin.util.lifecycle.Destroyable

process

public void process(org.apache.zookeeper.WatchedEvent event)
Specified by:
process in interface org.apache.zookeeper.Watcher

getZk

protected IZooKeeper getZk()
                    throws org.linkedin.util.exceptions.InternalException
Specified by:
getZk in class AbstractZooKeeper
Throws:
org.linkedin.util.exceptions.InternalException