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>
impl<TMessage> ActorRef<TMessage>
Sourcepub fn notify_supervisor_and_monitors(&self, evt: SupervisionEvent)
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,
impl<TMessage> ActorRef<TMessage>where
TMessage: Message,
Sourcepub fn send_message(
&self,
message: TMessage,
) -> Result<(), MessagingErr<TMessage>>
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§impl<TMessage: Message> ActorRef<TMessage>
impl<TMessage: Message> ActorRef<TMessage>
Sourcepub fn get_derived<TFrom>(&self) -> DerivedActorRef<TFrom>
pub fn get_derived<TFrom>(&self) -> DerivedActorRef<TFrom>
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>>>
impl<TKey, TMsg> ActorRef<FactoryMessage<TKey, RetriableMessage<TKey, TMsg>>>
Sourcepub fn submit_retriable_job(
&self,
job: Job<TKey, TMsg>,
strategy: MessageRetryStrategy,
) -> Result<(), MessagingErr<FactoryMessage<TKey, RetriableMessage<TKey, TMsg>>>>
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 theacceptedfield, if set, will be dropped as RetriableMessages do not supportacceptedreplies, except on the first iterationstrategy: 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,
impl<TMessage> ActorRef<TMessage>where
TMessage: Message,
Sourcepub async fn call<TReply, TMsgBuilder>(
&self,
msg_builder: TMsgBuilder,
timeout_option: Option<Duration>,
) -> Result<CallResult<TReply>, MessagingErr<TMessage>>where
TMsgBuilder: FnOnce(RpcReplyPort<TReply>) -> TMessage,
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
Sourcepub 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>>
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>>
Alias of call_and_forward
Source§impl<TMessage> ActorRef<TMessage>where
TMessage: Message,
Add the timing functionality on top of the crate::ActorRef
impl<TMessage> ActorRef<TMessage>where
TMessage: Message,
Add the timing functionality on top of the crate::ActorRef
Sourcepub fn send_interval<F>(&self, period: Duration, msg: F) -> JoinHandle<()>
pub fn send_interval<F>(&self, period: Duration, msg: F) -> JoinHandle<()>
Alias of send_interval
Sourcepub fn send_after<F>(
&self,
period: Duration,
msg: F,
) -> JoinHandle<Result<(), MessagingErr<TMessage>>>
pub fn send_after<F>( &self, period: Duration, msg: F, ) -> JoinHandle<Result<(), MessagingErr<TMessage>>>
Alias of send_after
Sourcepub fn exit_after(&self, period: Duration) -> JoinHandle<()>
pub fn exit_after(&self, period: Duration) -> JoinHandle<()>
Alias of exit_after
Sourcepub fn kill_after(&self, period: Duration) -> JoinHandle<()>
pub fn kill_after(&self, period: Duration) -> JoinHandle<()>
Alias of kill_after
Methods from Deref<Target = 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<ActorName>
pub fn get_name(&self) -> Option<ActorName>
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: Message>(&self) -> Option<bool>
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.