Struct ractor::actor::actor_cell::ActorCell

source ·
pub struct ActorCell { /* private fields */ }
Expand description

An ActorCell is a reference to an Actor’s communication channels and provides external access to send messages, stop, kill, and generally interactor with the underlying Actor process.

The input ports contained in the cell will return an error should the underlying actor have terminated and no longer exist.

Implementations§

source§

impl 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 Clone for ActorCell

source§

fn clone(&self) -> ActorCell

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 Debug for ActorCell

source§

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

Formats the value using the given formatter. Read more
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.

Auto Trait Implementations§

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,