ractor::actor::actor_ref

Struct ActorRef

Source
pub struct ActorRef<TMessage> { /* private fields */ }
Expand description

An ActorRef is a strongly-typed wrapper over an ActorCell to provide some syntactic wrapping on the requirement to pass the actor’s message type everywhere.

An ActorRef is the primary means of communication typically used when interfacing with super::Actors

Implementations§

Source§

impl<TMessage> ActorRef<TMessage>

Source

pub fn get_cell(&self) -> ActorCell

Retrieve a cloned ActorCell representing this ActorRef

Source

pub fn notify_supervisor_and_monitors(&self, evt: SupervisionEvent)

Notify the supervisor and all monitors that a supervision event occurred. Monitors receive a reduced copy of the supervision event which won’t contain the crate::actor::BoxedState and collapses the crate::ActorProcessingErr exception to a String

  • evt - The event to send to this crate::Actor’s supervisors
Source§

impl<TMessage> ActorRef<TMessage>
where TMessage: Message,

Source

pub fn send_message( &self, message: TMessage, ) -> Result<(), MessagingErr<TMessage>>

Send a strongly-typed message, constructing the boxed message on the fly

  • message - The message to send

Returns [Ok(())] on successful message send, [Err(MessagingErr)] otherwise

Source

pub fn where_is(name: ActorName) -> Option<ActorRef<TMessage>>

Try and retrieve a strongly-typed actor from the registry.

Alias of crate::registry::where_is

Source§

impl<TMessage: Message> ActorRef<TMessage>

Source

pub fn get_derived<TFrom>(&self) -> DerivedActorRef<TFrom>
where TMessage: From<TFrom>, TFrom: TryFrom<TMessage>,

Constructs the DerivedActorRef for a specific type from ActorRef. This allows an actor which handles either a subset of the full actor’s messages or a convertable type, allowing hiding of the original message type through implementation of From conversion.

Returns a DerivedActorRef where the message type is convertable to the ActorRef’s original message type via From. In order to facilitate MessagingErr::SendErr the original message type also needs to be reverse convertable via TryFrom to the TFrom type.

This method will panic if a send error occurs, and the returned message cannot be converted back to the TFrom type. This should never happen, unless conversions are created incorrectly.

Source§

impl<TKey, TMsg> ActorRef<FactoryMessage<TKey, RetriableMessage<TKey, TMsg>>>
where TKey: JobKey, TMsg: Message,

Source

pub fn submit_retriable_job( &self, job: Job<TKey, TMsg>, strategy: MessageRetryStrategy, ) -> Result<(), MessagingErr<FactoryMessage<TKey, RetriableMessage<TKey, TMsg>>>>

When you’re talking to a factory, which accepts “retriable” jobs, this convenience function sets up the retriable state for you and converts your job to a retriable equivalent.

  • job: The traditional Job which will be auto-converted into a Job of RetriableMessage for you however the accepted field, if set, will be dropped as RetriableMessages do not support accepted replies, except on the first iteration
  • strategy: The MessageRetryStrategy to use for this retriable message

Returns the result from the underlying cast operation to the factory’s ActorRef.

Source§

impl<TMessage> ActorRef<TMessage>
where TMessage: Message,

Source

pub fn cast(&self, msg: TMessage) -> Result<(), MessagingErr<TMessage>>

Alias of cast

Source

pub async fn call<TReply, TMsgBuilder>( &self, msg_builder: TMsgBuilder, timeout_option: Option<Duration>, ) -> Result<CallResult<TReply>, MessagingErr<TMessage>>
where TMsgBuilder: FnOnce(RpcReplyPort<TReply>) -> TMessage,

Alias of call

Source

pub fn call_and_forward<TReply, TForwardMessage, TMsgBuilder, TFwdMessageBuilder>( &self, msg_builder: TMsgBuilder, response_forward: &ActorRef<TForwardMessage>, forward_mapping: TFwdMessageBuilder, timeout_option: Option<Duration>, ) -> Result<JoinHandle<CallResult<Result<(), MessagingErr<TForwardMessage>>>>, MessagingErr<TMessage>>
where TReply: Send + 'static, TMsgBuilder: FnOnce(RpcReplyPort<TReply>) -> TMessage, TForwardMessage: Message, TFwdMessageBuilder: FnOnce(TReply) -> TForwardMessage + Send + 'static,

