Actor

Trait Actor 

Source
pub trait Actor:
    Any
    + Send
    + Sync {
    // Required method
    fn receive(&mut self, mail: Mail) -> Option<Mail>;

    // Provided methods
    fn type_name(&self) -> &'static str { ... }
    fn post_start(&mut self, _mail: Mail) -> Option<Mail> { ... }
    fn pre_shutdown(&mut self, _mail: Mail) -> Option<Mail> { ... }
}
Expand description

§Actor

Actor - the trait for an actor implementation in the system. The only required method to implement is receive - which keeps receiving messagesMail(crate::common::msg::Ma //!il and optionally supposed to return an outgoing message(s) which may be addressed to any local or remote actor(s). Outgoing Mail can contain multiple messages directed to different actors. Messages directed to an actor will always be delivered in the order that they were ingested into the actor system. Out of sequence messages will not be delivered until all previous messages have been consumed by the actor. Message might get delivered more than once because of actor failing to process message.

Upon restart - actor would start receiving messages - where it left off from.

Required Methods§

Source

fn receive(&mut self, mail: Mail) -> Option<Mail>

The required method that needs to be implemented as part of Actor implementation. Called to handle incoming messages. The incoming message should not be returned as it is - doing so would lead to re-delivery of the message back again. The ‘to’ Addr of the recipient should be set emptied out in the outgoing payload.

Incoming payload will be of type Trade(Msg).

Provided Methods§

Source

fn type_name(&self) -> &'static str

Name of the type implementing the Actor trait

Source

fn post_start(&mut self, _mail: Mail) -> Option<Mail>

The startup signal that the actor receives upon definition - when actor is defined via define_actor! macro or on restoration from the backing store.

Source

fn pre_shutdown(&mut self, _mail: Mail) -> Option<Mail>

Pre-shutdown signal that the actor will receive at normal shutdown or actor eviction due to actor panicking while processing message. An actor is allowed to panic a set number of times(currently 3) before eviction. Actor might panic due to internal(faulty logic, index bounds exception) or external reasons like message getting corrupted in transit.

Trait Implementations§

Source§

impl Debug for dyn Actor

Source§

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

Formats the value using the given formatter. Read more

Implementors§