ActorSystem

Struct ActorSystem 

Source
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

Source

pub fn new(name: String) -> ActorSystem

Creates a new ActorSystem.

Note that one thread is started.

Source

pub fn actor_of(&self, props: Arc<dyn ActorFactory>, name: String) -> ActorRef

Spawns an Actor created using the Props given for the user.

Source

pub fn system_actor_of( &self, props: Arc<dyn ActorFactory>, name: String, ) -> ActorRef

Spawns an Actor created using the Props given for the system.

Source

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.

Source

pub fn enqueue_actor(&self, actor_ref: ActorRef)

Enqueues the given ActorRef in the queue of ActorRef with message to handle.

Source

pub fn spawn_thread(&self)

Spawns a thread that will have ActorRef handle their messages.

This thread can be terminated by calling terminate_thread.

Source

pub fn terminate_thread(&self)

Kills a consumer thread.

Source

pub fn spawn_threads(&self, n: u32)

Spawns n consumer threads.

Source

pub fn terminate_threads(&self, n: u32)

Kills n consumer threads.

Source

pub fn name_resolver(&self) -> ActorRef

Gives the ActorRef of the name resolver actor.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ActorSystem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Arguments for T
where T: Clone + Send + Sync + 'static,

Source§

impl<T> Message for T
where T: Clone + Send + Sync + 'static + Any,