Struct ractor::actor::actor_ref::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

The ActorRef is SPECIFICALLY marked Sync, regardless of the message type because all usages of the message type are to send an owned instance of a message and in no case is that message instance shared across threads. This is guaranteed by the underlying Tokio channel usages. Without this manual marking of Sync on ActorRef, we would need to constrain the message type Message to be Sync which is overly restrictive.

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> 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 monitor(&self, who: ActorCell)

Monitor the provided super::Actor for supervision events. An actor in ractor can only have a single supervisor, denoted by the link function, however they may have multiple monitors. Monitor’s receive copies of the SupervisionEvents, with non-cloneable information removed.

  • who: The actor to monitor
source

pub fn unmonitor(&self, who: ActorCell)

Stop monitoring the provided super::Actor for supervision events.

  • who: The actor to stop monitoring
source

pub fn clear_monitors(&self)

Clear all the self::Actors which are monitored by this self::Actor

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 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 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 super::Actor’s supervisors

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>

§

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

impl<T> Sync for ActorRef<T>

Auto Trait Implementations§

§

impl<TMessage> Freeze for ActorRef<TMessage>

§

impl<TMessage> !RefUnwindSafe for ActorRef<TMessage>

§

impl<TMessage> Send for ActorRef<TMessage>
where TMessage: Send,

§

impl<TMessage> Unpin for ActorRef<TMessage>
where TMessage: Unpin,

§

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

§

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

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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,