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

Lease client struct.

Implementations§

Source§

impl<C> Client<C>

Lease client implementation

Notes: Do not call any of the methods of this client after the state_store parameter is shutdown. Calling any of the methods in this implementation after the state_store is shutdown results in undefined behavior.

Source

pub fn new( state_store: Arc<Client<C>>, lease_name: Vec<u8>, lease_holder_name: Vec<u8>, ) -> Result<Self, Error>

Create a new Lease Client.

Notes:

  • lease_holder_name is expected to be the client ID used in the underlying MQTT connection settings.
  • There must be only one instance of lease::Client per lease.
§Errors

Error of kind InvalidArgument if the either lease_name or lease_holder_name is empty.

Source

pub fn current_lease_fencing_token(&self) -> Option<HybridLogicalClock>

Gets the latest fencing token related to the most recent lease.

Returns either None or an actual Fencing Token (HybridLogicalClock). None means that either a lease has not been acquired previously with this client, or a lease renewal has failed (if lease auto-renewal is used). The presence of a HybridLogicalClock does not mean that it is the most recent (and thus valid) Fencing Token - this can happen in the scenario where auto-renewal has not been used and the lease has already expired.

§Panics

If the lock on the current_fencing_token is poisoned, which should not be possible.

Source

pub async fn acquire( &self, lease_expiration: Duration, request_timeout: Duration, renewal_period: Option<Duration>, ) -> Result<HybridLogicalClock, Error>

Attempts to acquire a lease, returning if it cannot be acquired after one attempt.

lease_expiration is how long the lease will remain held in the State Store after acquired, if not released before then. request_timeout is the maximum time the function will wait for receiving a response from the State Store service, it is rounded up to the nearest second. renewal_period is the frequency with which the lease will be auto-renewed by the lease client if acquired successfully. None (or zero) indicates the lease should not be auto-renewed.

Note: If lease auto-renewal is used when acquiring a lease, an auto-renewal task is spawned. To terminate this task and stop the lease auto-renewal, lease::Client::release() must be called. Simply dropping the lease::Client instance will not terminate the auto-renewal task. This logic is intended for a scenario where the lease::Client is cloned and a lease is acquired with auto-renewal by the original instance. If the original instance is dropped, its clone remains in control of the lease (through the auto-renewal task that remains active). Special attention must be used to avoid a memory leak if lease::Client::release() is never called in this scenario.

Returns Ok with a fencing token (HybridLogicalClock) if completed successfully, or Error if lease is not acquired.

§Errors

Error of kind InvalidArgument if the request_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 the command invoker

Error of kind LeaseAlreadyHeld if the lease is already in use by another holder

Error of kind MissingFencingToken if the fencing token in the service response is empty.

Source

pub async fn release(&self, request_timeout: Duration) -> Result<(), Error>

Releases a lease if and only if requested by the lease holder (same client id).

Note: request_timeout is rounded up to the nearest second.

Returns Ok() if lease is no longer held by this lease_holder, or Error otherwise.

Even if this method fails the current fencing token (obtained by calling current_lease_fencing_token()) is cleared and the auto-renewal task is terminated (if the lease was acquired using auto-renewal).

§Errors

Error of kind InvalidArgument if the request_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 the command invoker

§Panics

If the lock on the current_fencing_token is poisoned, which should not be possible.

Source

pub async fn observe( &self, request_timeout: Duration, ) -> Result<LeaseObservation, Error>

Starts observation of any changes on a lease

Note: request_timeout is rounded up to the nearest second.

Returns OK(LeaseObservation) if the lease is now being observed. The LeaseObservation can be used to receive lease notifications for this lease

If a client disconnects, observe must be called again by the user.

§Errors

Error of kind InvalidArgument if

  • the request_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 the command invoker
Source

pub async fn unobserve(&self, request_timeout: Duration) -> Result<bool, Error>

Stops observation of any changes on a lease.

Note: request_timeout is rounded up to the nearest second.

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

§Errors

Error of kind InvalidArgument if

  • the request_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 the command invoker
Source

pub async fn get_holder( &self, request_timeout: Duration, ) -> Result<Option<Vec<u8>>, Error>

Gets the name of the holder of a lease

Note: request_timeout is rounded up to the nearest second.

Returns Some(<holder of the lease>) if the lease is found or None if the lease was not found (i.e., was not acquired by anyone, already released or expired).

§Errors

Error of kind InvalidArgument if the request_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 the command invoker

Trait Implementations§

Source§

impl<C> Clone for Client<C>
where C: ManagedClient + Clone + Send + Sync + 'static + Clone, C::PubReceiver: Send + Sync,

Source§

fn clone(&self) -> Client<C>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<C> Freeze for Client<C>

§

impl<C> !RefUnwindSafe for Client<C>

§

impl<C> Send for Client<C>

§

impl<C> Sync for Client<C>

§

impl<C> Unpin for Client<C>

§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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