Struct Watcher

Source
pub struct Watcher { /* private fields */ }
Expand description

The Watcher is the hub where updates are published regarding tables that updated when observing a connection.

All changes are published to a background thread which then notifies the respective TableObservers.

§Observing Tables

To be notified of changes, register an observer with Watcher::add_observer.

The Watcher by itself does not automatically watch all tables. The observed tables are driven by the tables defined by each TableObserver.

A table can be observed by many TableObserver. When the last TableObserver is removed for a given table, that table stops being tracked.

§Update Propagation

Every time a TableObserver is added or removed, the list of tracked tables is updated and a counter is bumped. These changes are propagated to State instances when they sync their state State::sync_tables().

Due to the nature of concurrent operations, it is possible that a connection on different thread will miss the changes applied from adding/removing an observer on the current thread. On the next sync this will be rectified.

If both operation happen on the same thread, everything will work as expected.

§Notifications

To notify the Watcher of changed tables, an instance of either Connection or State needs to be used. Check each type for more information on how to use it correctly.

§Remarks

The Watcher currently maintains a list of observed tables that is never pruned. It will keep growing with every new table that is observed. If you have af fixed set of tables that you watch on a regular basis this is not an issue. If you have a dynamic list of tables deleted tables are currently not removed. To be addressed in the future.

Implementations§

Source§

impl Watcher

Source

pub fn new() -> Result<Arc<Self>, Error>

Create a new instance of an in process tracker service.

§Errors

Returns error if the worker thread fails to spawn.

Source

pub fn add_observer( &self, observer: Box<dyn TableObserver>, ) -> Result<TableObserverHandle, Error>

Register a new observer with a list of interested tables.

This function returns a TableObserverHandle which can later be used to remove the current observer.

§Errors

Returns error if the command which adds the observer to the background thread could not be sent or the handle could not be retrieved.

Source

pub fn add_observer_with_drop_remove( self: &Arc<Self>, observer: Box<dyn TableObserver>, ) -> Result<DropRemoveTableObserverHandle, Error>

Same as Self::add_observer, but returns a handle that removes the observer from this Watcher on drop.

§Errors

See Self::add_observer for more details.

Source

pub fn remove_observer_deferred( &self, handle: TableObserverHandle, ) -> Result<(), Error>

Remove an observer via its handle without waiting for the operation to complete.

The removal of observers is deferred to the background thread and will be executed as soon as possible.

If you wish to wait for an observer to finish being removed from the list, you should use Self::remove_observer()

§Errors

Returns error if the command to remove the observer could not be sent.

Source

pub fn remove_observer(&self, handle: TableObserverHandle) -> Result<(), Error>

Remove an observer via its handle and wait for it to be removed.

If you wish do not wish to wait for an observer to finish being removed from the list, you should use Self::remove_observer_deferred()

§Errors

Returns error if the command to remove the observer could not be sent or the reply could not be received.

Source

pub fn observed_tables(&self) -> Vec<String>

Return the list of observed tables at this point in time.

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>,

Source§

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>,

Source§

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