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
impl ActorCell
Sourcepub fn get_id(&self) -> ActorId
pub fn get_id(&self) -> ActorId
Retrieve the super::Actor’s unique identifier ActorId
Sourcepub fn get_name(&self) -> Option<String>
pub fn get_name(&self) -> Option<String>
Retrieve the super::Actor’s name
Sourcepub fn get_status(&self) -> ActorStatus
pub fn get_status(&self) -> ActorStatus
Retrieve the current status of an super::Actor
Returns the super::Actor’s current ActorStatus
Sourcepub fn link(&self, supervisor: ActorCell)
pub fn link(&self, supervisor: ActorCell)
Link this super::Actor to the provided supervisor
supervisor- The supervisor super::Actor of this actor
Sourcepub fn unlink(&self, supervisor: ActorCell)
pub fn unlink(&self, supervisor: ActorCell)
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
Sourcepub fn kill(&self)
pub fn kill(&self)
Kill this super::Actor forcefully (terminates async work)
Sourcepub async fn kill_and_wait(
&self,
timeout: Option<Duration>,
) -> Result<(), RactorErr<()>>
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)
Sourcepub fn stop(&self, reason: Option<String>)
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
Sourcepub async fn stop_and_wait(
&self,
reason: Option<String>,
timeout: Option<Duration>,
) -> Result<(), RactorErr<StopMessage>>
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 occurringtimeout- 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)
Sourcepub async fn wait(&self, timeout: Option<Duration>) -> Result<(), Timeout>
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.
Sourcepub fn send_message<TMessage>(
&self,
message: TMessage,
) -> Result<(), MessagingErr<TMessage>>where
TMessage: Message,
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
Sourcepub fn drain(&self) -> Result<(), MessagingErr<()>>
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
Sourcepub async fn drain_and_wait(
&self,
timeout: Option<Duration>,
) -> Result<(), RactorErr<()>>
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
Sourcepub fn notify_supervisor(&self, evt: SupervisionEvent)
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
Sourcepub fn stop_children(&self, reason: Option<String>)
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.
Sourcepub fn try_get_supervisor(&self) -> Option<ActorCell>
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.
Sourcepub async fn stop_children_and_wait(
&self,
reason: Option<String>,
timeout: Option<Duration>,
)
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 childrentimeout: 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.
Sourcepub fn drain_children(&self)
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.
Sourcepub async fn drain_children_and_wait(&self, timeout: Option<Duration>)
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
Sourcepub fn get_children(&self) -> Vec<ActorCell>
pub fn get_children(&self) -> Vec<ActorCell>
Sourcepub fn get_type_id(&self) -> TypeId
pub fn get_type_id(&self) -> TypeId
Sourcepub fn is_message_type_of<TMessage>(&self) -> Option<bool>where
TMessage: Message,
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.
Sourcepub 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,
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 printinghandlerThe implementation of Selfstartup_args: Arguments passed to thepre_startcall 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
impl ActorCell
Sourcepub 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>where
T: ThreadLocalActor,
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>where
T: ThreadLocalActor,
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 printinghandlerThe implementation of Selfstartup_args: Arguments passed to thepre_startcall 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§
impl Eq for ActorCell
Auto Trait Implementations§
impl Freeze for ActorCell
impl RefUnwindSafe for ActorCell
impl Send for ActorCell
impl Sync for ActorCell
impl Unpin for ActorCell
impl UnsafeUnpin for ActorCell
impl UnwindSafe for ActorCell
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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