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

Command Executor struct

§Example

let executor_options = rpc_command::executor::OptionsBuilder::default()
  .command_name("test_command")
  .request_topic_pattern("test/request")
  .build().unwrap();
let mut executor: rpc_command::Executor<Vec<u8>, Vec<u8>, _> = rpc_command::Executor::new(application_context, mqtt_session.create_managed_client(), executor_options).unwrap();
// let request = executor.recv().await.unwrap();
// let response = rpc_command::executor::ResponseBuilder::default()
 // .payload(Vec::new()).unwrap()
 // .build().unwrap();
// let request.complete(response).await.unwrap();

Implementations§

Source§

impl<TReq, TResp, C> Executor<TReq, TResp, C>
where TReq: PayloadSerialize + Send + 'static, TResp: PayloadSerialize + Send + 'static, C: ManagedClient + Clone + Send + Sync + 'static, C::PubReceiver: Send + Sync + 'static,

Implementation of Command Executor.

Source

pub fn new( application_context: ApplicationContext, client: C, executor_options: Options, ) -> Result<Self, AIOProtocolError>

Create a new Executor.

§Arguments
  • application_context - ApplicationContext that the command executor is part of.
  • client - The MQTT client to use for communication.
  • executor_options - Configuration options.

Returns Ok(Executor) on success, otherwise returns AIOProtocolError.

§Errors

AIOProtocolError of kind ConfigurationInvalid if:

Source

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

Shutdown the Executor. Unsubscribes from the request topic.

Note: If this method is called, the Executor will no longer receive commands from the MQTT client, any command requests that have not been processed can still be received by the executor. If the method returns an error, it may be called again to attempt the unsubscribe again.

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

§Errors

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

Source

pub async fn recv( &mut self, ) -> Option<Result<Request<TReq, TResp>, AIOProtocolError>>

Receive a command request or None if there will be no more requests.

If there are messages:

Will also subscribe to the request topic if not already subscribed.

§Errors

AIOProtocolError of kind UnknownError if an error occurs while receiving the message.

AIOProtocolError of kind ClientError if the subscribe fails or if the suback reason code doesn’t indicate success.

AIOProtocolError of kind InternalLogicError if the command expiration time cannot be calculated.

Trait Implementations§

Source§

impl<TReq, TResp, C> Drop for Executor<TReq, TResp, C>
where TReq: PayloadSerialize + Send + 'static, TResp: PayloadSerialize + Send + 'static, C: ManagedClient + Clone + Send + Sync + 'static, C::PubReceiver: Send + Sync + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<TReq, TResp, C> Freeze for Executor<TReq, TResp, C>
where C: Freeze, <C as ManagedClient>::PubReceiver: Freeze,

§

impl<TReq, TResp, C> RefUnwindSafe for Executor<TReq, TResp, C>
where C: RefUnwindSafe, <C as ManagedClient>::PubReceiver: RefUnwindSafe, TReq: RefUnwindSafe, TResp: RefUnwindSafe,

§

impl<TReq, TResp, C> Send for Executor<TReq, TResp, C>

§

impl<TReq, TResp, C> Sync for Executor<TReq, TResp, C>
where TReq: Sync, TResp: Sync,

§

impl<TReq, TResp, C> Unpin for Executor<TReq, TResp, C>
where C: Unpin, <C as ManagedClient>::PubReceiver: Unpin, TReq: Unpin, TResp: Unpin,

§

impl<TReq, TResp, C> UnwindSafe for Executor<TReq, TResp, C>
where C: UnwindSafe, <C as ManagedClient>::PubReceiver: UnwindSafe, TReq: UnwindSafe, TResp: UnwindSafe,

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