Skip to main content

ActorCell

Struct 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<String>

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>(&self) -> Option<bool>
where TMessage: Message,

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.

Source

pub async fn spawn_linked<T>( &self, name: Option<String>, handler: T, startup_args: <T as Actor>::Arguments, ) -> Result<(ActorRef<<T as Actor>::Msg>, JoinHandle<()>), SpawnErr>
where T: Actor,

Spawn an actor of the given type as a child of this actor, automatically starting the actor. This ActorCell becomes the supervisor of the child actor.

  • name: A name to give the actor. Useful for global referencing or debug printing
  • handler The implementation of Self
  • startup_args: Arguments passed to the pre_start call of the Actor to facilitate startup and initial state creation

Returns a [Ok((ActorRef, JoinHandle<()>))] upon successful start, denoting the actor reference along with the join handle which will complete when the actor terminates. Returns [Err(SpawnErr)] if the actor failed to start

Source§

impl ActorCell

Source

pub async fn spawn_local_linked<T>( &self, name: Option<String>, startup_args: <T as ThreadLocalActor>::Arguments, spawner: ThreadLocalActorSpawner, ) -> Result<(ActorRef<<T as ThreadLocalActor>::Msg>, JoinHandle<()>), SpawnErr>

Spawn an actor of the given type as a thread-local child of this actor, automatically starting the actor. This ActorCell becomes the supervisor of the child actor.

  • name: A name to give the actor. Useful for global referencing or debug printing
  • handler The implementation of Self
  • startup_args: Arguments passed to the pre_start call of the ThreadLocalActor to facilitate startup and initial state creation

Returns a [Ok((ActorRef, JoinHandle<()>))] upon successful start, denoting the actor reference along with the join handle which will complete when the actor terminates. Returns [Err(SpawnErr)] if the actor failed to start

Trait Implementations§

Source§

impl Clone for ActorCell

Source§

fn clone(&self) -> ActorCell

Returns a duplicate 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<(), Error>

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

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

Source§

fn from(value: ActorCell) -> ActorRef<TMessage>

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl Hash for ActorCell

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ActorCell

Source§

fn eq(&self, other: &ActorCell) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for ActorCell

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

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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> JobKey for T
where T: Debug + Hash + Send + Sync + Clone + Eq + PartialEq + 'static,

Source§

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

Source§

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