pub struct ActorSystem { /* private fields */ }Expand description
The actor system is the struct that manages:
- The creation of the root actors.
- The consumer threads.
- Scheduling the actors.
It needs to be instantiated once at the beggining of the application. Then we need to specify the number of consumer threads that will be allocated.
Calling shutdown, will drop all the actors and terminate the consumer threads.
Note that it will shut down the system even if some actors have still messages to handle.
Implementations§
Source§impl ActorSystem
impl ActorSystem
Sourcepub fn new(name: String) -> ActorSystem
pub fn new(name: String) -> ActorSystem
Creates a new ActorSystem.
Note that one thread is started.
Sourcepub fn actor_of(&self, props: Arc<dyn ActorFactory>, name: String) -> ActorRef
pub fn actor_of(&self, props: Arc<dyn ActorFactory>, name: String) -> ActorRef
Spawns an Actor created using the Props given for the user.
Sourcepub fn system_actor_of(
&self,
props: Arc<dyn ActorFactory>,
name: String,
) -> ActorRef
pub fn system_actor_of( &self, props: Arc<dyn ActorFactory>, name: String, ) -> ActorRef
Spawns an Actor created using the Props given for the system.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Shuts the actor system down.
It will terminate all the actors (whether they still have messages to handle or not) and then terminate the consumer threads.
Sourcepub fn enqueue_actor(&self, actor_ref: ActorRef)
pub fn enqueue_actor(&self, actor_ref: ActorRef)
Enqueues the given ActorRef in the queue of ActorRef with message to handle.
Sourcepub fn spawn_thread(&self)
pub fn spawn_thread(&self)
Spawns a thread that will have ActorRef handle their messages.
This thread can be terminated by calling terminate_thread.
Sourcepub fn terminate_thread(&self)
pub fn terminate_thread(&self)
Kills a consumer thread.
Sourcepub fn spawn_threads(&self, n: u32)
pub fn spawn_threads(&self, n: u32)
Spawns n consumer threads.
Sourcepub fn terminate_threads(&self, n: u32)
pub fn terminate_threads(&self, n: u32)
Kills n consumer threads.
Sourcepub fn name_resolver(&self) -> ActorRef
pub fn name_resolver(&self) -> ActorRef
Gives the ActorRef of the name resolver actor.
Sourcepub fn tell<M: Message>(&self, to: ActorRef, message: M)
pub fn tell<M: Message>(&self, to: ActorRef, message: M)
Sends a message to the given actor.
The sender of the message is the user_actor, thus this expects that no answer will be given.
Sourcepub fn ask<M: Message>(
&self,
to: ActorRef,
message: M,
name: String,
) -> ActorRef
pub fn ask<M: Message>( &self, to: ActorRef, message: M, name: String, ) -> ActorRef
Creates a Future that will send the message to the targetted actor.
The father of this Future is the user_actor.
Sourcepub fn extract_result<M: Message>(&self, future: ActorRef) -> M
pub fn extract_result<M: Message>(&self, future: ActorRef) -> M
Extracts the result from a Future.
This is not supposed to be used a lot as this is a synchronous call (if an actor wants to get the result of a fututure it should use forward_result instead).
The extraction creates an Extractor actor whose father is the user_actor.
Trait Implementations§
Source§impl Clone for ActorSystem
impl Clone for ActorSystem
Source§fn clone(&self) -> ActorSystem
fn clone(&self) -> ActorSystem
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more