Struct tokio_zookeeper::ZooKeeper [−][src]
pub struct ZooKeeper { /* fields omitted */ }
A connection to ZooKeeper.
All interactions with ZooKeeper are performed by calling the methods of a ZooKeeper
instance.
All clones of the same ZooKeeper
instance use the same underlying connection. Once a
connection to a server is established, a session ID is assigned to the client. The client will
send heart beats to the server periodically to keep the session valid.
The application can call ZooKeeper APIs through a client as long as the session ID of the
client remains valid. If for some reason, the client fails to send heart beats to the server
for a prolonged period of time (exceeding the session timeout value, for instance), the server
will expire the session, and the session ID will become invalid. The ZooKeeper
instance will
then no longer be usable, and all futures will resolve with a protocol-level error. To make
further ZooKeeper API calls, the application must create a new ZooKeeper
instance.
If the ZooKeeper server the client currently connects to fails or otherwise does not respond, the client will automatically try to connect to another server before its session ID expires. If successful, the application can continue to use the client.
Some successful ZooKeeper API calls can leave watches on the "data nodes" in the ZooKeeper server. Other successful ZooKeeper API calls can trigger those watches. Once a watch is triggered, an event will be delivered to the client which left the watch at the first place. Each watch can be triggered only once. Thus, up to one event will be delivered to a client for every watch it leaves.
Methods
impl ZooKeeper
[src]
impl ZooKeeper
pub fn connect(
addr: &SocketAddr
) -> impl Future<Item = (Self, impl Stream<Item = WatchedEvent, Error = ()>), Error = Error>
[src]
pub fn connect(
addr: &SocketAddr
) -> impl Future<Item = (Self, impl Stream<Item = WatchedEvent, Error = ()>), Error = Error>
Connect to a ZooKeeper server instance at the given address with default parameters.
pub fn create<D, A>(
self,
path: &str,
data: D,
acl: A,
mode: CreateMode
) -> impl Future<Item = (Self, Result<String, Create>), Error = Error> where
D: Into<Cow<'static, [u8]>>,
A: Into<Cow<'static, [Acl]>>,
[src]
pub fn create<D, A>(
self,
path: &str,
data: D,
acl: A,
mode: CreateMode
) -> impl Future<Item = (Self, Result<String, Create>), Error = Error> where
D: Into<Cow<'static, [u8]>>,
A: Into<Cow<'static, [Acl]>>,
Create a node with the given path
with data
as its contents.
The mode
argument specifies additional options for the newly created node.
If mode
is set to CreateMode::Ephemeral
(or CreateMode::EphemeralSequential
), the
node will be removed by the ZooKeeper automatically when the session associated with the
creation of the node expires.
If mode
is set to CreateMode::PersistentSequential
or
CreateMode::EphemeralSequential
, the actual path name of a sequential node will be the
given path
plus a suffix i
where i
is the current sequential number of the node. The
sequence number is always fixed length of 10 digits, 0 padded. Once such a node is created,
the sequential number will be incremented by one. The newly created node's full name is
returned when the future is resolved.
If a node with the same actual path already exists in the ZooKeeper, the returned future
resolves with an error of error::Create::NodeExists
. Note that since a different actual
path is used for each invocation of creating sequential nodes with the same path
argument, calls with sequential modes will never return NodeExists
.
Ephemeral nodes cannot have children in ZooKeeper. Therefore, if the parent node of the
given path
is ephemeral, the return future resolves to
error::Create::NoChildrenForEphemerals
.
If a node is created successfully, the ZooKeeper server will trigger the watches on the
path
left by exists
calls, and the watches on the parent of the node by get_children
calls.
The maximum allowable size of the data array is 1 MB (1,048,576 bytes).
pub fn delete(
self,
path: &str,
version: Option<i32>
) -> impl Future<Item = (Self, Result<(), Delete>), Error = Error>
[src]
pub fn delete(
self,
path: &str,
version: Option<i32>
) -> impl Future<Item = (Self, Result<(), Delete>), Error = Error>
Delete the node at the given path
. The call will succeed if such a node exists, and the
given version
matches the node's version (if the given version
is None
, it matches
any node's versions).
This operation, if successful, will trigger all the watches on the node of the given path
left by exists
API calls, and the watches on the parent node left by get_children
API
calls.
impl ZooKeeper
[src]
impl ZooKeeper
pub fn watch(self) -> WatchGlobally
[src]
pub fn watch(self) -> WatchGlobally
Add a global watch for the next chained operation.
pub fn with_watcher(self) -> WithWatcher
[src]
pub fn with_watcher(self) -> WithWatcher
Add a watch for the next chained operation, and return a future for any received event along with the operation's (successful) result.
pub fn exists(
self,
path: &str
) -> impl Future<Item = (Self, Option<Stat>), Error = Error>
[src]
pub fn exists(
self,
path: &str
) -> impl Future<Item = (Self, Option<Stat>), Error = Error>
Return the Stat
of the node of the given path
, or None
if the node does not exist.
pub fn get_children(
self,
path: &str
) -> impl Future<Item = (Self, Option<Vec<String>>), Error = Error>
[src]
pub fn get_children(
self,
path: &str
) -> impl Future<Item = (Self, Option<Vec<String>>), Error = Error>
Return the names of the children of the node at the given path
, or None
if the node
does not exist.
The returned list of children is not sorted and no guarantee is provided as to its natural or lexical order.
pub fn get_data(
self,
path: &str
) -> impl Future<Item = (Self, Option<(Vec<u8>, Stat)>), Error = Error>
[src]
pub fn get_data(
self,
path: &str
) -> impl Future<Item = (Self, Option<(Vec<u8>, Stat)>), Error = Error>
Return the data and the Stat
of the node at the given path
, or None
if it does not
exist.
Trait Implementations
impl Debug for ZooKeeper
[src]
impl Debug for ZooKeeper
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Clone for ZooKeeper
[src]
impl Clone for ZooKeeper