Source§

impl<TMessage> ActorRef<TMessage>
where TMessage: Message,

Add the timing functionality on top of the crate::ActorRef

Source

pub fn send_interval<F>(&self, period: Duration, msg: F) -> JoinHandle<()>
where F: Fn() -> TMessage + Send + 'static,

Alias of send_interval

Source

pub fn send_after<F>( &self, period: Duration, msg: F, ) -> JoinHandle<Result<(), MessagingErr<TMessage>>>
where F: FnOnce() -> TMessage + Send + 'static,

Alias of send_after

Source

pub fn exit_after(&self, period: Duration) -> JoinHandle<()>

Alias of exit_after

Source

pub fn kill_after(&self, period: Duration) -> JoinHandle<()>

Alias of kill_after

Methods from Deref<Target = ActorCell>§

Source

pub fn get_id(&self) -> ActorId

Retrieve the super::Actor’s unique identifier ActorId

Source

pub fn get_name(&self) -> Option<ActorName>

Retrieve the super::Actor’s name

Source

pub fn get_status(&self) -> ActorStatus

Retrieve the current status of an super::Actor

Returns the super::Actor’s current ActorStatus

Link this super::Actor to the provided supervisor

Unlink this super::Actor from the supervisor if it’s currently linked (if self’s supervisor is supervisor)

  • supervisor - The supervisor to unlink this super::Actor from
Source

pub fn kill(&self)

Kill this super::Actor forcefully (terminates async work)

Source

pub async fn kill_and_wait( &self, timeout: Option<Duration>, ) -> Result<(), RactorErr<()>>

Kill this super::Actor forcefully (terminates async work) and wait for the actor shutdown to complete

  • timeout - An optional timeout duration to wait for shutdown to occur

Returns [Ok(())] upon the actor being stopped/shutdown. [Err(RactorErr::Messaging(_))] if the channel is closed or dropped (which may indicate some other process is trying to shutdown this actor) or [Err(RactorErr::Timeout)] if timeout was hit before the actor was successfully shut down (when set)

Source

pub fn stop(&self, reason: Option<String>)

Stop this super::Actor gracefully (stopping message processing)

  • reason - An optional string reason why the stop is occurring
Source

pub async fn stop_and_wait( &self, reason: Option<String>, timeout: Option<Duration>, ) -> Result<(), RactorErr<StopMessage>>

Stop the super::Actor gracefully (stopping messaging processing) and wait for the actor shutdown to complete

  • reason - An optional string reason why the stop is occurring
  • timeout - An optional timeout duration to wait for shutdown to occur

Returns [Ok(())] upon the actor being stopped/shutdown. [Err(RactorErr::Messaging(_))] if the channel is closed or dropped (which may indicate some other process is trying to shutdown this actor) or [Err(RactorErr::Timeout)] if timeout was hit before the actor was successfully shut down (when set)

Source

pub async fn wait(&self, timeout: Option<Duration>) -> Result<(), Timeout>

Wait for the actor to exit, optionally within a timeout

  • timeout: If supplied, the amount of time to wait before returning an error and cancelling the wait future.

IMPORTANT: If the timeout is hit, the actor is still running. You should wait again for its exit.

Source

pub fn send_message<TMessage>( &self, message: TMessage, ) -> Result<(), MessagingErr<TMessage>>
where TMessage: Message,

Send a strongly-typed message, constructing the boxed message on the fly

Note: The type requirement of TActor assures that TMsg is the supported message type for TActor such that we can’t send boxed messages of an unsupported type to the specified actor.

  • message - The message to send

Returns [Ok(())] on successful message send, [Err(MessagingErr)] otherwise

Source

pub fn drain(&self) -> Result<(), MessagingErr<()>>

Drain the actor’s message queue and when finished processing, terminate the actor.

Any messages received after the drain marker but prior to shutdown will be rejected

Source

pub async fn drain_and_wait( &self, timeout: Option<Duration>, ) -> Result<(), RactorErr<()>>

Drain the actor’s message queue and when finished processing, terminate the actor, notifying on this handler that the actor has drained and exited (stopped).

  • timeout: The optional amount of time to wait for the drain to complete.

