public class ZKBackend extends Object implements ServiceLocatorBackend
| Modifier and Type | Class and Description |
|---|---|
static interface |
ZKBackend.NodeMapper<T> |
class |
ZKBackend.WatcherImpl |
| Modifier and Type | Field and Description |
|---|---|
static NodePath |
LOCATOR_ROOT_PATH |
static Charset |
UTF8_CHAR_SET |
| Constructor and Description |
|---|
ZKBackend() |
| Modifier and Type | Method and Description |
|---|---|
void |
addPostConnectAction(ServiceLocator.PostConnectAction postConnectAction)
Specify the action to be be executed after the Service Locator has
connected to the server.
|
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 |
removePostConnectAction(ServiceLocator.PostConnectAction postConnectAction)
Specify the action to be be executed after the Service Locator has
connected to the server.
|
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 |
setSessionTimeout(int timeout)
Specify the time out of the session established at the server.
|
void |
setUserName(String userName) |
public static final NodePath LOCATOR_ROOT_PATH
public static final Charset UTF8_CHAR_SET
public RootNode connect() throws InterruptedException, ServiceLocatorException
ServiceLocatorBackendServiceLocator.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.connect in interface ServiceLocatorBackendInterruptedException - the current Thread was interrupted when waiting
for a successful connection to the ServiceLocatorServiceLocatorException - the connect operation failedpublic void disconnect()
throws InterruptedException,
ServiceLocatorException
ServiceLocatorBackendconnect again.disconnect in interface ServiceLocatorBackendInterruptedException - the current Thread was interrupted when waiting
for the disconnect to happenServiceLocatorExceptionpublic boolean isConnected()
isConnected in interface ServiceLocatorBackendpublic RootNode getRootNode() throws InterruptedException, ServiceLocatorException
public boolean nodeExists(NodePath path) throws ServiceLocatorException, InterruptedException
public void createNode(NodePath path, org.apache.zookeeper.CreateMode mode, byte[] content) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic void setNodeData(NodePath path, byte[] content) throws ServiceLocatorException, InterruptedException
public boolean deleteNode(NodePath path, boolean canHaveChildren) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperExceptionInterruptedExceptionpublic <T> List<T> getChildren(NodePath path, ZKBackend.NodeMapper<T> mapper) throws ServiceLocatorException, InterruptedException
public byte[] getContent(NodePath path) throws ServiceLocatorException, InterruptedException
public void ensurePathExists(NodePath path, org.apache.zookeeper.CreateMode mode) throws ServiceLocatorException, InterruptedException
public void ensurePathExists(NodePath path, org.apache.zookeeper.CreateMode mode, byte[] content) throws ServiceLocatorException, InterruptedException
public void ensurePathDeleted(NodePath path, boolean canHaveChildren) throws ServiceLocatorException, InterruptedException
path - Path to the node to be removedcanHaveChildren - 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.ServiceLocatorExceptionInterruptedExceptionpublic void addPostConnectAction(ServiceLocator.PostConnectAction postConnectAction)
ServiceLocatorBackendaddPostConnectAction in interface ServiceLocatorBackendpostConnectAction - the action to be executed, must not be null.public void removePostConnectAction(ServiceLocator.PostConnectAction postConnectAction)
ServiceLocatorBackendremovePostConnectAction in interface ServiceLocatorBackendpostConnectAction - the action to be executed, must not be null.public void setLocatorEndpoints(String endpoints)
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.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"public void setSessionTimeout(int timeout)
timeout - timeout in milliseconds, must be greater than zero and less
than 60000.public void setConnectionTimeout(int timeout)
for a connection to
get established.timeout - timeout in milliseconds, must be greater than zeropublic void setUserName(String userName)
public void setPassword(String passWord)
protected org.apache.zookeeper.ZooKeeper createZooKeeper(CountDownLatch connectionLatch) throws ServiceLocatorException
ServiceLocatorExceptionCopyright © 2011–2016 Talend Inc.. All rights reserved.