pub struct PathChildrenCache { /* private fields */ }
Expand description

A Path Cache is used to watch a znode.

A utility that attempts to keep all data from all children of a ZK path locally cached. This will watch the ZK path; whenever a child is added, updated or removed, the Path Cache will change its state to contain the current set of children, the children’s data and the children’s state. You can register a listener that will get notified when changes occur.

§Note

It is not possible to stay transactionally in sync. Users of this class must be prepared for false-positives and false-negatives. Additionally, always use the version number when updating data to avoid overwriting another process’s change.

Implementations§

source§

impl PathChildrenCache

source

pub async fn new(zk: Arc<ZooKeeper>, path: &str) -> ZkResult<PathChildrenCache>

Create a new cache instance watching path. If path does not exist, it will be created (see ZooKeeperExt::ensure_path).

§Note

After creating the instance, you must call start.

source

pub async fn get_current_data(&self) -> Data

Return the current data. There are no guarantees of accuracy. This is merely the most recent view of the data.

source

pub async fn clear(&self)

source

pub fn start(&mut self) -> ZkResult<()>

Start the cache. The cache is not started automatically. You must call this method.

source

pub fn add_listener<Listener: Fn(PathChildrenCacheEvent) + Send + 'static>( &self, subscriber: Listener ) -> Subscription

source

pub fn remove_listener(&self, sub: Subscription)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more