[−][src]Trait kompact::prelude::Actor
A slightly higher level Actor API that handles both local and networked messages
This trait should generally be preferred over ActorRaw, as it abstracts away the message envelope enum used internally.
Actor can also be derived via #[derive(Actor)]
for components which don't require
this messaging mechanism.
Example
use kompact::prelude::*; #[derive(ComponentDefinition)] struct NormalActor { ctx: ComponentContext<Self> } ignore_control!(NormalActor); impl Actor for NormalActor { type Message = (); fn receive_local(&mut self, msg: Self::Message) -> () { info!(self.log(), "Got a local message: {:?}", msg); } fn receive_network(&mut self, msg: NetMessage) -> () { info!(self.log(), "Got a network message: {:?}", msg) } }
Associated Types
type Message: MessageBounds
The type of local messages the actor accepts
Required methods
fn receive_local(&mut self, msg: Self::Message)
Handle an incoming local message
Local message are of type Self::Message
.
Note
Remember that components usually run on a shared thread pool, so, just like for handle implementations, you shouldn't ever block in this method unless you know what you are doing.
fn receive_network(&mut self, msg: NetMessage)
Handle an incoming network message
Network messages are of type NetMessage and can be either be serialised data, or a heap-allocated "reflected" message. Messages are "reflected" instead of serialised whenever possible for messages sent to an ActorPath that turned out to be in the same KompactSystem.
Note
Remember that components usually run on a shared thread pool, so, just like for handle implementations, you shouldn't ever block in this method unless you know what you are doing.
Implementors
impl Actor for DeadletterBox
[src]
type Message = Never
fn receive_local(&mut self, _msg: Self::Message)
[src]
Handles local messages.
fn receive_network(&mut self, msg: NetMessage)
[src]
Handles (serialised or reflected) messages from the network.
impl Actor for LocalDispatcher
[src]
type Message = DispatchEnvelope
fn receive_local(&mut self, msg: Self::Message)
[src]
fn receive_network(&mut self, msg: NetMessage)
[src]
impl Actor for NetworkDispatcher
[src]
type Message = DispatchEnvelope
fn receive_local(&mut self, msg: Self::Message)
[src]
fn receive_network(&mut self, msg: NetMessage)
[src]
impl<A, M, D> Actor for A where
M: MessageBounds,
D: Deserialiser<M>,
A: NetworkActor<Message = M, Deserialiser = D>,
[src]
M: MessageBounds,
D: Deserialiser<M>,
A: NetworkActor<Message = M, Deserialiser = D>,