Struct kay::ActorSystem [−][src]
pub struct ActorSystem { pub panic_happened: bool, pub shutting_down: bool, // some fields omitted }
The main thing inside of which all the magic happens.
An ActorSystem
contains the states of all registered actor instances,
message inboxes (queues) for each registered Actor type,
and message dispatchers for each registered (Actor
, Message
) pair.
It can be controlled from the outside to do message passing and handling in turns.
Fields
panic_happened: bool
Flag that the system is in a panicked state
shutting_down: bool
Flag that the system is shutting down
Methods
impl ActorSystem
[src]
impl ActorSystem
pub fn new(networking: Networking) -> ActorSystem
[src]
pub fn new(networking: Networking) -> ActorSystem
Create a new ActorSystem (usually only one per application is needed). Expects to get a panic callback as a parameter that is called when an actor panics during message handling and can thus be used to for example display the panic error message.
Note that after an actor panicking, the whole ActorSystem
switches
to a panicked state and only passes messages anymore which have been
marked as critically receiveable using add_handler
.
pub fn register<A: Actor>(&mut self)
[src]
pub fn register<A: Actor>(&mut self)
Register a new Actor type with the system
pub fn add_handler<A: Actor, M: Message, F: Fn(&M, &mut A, &mut World) -> Fate + 'static>(
&mut self,
handler: F,
critical: bool
)
[src]
pub fn add_handler<A: Actor, M: Message, F: Fn(&M, &mut A, &mut World) -> Fate + 'static>(
&mut self,
handler: F,
critical: bool
)
Register a handler for an Actor type and Message type.
pub fn add_spawner<A: Actor, M: Message, F: Fn(&M, &mut World) -> A + 'static>(
&mut self,
constructor: F,
critical: bool
)
[src]
pub fn add_spawner<A: Actor, M: Message, F: Fn(&M, &mut World) -> A + 'static>(
&mut self,
constructor: F,
critical: bool
)
Register a handler that constructs an instance of an Actor type, given an RawID
pub fn send<M: Message>(&mut self, recipient: RawID, message: M)
[src]
pub fn send<M: Message>(&mut self, recipient: RawID, message: M)
Send a message to the actor(s) with a given RawID
.
This is only used to send messages into the system from outside.
Inside actor message handlers you always have access to a
World
that allows you to send messages.
pub fn id<A: Actor>(&mut self) -> RawID
[src]
pub fn id<A: Actor>(&mut self) -> RawID
Get the base RawID of an Actor type
pub fn process_all_messages(&mut self)
[src]
pub fn process_all_messages(&mut self)
Processes all sent messages, and messages which are in turn sent during the handling of messages, up to a recursion depth of 1000.
This is typically called in the main loop of an application.
By sending different "top-level commands" into the system and calling
process_all_messages
inbetween, different aspects of an application
(for example, UI, simulation, rendering) can be run isolated from each other,
in a fixed order of "turns" during each main-loop iteration.
pub fn world(&mut self) -> World
[src]
pub fn world(&mut self) -> World
Get a world context directly from the system, typically to send messages from outside
pub fn networking_connect(&mut self)
[src]
pub fn networking_connect(&mut self)
Connect to all peers in the network
pub fn networking_send_and_receive(&mut self)
[src]
pub fn networking_send_and_receive(&mut self)
Send queued outbound messages and take incoming queued messages and forward them to their local target recipient(s)
pub fn networking_finish_turn(&mut self) -> Option<usize>
[src]
pub fn networking_finish_turn(&mut self) -> Option<usize>
Finish the current networking turn and wait for peers which lag behind based on their turn number. This is the main backpressure mechanism.
pub fn networking_machine_id(&self) -> MachineID
[src]
pub fn networking_machine_id(&self) -> MachineID
The machine index of this machine within the network of peers
pub fn networking_n_turns(&self) -> usize
[src]
pub fn networking_n_turns(&self) -> usize
The current network turn this machine is in. Used to keep track if this machine lags behind or runs fast compared to its peers
pub fn networking_debug_all_n_turns(&self) -> HashMap<MachineID, isize>
[src]
pub fn networking_debug_all_n_turns(&self) -> HashMap<MachineID, isize>
Return a debug message containing the current local view of network turn progress of all peers in the network
pub fn get_instance_counts(&self) -> HashMap<String, usize>
[src]
pub fn get_instance_counts(&self) -> HashMap<String, usize>
Get current instance counts for all actory types
pub fn get_message_statistics(&self) -> HashMap<String, usize>
[src]
pub fn get_message_statistics(&self) -> HashMap<String, usize>
Get number of processed messages per message type since last reset
pub fn reset_message_statistics(&mut self)
[src]
pub fn reset_message_statistics(&mut self)
Reset count of processed messages
pub fn get_queue_lengths(&self) -> HashMap<String, usize>
[src]
pub fn get_queue_lengths(&self) -> HashMap<String, usize>
Get current inbox queue lengths per actor type
Auto Trait Implementations
impl !Send for ActorSystem
impl !Send for ActorSystem
impl !Sync for ActorSystem
impl !Sync for ActorSystem