Apache Mesos
|
#include <zookeeper.hpp>
Public Member Functions | |
ZooKeeper (const std::string &servers, const Duration &sessionTimeout, Watcher *watcher) | |
instantiate new ZooKeeper client. More... | |
~ZooKeeper () | |
int | getState () |
get the state of the zookeeper connection. More... | |
int64_t | getSessionId () |
get the current session id. More... | |
Duration | getSessionTimeout () const |
get the current session timeout. More... | |
int | authenticate (const std::string &scheme, const std::string &credentials) |
authenticate synchronously. More... | |
int | create (const std::string &path, const std::string &data, const ACL_vector &acl, int flags, std::string *result, bool recursive=false) |
create a node synchronously. More... | |
int | remove (const std::string &path, int version) |
delete a node in zookeeper synchronously. More... | |
int | exists (const std::string &path, bool watch, Stat *stat) |
checks the existence of a node in zookeeper synchronously. More... | |
int | get (const std::string &path, bool watch, std::string *result, Stat *stat) |
gets the data associated with a node synchronously. More... | |
int | getChildren (const std::string &path, bool watch, std::vector< std::string > *results) |
lists the children of a node synchronously. More... | |
int | set (const std::string &path, const std::string &data, int version) |
sets the data associated with a node. More... | |
std::string | message (int code) const |
return a message describing the return code. More... | |
bool | retryable (int code) |
returns whether or not the specified return code implies the operation can be retried "as is" (i.e., without needing to change anything). More... | |
Protected Attributes | |
ZooKeeperProcess * | process |
ZooKeeper::ZooKeeper | ( | const std::string & | servers, |
const Duration & | sessionTimeout, | ||
Watcher * | watcher | ||
) |
instantiate new ZooKeeper client.
The constructor initiates a new session, however session establishment is asynchronous, meaning that the session should not be considered established until (and unless) an event of state ZOO_CONNECTED_STATE is received.
servers | comma-separated host:port pairs, each corresponding to a ZooKeeper server. e.g. "127.0.0.1:3000,127.0.0.1:3001" |
watcher | the instance of Watcher that receives event callbacks. When notifications are triggered the Watcher::process method will be invoked. |
ZooKeeper::~ZooKeeper | ( | ) |
int ZooKeeper::authenticate | ( | const std::string & | scheme, |
const std::string & | credentials | ||
) |
authenticate synchronously.
int ZooKeeper::create | ( | const std::string & | path, |
const std::string & | data, | ||
const ACL_vector & | acl, | ||
int | flags, | ||
std::string * | result, | ||
bool | recursive = false |
||
) |
create a node synchronously.
This method will create a node in ZooKeeper. A node can only be created if it does not already exists. The Create Flags affect the creation of nodes. If ZOO_EPHEMERAL flag is set, the node will automatically get removed if the client session goes away. If the ZOO_SEQUENCE flag is set, a unique monotonically increasing sequence number is appended to the path name.
path | The name of the node. Expressed as a file name with slashes separating ancestors of the node. |
data | The data to be stored in the node. |
acl | The initial ACL of the node. If null, the ACL of the parent will be used. |
flags | this parameter can be set to 0 for normal create or an OR of the Create Flags |
result | A string which will be filled with the path of the new node (this might be different than the supplied path because of the ZOO_SEQUENCE flag). The path string will always be null-terminated. |
recursive | if true, attempts to create all intermediate znodes as required; note that 'flags' and 'data' will only be applied to the creation of 'basename(path)'. |
int ZooKeeper::exists | ( | const std::string & | path, |
bool | watch, | ||
Stat * | stat | ||
) |
checks the existence of a node in zookeeper synchronously.
path | the name of the node. Expressed as a file name with slashes separating ancestors of the node. |
watch | if true, a watch will be set at the server to notify the client if the node changes. The watch will be set even if the node does not exist. This allows clients to watch for nodes to appear. |
stat | the return stat value of the node. |
int ZooKeeper::get | ( | const std::string & | path, |
bool | watch, | ||
std::string * | result, | ||
Stat * | stat | ||
) |
gets the data associated with a node synchronously.
path | the name of the node. Expressed as a file name with slashes separating ancestors of the node. |
watch | if nonzero, a watch will be set at the server to notify the client if the node changes. |
result | the data returned by the server |
stat | if not nullptr , will hold the value of stat for the path on return. |
int ZooKeeper::getChildren | ( | const std::string & | path, |
bool | watch, | ||
std::vector< std::string > * | results | ||
) |
lists the children of a node synchronously.
path | the name of the node. Expressed as a file name with slashes separating ancestors of the node. |
watch | if true, a watch will be set at the server to notify the client if the node changes. |
results | return value of children paths. |
int64_t ZooKeeper::getSessionId | ( | ) |
get the current session id.
The current session id or 0 if no session is established.
Duration ZooKeeper::getSessionTimeout | ( | ) | const |
get the current session timeout.
The session timeout requested by the client or the negotiated session timeout after the session is established with ZooKeeper. Note that this might differ from the initial sessionTimeout
specified when this instance was constructed.
int ZooKeeper::getState | ( | ) |
get the state of the zookeeper connection.
The return value will be one of the State Consts.
std::string ZooKeeper::message | ( | int | code | ) | const |
return a message describing the return code.
int ZooKeeper::remove | ( | const std::string & | path, |
int | version | ||
) |
delete a node in zookeeper synchronously.
path | the name of the node. Expressed as a file name with slashes separating ancestors of the node. |
version | the expected version of the node. The function will fail if the actual version of the node does not match the expected version. If -1 is used the version check will not take place. |
bool ZooKeeper::retryable | ( | int | code | ) |
returns whether or not the specified return code implies the operation can be retried "as is" (i.e., without needing to change anything).
int ZooKeeper::set | ( | const std::string & | path, |
const std::string & | data, | ||
int | version | ||
) |
sets the data associated with a node.
path | the name of the node. Expressed as a file name with slashes separating ancestors of the node. |
data | the data to be written to the node. |
version | the expected version of the node. The function will fail if the actual version of the node does not match the expected version. If -1 is used the version check will not take place. |
|
protected |