public class ZookeeperSession extends Object implements ClusterInfoSession, DisruptibleSession
Modifier and Type | Class and Description |
---|---|
protected class |
ZookeeperSession.WatcherProxy |
protected static class |
ZookeeperSession.ZkWatcher |
Modifier and Type | Field and Description |
---|---|
protected String |
connectString |
protected long |
resetDelay |
protected int |
sessionTimeout |
Modifier | Constructor and Description |
---|---|
protected |
ZookeeperSession(Serializer serializer,
String connectString,
int sessionTimeout) |
Modifier and Type | Method and Description |
---|---|
void |
disrupt() |
boolean |
exists(String ppath,
ClusterInfoWatcher watcher)
Check if a path has already been created.
|
Object |
getData(String ppath,
ClusterInfoWatcher watcher)
If data is stored at the node indicated by the path, then the data will be returned.
|
Collection<String> |
getSubdirs(String ppath,
ClusterInfoWatcher pwatcher)
Show all of the subdirectories of the given directory.
|
protected ZookeeperSession.WatcherProxy |
makeWatcherProxy(ClusterInfoWatcher watcher) |
protected org.apache.zookeeper.ZooKeeper |
makeZooKeeperClient(String connectString,
int sessionTimeout)
This is defined here to be overridden in a test.
|
String |
mkdir(String path,
Object data,
DirMode mode)
This will create a node at the given path.
|
void |
rmdir(String ppath)
This will remove the directory stored at the path.
|
void |
setData(String ppath,
Object info)
Set the data associated with the tree node identified by the path.
|
void |
stop()
Stop the session.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, recursiveMkdir
protected long resetDelay
protected String connectString
protected int sessionTimeout
protected ZookeeperSession(Serializer serializer, String connectString, int sessionTimeout) throws IOException
IOException
public String mkdir(String path, Object data, DirMode mode) throws ClusterInfoException
ClusterInfoSession
mkdir
in interface ClusterInfoSession
path
- a '/' separated path to a directory in the cluster information manager to create.data
- optional data to set for that directorymode
- is the mode to set for the new directory. See DirMode
.null
if the directory cannot be created
or already exists. If the DirMode
is sequential then the result will satisfy the SEQUENTIAL
requirements (see DirMode
for the details).ClusterInfoException
- on an error which can include the fact that the parent directory doesn't exist (when it
should throw a ClusterInfoException.NoParentException
) or if you add a directory as a subdir of an
EPHEMERAL directory.public void rmdir(String ppath) throws ClusterInfoException
ClusterInfoSession
rmdir
in interface ClusterInfoSession
ppath
- is the directory to delete.ClusterInfoException
- if there is no node at the given path.public boolean exists(String ppath, ClusterInfoWatcher watcher) throws ClusterInfoException
ClusterInfoSession
exists
in interface ClusterInfoSession
ppath
- is the directory to checkwatcher
- if non-null, and the path exists, then the watcher will be called back whenever the node at the path has data added to it, or is deleted.ClusterInfoException
- if there is an unforeseen problem.public Object getData(String ppath, ClusterInfoWatcher watcher) throws ClusterInfoException
ClusterInfoSession
getData
in interface ClusterInfoSession
ppath
- place to put the data.watcher
- if non-null, and the path exists, then the watcher will be called back whenever the node at the path has data added to it, or is deleted.ClusterInfoException
public void setData(String ppath, Object info) throws ClusterInfoException
ClusterInfoSession
setData
in interface ClusterInfoSession
ppath
- identify the directory/tree node of the place to store the datainfo
- the data to put at the given location.ClusterInfoException
public Collection<String> getSubdirs(String ppath, ClusterInfoWatcher pwatcher) throws ClusterInfoException
ClusterInfoSession
getSubdirs
in interface ClusterInfoSession
ppath
- where the subdirectories to show are.pwatcher
- if non-null, and the path exists, then the watcher will be called back whenever the node at the path has data added to it, or is deleted.ClusterInfoException
public void stop()
ClusterInfoSession
stop
in interface ClusterInfoSession
public void disrupt()
disrupt
in interface DisruptibleSession
protected org.apache.zookeeper.ZooKeeper makeZooKeeperClient(String connectString, int sessionTimeout) throws IOException
IOException
protected ZookeeperSession.WatcherProxy makeWatcherProxy(ClusterInfoWatcher watcher)
Copyright © 2018. All rights reserved.