org.talend.esb.servicelocator.client.internal.zk
Class ZKBackend

java.lang.Object
  extended by org.talend.esb.servicelocator.client.internal.zk.ZKBackend
All Implemented Interfaces:
ServiceLocatorBackend

public class ZKBackend
extends Object
implements ServiceLocatorBackend


Nested Class Summary
static interface ZKBackend.NodeMapper<T>
           
 class ZKBackend.WatcherImpl
           
 
Field Summary
static NodePath LOCATOR_ROOT_PATH
           
static Charset UTF8_CHAR_SET
           
 
Constructor Summary
ZKBackend()
           
 
Method Summary
 RootNode connect()
          Establish a connection to the Service Locator.
 void createNode(NodePath path, org.apache.zookeeper.CreateMode mode, byte[] content)
           
protected  org.apache.zookeeper.ZooKeeper createZooKeeper(CountDownLatch connectionLatch)
           
 boolean deleteNode(NodePath path, boolean canHaveChildren)
           
 void disconnect()
          Disconnects from a Service Locator server.
 void ensurePathDeleted(NodePath path, boolean canHaveChildren)
           
 void ensurePathExists(NodePath path, org.apache.zookeeper.CreateMode mode)
           
 void ensurePathExists(NodePath path, org.apache.zookeeper.CreateMode mode, byte[] content)
           
