Skip to main content

ActorContext

Trait ActorContext 

Source
pub trait ActorContext<A>:
    Sized
    + Send
    + 'static
where A: Actor<Context = Self>,
{
Show 19 methods // Required methods fn new(label: String) -> Self; fn index(&self) -> usize; fn label(&self) -> &str; fn address(&self) -> Address<A>; fn take_mailbox(&mut self) -> Option<Mailbox<A>>; fn state(&self) -> ActorState; fn set_state(&mut self, state: ActorState); fn supervisor(&self) -> Option<&Recipient<SupervisionEvent<A>>>; fn set_supervisor( &mut self, supervisor: Option<Recipient<SupervisionEvent<A>>>, ); fn processing( &mut self, actor: &mut A, mailbox: Mailbox<A>, ) -> impl Future<Output = Result<(), A::Error>> + Send; // Provided methods fn set_error(&mut self, error: A::Error) { ... } fn drain_mailbox(&mut self) { ... } fn stop(&mut self) { ... } fn stop_with_error(&mut self, error: A::Error) { ... } fn terminate(&mut self) { ... } fn terminate_with_error(&mut self, error: A::Error) { ... } fn notify_supervisor( &mut self, event: SupervisionEvent<A>, ) -> impl Future<Output = ()> + Send { ... } fn try_notify_supervisor(&mut self, event: SupervisionEvent<A>) { ... } fn run( self, actor: A, span: Span, ) -> Result<(Address<A>, JoinHandle<()>), A::Error> { ... }
}
Expand description

Describes the execution context of an actor.

Required Methods§

Source

fn new(label: String) -> Self

Constructs a new context.

Source

fn index(&self) -> usize

Returns the index of the actor.

Source

fn label(&self) -> &str

Returns the label of the actor.

Source

fn address(&self) -> Address<A>

Returns the address of the actor.

Source

fn take_mailbox(&mut self) -> Option<Mailbox<A>>

Returns the mailbox of the actor.

Source

fn state(&self) -> ActorState

Returns the state of the actor.

Source

fn set_state(&mut self, state: ActorState)

Sets the state of the actor.

Source

fn supervisor(&self) -> Option<&Recipient<SupervisionEvent<A>>>

Returns the address of the supervisor.

Source

fn set_supervisor(&mut self, supervisor: Option<Recipient<SupervisionEvent<A>>>)

Sets a supervisor.

Source

fn processing( &mut self, actor: &mut A, mailbox: Mailbox<A>, ) -> impl Future<Output = Result<(), A::Error>> + Send

Runs the main processing loop of the actor.

This method is called after post_start and drives the actor until it stops. It is responsible for receiving messages from the mailbox and dispatching them to the actor.

Provided Methods§

Source

fn set_error(&mut self, error: A::Error)

Sets an error during message processing.

Source

fn drain_mailbox(&mut self)

Drains the mailbox of the actor.

The default implementation does nothing. Users who needs this functionality should implement it in their own context.

Source

fn stop(&mut self)

Stops the actor.

This method will switch the actor to the Stopping state.

Source

fn stop_with_error(&mut self, error: A::Error)

Stops the actor and save the error for reporting.

This method will switch the actor to the Stopping state.

Source

fn terminate(&mut self)

Terminates the actor.

This method will switch the actor to the Stopped state.

Source

fn terminate_with_error(&mut self, error: A::Error)

Terminates the actor and save the error for reporting.

This method will switch the actor to the Stopped state.

Source

fn notify_supervisor( &mut self, event: SupervisionEvent<A>, ) -> impl Future<Output = ()> + Send

Notifies the supervisor for an event.

This method will wait until there is capacity in the mailbox of the supervisor.

Source

fn try_notify_supervisor(&mut self, event: SupervisionEvent<A>)

Notifies the supervisor for an event.

This method will return immediately if there is no capacity in the mailbox of the supervisor.

Source

fn run( self, actor: A, span: Span, ) -> Result<(Address<A>, JoinHandle<()>), A::Error>

Starts the actor and returns its address and a join handle.

This method consumes the context and the actor.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<A> ActorContext<A> for CronContext<A>
where A: Actor<Context = Self> + CronActor,

Source§

impl<A> ActorContext<A> for Context<A>
where A: Actor<Context = Self>,