pub struct Client<C>
where C: ManagedClient + Clone + Send + Sync + 'static, C::PubReceiver: Send + Sync,
{ /* private fields */ }
Expand description

State store client implementation

Implementations§

Source§

impl<C> Client<C>

Source

pub fn new( application_context: ApplicationContext, client: C, connection_monitor: SessionConnectionMonitor, options: ClientOptions, ) -> Result<Self, Error>

Create a new State Store Client

Note: connection_monitor must be from the same session as client.

§Errors

Error of kind AIOProtocolError is possible if there are any errors creating the underlying command invoker or telemetry receiver, but it should not happen

§Panics

Possible panics when building options for the underlying command invoker or telemetry receiver, but they should be unreachable because we control the static parameters that go into these calls.

Source

pub async fn shutdown(&self) -> Result<(), Error>

Shutdown the state_store::Client. Shuts down the command invoker and telemetry receiver and cancels the receiver loop to drop the receiver and to prevent the task from looping indefinitely.

Note: If this method is called, the state_store::Client should not be used again. If the method returns an error, it may be called again to attempt the unsubscribe again.

Returns Ok(()) on success, otherwise returns Error.

§Errors

Error of kind AIOProtocolError if the unsubscribe fails or if the unsuback reason code doesn’t indicate success.

Source

pub async fn set( &self, key: Vec<u8>, value: Vec<u8>, timeout: Duration, fencing_token: Option<HybridLogicalClock>, options: SetOptions, ) -> Result<Response<bool>, Error>

Sets a key value pair in the State Store Service

Note: timeout refers to the duration until the State Store Client stops waiting for a Set response from the Service. This value is not linked to the key in the State Store. It is rounded up to the nearest second.

Returns true if the Set completed successfully, or false if the Set did not occur because of values specified in SetOptions

§Errors

Error of kind KeyLengthZero if the key is empty

Error of kind InvalidArgument if the timeout is zero or > u32::max

Error of kind ServiceError if the State Store returns an Error response

Error of kind UnexpectedPayload if the State Store returns a response that isn’t valid for a Set request

Error of kind AIOProtocolError if there are any underlying errors from rpc_command::Invoker::invoke

Source

pub async fn get( &self, key: Vec<u8>, timeout: Duration, ) -> Result<Response<Option<Vec<u8>>>, Error>

Gets the value of a key in the State Store Service

Note: timeout refers to the duration until the State Store Client stops waiting for a Get response from the Service. This value is not linked to the key in the State Store. It is rounded up to the nearest second.

Returns Some(<value of the key>) if the key is found or None if the key was not found

§Errors

Error of kind KeyLengthZero if the key is empty

Error of kind InvalidArgument if the timeout is zero or > u32::max

Error of kind ServiceError if the State Store returns an Error response

Error of kind UnexpectedPayload if the State Store returns a response that isn’t valid for a Get request

Error of kind AIOProtocolError if there are any underlying errors from rpc_command::Invoker::invoke

Source

pub async fn del( &self, key: Vec<u8>, fencing_token: Option<HybridLogicalClock>, timeout: Duration, ) -> Result<Response<i64>, Error>

Deletes a key from the State Store Service

Note: timeout refers to the duration until the State Store Client stops waiting for a Delete response from the Service. This value is not linked to the key in the State Store. It is rounded up to the nearest second.

Returns the number of keys deleted. Will be 0 if the key was not found, otherwise 1

§Errors

Error of kind KeyLengthZero if the key is empty

Error of kind InvalidArgument if the timeout is zero or > u32::max

Error of kind ServiceError if the State Store returns an Error response

Error of kind UnexpectedPayload if the State Store returns a response that isn’t valid for a Delete request

Error of kind AIOProtocolError if there are any underlying errors from rpc_command::Invoker::invoke

Source

pub async fn vdel( &self, key: Vec<u8>, value: Vec<u8>, fencing_token: Option<HybridLogicalClock>, timeout: Duration, ) -> Result<Response<i64>, Error>

Deletes a key from the State Store Service if and only if the value matches the one provided

Note: timeout refers to the duration until the State Store Client stops waiting for a V Delete response from the Service. This value is not linked to the key in the State Store. It is rounded up to the nearest second.

Returns the number of keys deleted. Will be 0 if the key was not found, -1 if the value did not match, otherwise 1

§Errors

Error of kind KeyLengthZero if the key is empty

Error of kind InvalidArgument if the timeout is zero or > u32::max

Error of kind ServiceError if the State Store returns an Error response

Error of kind UnexpectedPayload if the State Store returns a response that isn’t valid for a V Delete request

Error of kind AIOProtocolError if there are any underlying errors from rpc_command::Invoker::invoke

Source

pub async fn observe( &self, key: Vec<u8>, timeout: Duration, ) -> Result<Response<KeyObservation>, Error>

Starts observation of any changes on a key from the State Store Service

Note: timeout is rounded up to the nearest second.

Returns OK(state_store::Response<KeyObservation>) if the key is now being observed. The KeyObservation can be used to receive key notifications for this key

If a client disconnects, it must resend the Observe for any keys it needs to continue monitoring. Unlike MQTT subscriptions, which can be persisted across a nonclean session, the state store internally removes any key observations when a given client disconnects. This is a known limitation of the service, see here for more information

§Errors

Error of kind KeyLengthZero if

  • the key is empty

Error of kind InvalidArgument if

  • the timeout is zero or > u32::max

Error of kind ServiceError if

  • the State Store returns an Error response
  • the State Store returns a response that isn’t valid for an Observe request

Error of kind AIOProtocolError if

Source

pub async fn unobserve( &self, key: Vec<u8>, timeout: Duration, ) -> Result<Response<bool>, Error>

Stops observation of any changes on a key from the State Store Service

Note: timeout is rounded up to the nearest second.

Returns true if the key is no longer being observed or false if the key wasn’t being observed

§Errors

Error of kind KeyLengthZero if

  • the key is empty

Error of kind InvalidArgument if

  • the timeout is zero or > u32::max

Error of kind ServiceError if

  • the State Store returns an Error response
  • the State Store returns a response that isn’t valid for an Unobserve request

Error of kind AIOProtocolError if

Trait Implementations§

Source§

impl<C> Drop for Client<C>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<C> Freeze for Client<C>
where C: Freeze,

§

impl<C> !RefUnwindSafe for Client<C>

§

impl<C> Send for Client<C>

§

impl<C> Sync for Client<C>

§

impl<C> Unpin for Client<C>
where C: Unpin,

§

impl<C> !UnwindSafe for Client<C>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V