pub struct Client<C>{ /* private fields */ }
Expand description
State store client implementation
Implementations§
Source§impl<C> Client<C>
impl<C> Client<C>
Sourcepub fn new(
application_context: ApplicationContext,
client: C,
connection_monitor: SessionConnectionMonitor,
options: ClientOptions,
) -> Result<Self, Error>
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.
Sourcepub async fn shutdown(&self) -> Result<(), Error>
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.
Sourcepub async fn set(
&self,
key: Vec<u8>,
value: Vec<u8>,
timeout: Duration,
fencing_token: Option<HybridLogicalClock>,
options: SetOptions,
) -> Result<Response<bool>, Error>
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
Sourcepub async fn get(
&self,
key: Vec<u8>,
timeout: Duration,
) -> Result<Response<Option<Vec<u8>>>, Error>
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
Sourcepub async fn del(
&self,
key: Vec<u8>,
fencing_token: Option<HybridLogicalClock>,
timeout: Duration,
) -> Result<Response<i64>, Error>
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
Sourcepub async fn vdel(
&self,
key: Vec<u8>,
value: Vec<u8>,
fencing_token: Option<HybridLogicalClock>,
timeout: Duration,
) -> Result<Response<i64>, Error>
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
Sourcepub async fn observe(
&self,
key: Vec<u8>,
timeout: Duration,
) -> Result<Response<KeyObservation>, Error>
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
- there are any underlying errors from
rpc_command::Invoker::invoke
Sourcepub async fn unobserve(
&self,
key: Vec<u8>,
timeout: Duration,
) -> Result<Response<bool>, Error>
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
- there are any underlying errors from
rpc_command::Invoker::invoke