Struct ActorSystem

Source
pub struct ActorSystem { /* private fields */ }
Expand description

An actor system that contains and manages the actors spawned inside it.

Implementations§

Source§

impl ActorSystem

Source

pub fn create(config: ActorSystemConfig) -> ActorSystem

Creates an actor system with the given config. The user should benchmark how many slots are needed in the work channel, the number of threads they need in the system and and so on in order to satisfy the requirements of the software they are creating.

Source

pub fn start(&self)

Starts an unstarted ActorSystem. The function will do nothing if the ActorSystem has already been started.

Source

pub fn config(&self) -> &ActorSystemConfig

Returns a reference to the config for this actor system.

Source

pub fn connect( &self, sender: &SeccSender<WireMessage>, receiver: &SeccReceiver<WireMessage>, ) -> Uuid

Adds a connection to a remote actor system. When the connection is established the actor system will announce itself to the remote system with a WireMessage::Hello.

Source

pub fn disconnect(&self, system_uuid: Uuid) -> Result<(), AidError>

Disconnects this actor system from the remote actor system with the given UUID.

Source

pub fn connect_with_channels(system1: &ActorSystem, system2: &ActorSystem)

Connects two actor systems using two channels directly. This can be used as a utility in testing or to link two actor systems directly within the same process.

Source

pub fn init_current(&self)

Initializes this actor system to use for the current thread which is necessary if the user wishes to serialize and deserialize Aids.

§Contract

You must run this exactly once per thread where needed.

Source

pub fn current() -> ActorSystem

Fetches a clone of a reference to the actor system for the current thread.

Source

pub fn uuid(&self) -> Uuid

Returns the unique UUID for this actor system.

Source

pub fn trigger_shutdown(&self)

Triggers a shutdown but doesn’t wait for the Reactors to stop.

Source

pub fn await_shutdown( &self, timeout: impl Into<Option<Duration>>, ) -> ShutdownResult

Awaits the Executor shutting down all Reactors. This is backed by a barrier that Reactors will wait on after ActorSystem::trigger_shutdown is called, blocking until all Reactors have stopped.

Source

pub fn trigger_and_await_shutdown( &self, timeout: impl Into<Option<Duration>>, ) -> ShutdownResult

Triggers a shutdown of the system and returns only when all Reactors have shutdown.

Source

pub fn spawn(&self) -> ActorBuilder

Creates a single use builder for this actor system that allows a user to build actors using a chained syntax while optionally providing configuration parameters if desired.

§Examples
use axiom::prelude::*;

let system = ActorSystem::create(ActorSystemConfig::default().thread_pool_size(2));

async fn handler(mut count: usize, _: Context, _: Message) -> ActorResult<usize> {
    count += 1;
    Ok(Status::done(count))
}

let state = 0 as usize;

let aid1 = system.spawn().with(state, handler).unwrap();
let aid2 = system.spawn().name("Foo").with(state, handler).unwrap();
let aid3 = system.spawn().channel_size(10).with(state, handler).unwrap();
Source

pub fn stop_actor(&self, aid: &Aid)

Stops an actor by shutting down its channels and removing it from the actors list and telling the Aid to not allow messages to be sent to the actor since the receiving side of the actor is gone.

This is something that should rarely be called from the outside as it is much better to send the actor a SystemMsg::Stop message and allow it to stop gracefully.

Source

pub fn is_actor_alive(&self, aid: &Aid) -> bool

Checks to see if the actor with the given Aid is alive within this actor system.

Source

pub fn find_aid_by_uuid(&self, uuid: &Uuid) -> Option<Aid>

Look up an Aid by the unique UUID of the actor and either returns the located Aid in a Option::Some or Option::None if not found.

Source

pub fn find_aid_by_name(&self, name: &str) -> Option<Aid>

Look up an Aid by the user assigned name of the actor and either returns the located Aid in a Option::Some or Option::None if not found.

Source

pub fn system_actor_aid(&self) -> Aid

Returns the Aid to the “System” actor for this actor system.

Source

pub fn monitor(&self, monitoring: &Aid, monitored: &Aid)

Adds a monitor so that monitoring will be informed if monitored stops.

Source

pub fn send_to_system_actors(&self, message: Message)

Asynchronously send a message to the system actors on all connected actor systems.

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
Source§

impl Debug for ActorSystem

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> Erased for T