[−][src]Trait kompact::prelude::NetworkActor
A trait for actors that handle the same set of messages locally and remotely
Implementing this trait is roughly equivalent to the default assumptions in most actor system implementations with a distributed runtime (Erlang, Akka, Orelans, etc.).
Example
This implementation uses the trivial default Deserialiser
for the unit type ()
from the serialisation::default_serialisiers
module
(which is imported by default with the prelude).
use kompact::prelude::*; #[derive(ComponentDefinition)] struct NetActor { ctx: ComponentContext<Self> } ignore_lifecycle!(NetActor); impl NetworkActor for NetActor { type Message = (); type Deserialiser = (); fn receive(&mut self, sender: Option<ActorPath>, msg: Self::Message) -> Handled { info!(self.log(), "Got a local or deserialised remote message: {:?}", msg); Handled::Ok } }
Associated Types
type Message: MessageBounds
The type of messages the actor accepts
type Deserialiser: Deserialiser<Self::Message>
The deserialiser used to unpack network messages
into Self::Message
.
Required methods
fn receive(&mut self, sender: Option<ActorPath>, msg: Self::Message) -> Handled
Handles all messages after deserialisation
The sender
argument will only be supplied if the original message
was a NetMessage, otherwise it's None
.
All messages 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.
Provided methods
fn on_error(&mut self, error: UnpackError<NetMessage>) -> Handled
Handle errors during unpacking of network messages
The default implementation logs every error as a warning.