<T> List<T>
getChildren(NodePath path, ZKBackend.NodeMapper<T> mapper)
           
 byte[] getContent(NodePath path)
           
 RootNode getRootNode()
           
 boolean isConnected()
           
 boolean nodeExists(NodePath path)
           
 void setConnectionTimeout(int timeout)
          Specify the time this client waits for a connection to get established.
 void setLocatorEndpoints(String endpoints)
          Specify the endpoints of all the instances belonging to the service locator ensemble this object might potentially be talking to when connecting.
 void setNodeData(NodePath path, byte[] content)
           
 void setPassword(String passWord)
           
 void setPostConnectAction(ServiceLocator.PostConnectAction postConnectAction)
          Specify the action to be be executed after the Service Locator has connected to the server.
 void setSessionTimeout(int timeout)
          Specify the time out of the session established at the server.
 void setUserName(String userName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCATOR_ROOT_PATH

public static final NodePath LOCATOR_ROOT_PATH

UTF8_CHAR_SET

public static final Charset UTF8_CHAR_SET
Constructor Detail

ZKBackend

public ZKBackend()
Method Detail

connect

public RootNode connect()
                 throws InterruptedException,
                        ServiceLocatorException
Description copied from interface: ServiceLocatorBackend
Establish a connection to the Service Locator. After successful connection the specified ServiceLocator.PostConnectAction is run. If the session to the server expires because the server could not be reached within the specified time, a reconnect is automatically executed as soon as the server can be reached again. Because after a session time out all registered endpoints are removed it is important to specify a ServiceLocator.PostConnectAction that re-registers all endpoints.

Specified by:
connect in interface ServiceLocatorBackend
Throws:
InterruptedException - the current Thread was interrupted when waiting for a successful connection to the ServiceLocator
ServiceLocatorException - the connect operation failed

disconnect

public void disconnect()
                throws InterruptedException,
                       ServiceLocatorException
Description copied from interface: ServiceLocatorBackend
Disconnects from a Service Locator server. All endpoints that were registered before are removed from the server. To be able to communicate with a Service Locator server again the client has to connect again.

Specified by:
disconnect in interface ServiceLocatorBackend
Throws:
InterruptedException - the current Thread was interrupted when waiting for the disconnect to happen
ServiceLocatorException

isConnected

public boolean isConnected()
Specified by:
isConnected in interface ServiceLocatorBackend

getRootNode

public RootNode getRootNode()
                     throws InterruptedException,
                            ServiceLocatorException
Throws:
InterruptedException
ServiceLocatorException

nodeExists

public boolean nodeExists(NodePath path)
                   throws ServiceLocatorException,
                          InterruptedException
Throws:
ServiceLocatorException
InterruptedException

createNode

public void createNode(NodePath path,
                       org.apache.zookeeper.CreateMode mode,
                       byte[] content)
                throws org.apache.zookeeper.KeeperException,
                       InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

setNodeData

public void setNodeData(NodePath path,
                        byte[] content)
                 throws ServiceLocatorException,
                        InterruptedException
Throws:
ServiceLocatorException
InterruptedException

deleteNode

public boolean deleteNode(NodePath path,
                          boolean canHaveChildren)
                   throws org.apache.zookeeper.KeeperException,
                          InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getChildren

public <T> List<T> getChildren(NodePath path,
                               ZKBackend.NodeMapper<T> mapper)
                    throws ServiceLocatorException,
                           InterruptedException
Throws:
ServiceLocatorException
InterruptedException

getContent

public byte[] getContent(NodePath path)
                  throws ServiceLocatorException,
                         InterruptedException
Throws:
ServiceLocatorException
InterruptedException

ensurePathExists

public void ensurePathExists(NodePath path,
                             org.apache.zookeeper.CreateMode mode)
                      throws ServiceLocatorException,
                             InterruptedException
Throws:
ServiceLocatorException
InterruptedException

ensurePathExists

public void ensurePathExists(NodePath path,
                             org.apache.zookeeper.CreateMode mode,
                             byte[] content)
                      throws ServiceLocatorException,
                             InterruptedException
Throws:
ServiceLocatorException
InterruptedException

ensurePathDeleted

public void ensurePathDeleted(NodePath path,
                              boolean canHaveChildren)
                       throws ServiceLocatorException,
                              InterruptedException
Parameters:
path - Path to the node to be removed
canHaveChildren - If false method throws an exception in case we have KeeperException with code NotEmpty. If true, node just not be deleted in case we have Keeper NotEmptyException.
Throws:
ServiceLocatorException
InterruptedException

setPostConnectAction

public void setPostConnectAction(ServiceLocator.PostConnectAction postConnectAction)
Description copied from interface: ServiceLocatorBackend
Specify the action to be be executed after the Service Locator has connected to the server.

Specified by:
setPostConnectAction in interface ServiceLocatorBackend
Parameters:
postConnectAction - the action to be executed, must not be null.

setLocatorEndpoints

public void setLocatorEndpoints(String endpoints)
Specify the endpoints of all the instances belonging to the service locator ensemble this object might potentially be talking to when connecting. The object will one by one pick an endpoint (the order is non-deterministic) to connect to the service locator until a connection is established.

Parameters:
endpoints - comma separated list of endpoints,each corresponding to a service locator instance. Each endpoint is specified as a host:port pair. At least one endpoint must be specified. Valid exmaples are: "127.0.0.1:2181" or "sl1.example.com:3210, sl2.example.com:3210, sl3.example.com:3210"

setSessionTimeout

public void setSessionTimeout(int timeout)
Specify the time out of the session established at the server. The session is kept alive by requests sent by this client object. If the session is idle for a period of time that would timeout the session, the client will send a PING request to keep the session alive.

Parameters:
sessionTimeout - timeout in milliseconds, must be greater than zero and less than 60000.

setConnectionTimeout

public void setConnectionTimeout(int timeout)
Specify the time this client waits for a connection to get established.

Parameters:
connectionTimeout - timeout in milliseconds, must be greater than zero

setUserName

public void setUserName(String userName)

setPassword

public void setPassword(String passWord)

createZooKeeper

protected org.apache.zookeeper.ZooKeeper createZooKeeper(CountDownLatch connectionLatch)
                                                  throws ServiceLocatorException
Throws:
ServiceLocatorException


Copyright © 2011-2013 Talend Inc.. All Rights Reserved.