Any messages received after the drain marker but prior to shutdown will be rejected

Source

pub fn notify_supervisor(&self, evt: SupervisionEvent)

Notify the supervisor and all monitors that a supervision event occurred. Monitors receive a reduced copy of the supervision event which won’t contain the crate::actor::BoxedState and collapses the crate::ActorProcessingErr exception to a String

  • evt - The event to send to this super::Actor’s supervisors
Source

pub fn stop_children(&self, reason: Option<String>)

Stop any children of this actor, not waiting for their exit, and threading the optional reason to all children

  • reason: The stop reason to send to all the children

This swallows and communication errors because if you can’t send a message to the child, it’s dropped the message channel, and is dead/stopped already.

Source

pub fn try_get_supervisor(&self) -> Option<ActorCell>

Tries to retrieve this actor’s supervisor.

Returns None if this actor has no supervisor at the given instance or [Some(ActorCell)] supervisor if one is configured.

Source

pub async fn stop_children_and_wait( &self, reason: Option<String>, timeout: Option<Duration>, )

Stop any children of this actor, and wait for their collective exit, optionally threading the optional reason to all children

  • reason: The stop reason to send to all the children
  • timeout: An optional timeout which is the maximum time to wait for the actor stop operation to complete

This swallows and communication errors because if you can’t send a message to the child, it’s dropped the message channel, and is dead/stopped already.

Source

pub fn drain_children(&self)

Drain any children of this actor, not waiting for their exit

This swallows and communication errors because if you can’t send a message to the child, it’s dropped the message channel, and is dead/stopped already.

Source

pub async fn drain_children_and_wait(&self, timeout: Option<Duration>)

Drain any children of this actor, and wait for their collective exit

  • timeout: An optional timeout which is the maximum time to wait for the actor stop operation to complete
Source

pub fn get_children(&self) -> Vec<ActorCell>

Retrieve the supervised children of this actor (if any)

Returns a Vec of ActorCells which are the children that are presently linked to this actor.

Source

pub fn get_type_id(&self) -> TypeId

Retrieve the TypeId of this ActorCell which can be helpful for quick type-checking.

HOWEVER: Note this is an unstable identifier, and changes between Rust releases and may not be stable over a network call.

Source

pub fn is_message_type_of<TMessage: Message>(&self) -> Option<bool>

Runtime check the message type of this actor, which only works for local actors, as remote actors send serializable messages, and can’t have their message type runtime checked.

Returns None if the actor is a remote actor, and we cannot perform a runtime message type check. Otherwise [Some(true)] for the correct message type or [Some(false)] for an incorrect type will returned.

Trait Implementations§

Source§

impl<TMessage> Clone for ActorRef<TMessage>

Source§

fn clone(&self) -> Self

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
Source§

impl<TMessage> Debug for ActorRef<TMessage>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<TMessage> Deref for ActorRef<TMessage>

Source§

type Target = ActorCell

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<TMessage> From<ActorCell> for ActorRef<TMessage>

Source§

fn from(value: ActorCell) -> Self

Converts to this type from the input type.
Source§

impl<TActor> From<ActorRef<TActor>> for ActorCell

Source§

fn from(value: ActorRef<TActor>) -> Self

Converts to this type from the input type.
Source§

impl<I, O> OutputPortSubscriberTrait<I> for ActorRef<O>
where I: Message + Clone, O: Message + From<I>,

Source§

fn subscribe_to_port(&self, port: &OutputPort<I>)

Subscribe to the output port

Auto Trait Implementations§

§

impl<TMessage> Freeze for ActorRef<TMessage>

§

impl<TMessage> RefUnwindSafe for ActorRef<TMessage>

§

impl<TMessage> Send for ActorRef<TMessage>

§

impl<TMessage> Sync for ActorRef<TMessage>

§

impl<TMessage> Unpin for ActorRef<TMessage>

§

impl<TMessage> UnwindSafe for ActorRef<TMessage>

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> 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> Message for T
where T: Any + Send + 'static,

Source§

fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>

Convert a BoxedMessage to this concrete type
Source§

fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>

Convert this message to a BoxedMessage
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.
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
Source§

impl<T> OutputMessage for T
where T: Message + Clone,

Source§

impl<T> State for T
where T: Any + Send + 'static,