Skip to main content

ActorSystem

Struct ActorSystem 

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

A named actor registry with coordinated shutdown.

ActorSystem is a phone book, not a runtime. It does not create or own a Tokio runtime. Actors spawn on whatever runtime is current via Handle::try_current().

Implementations§

Source§

impl ActorSystem

Source

pub fn default() -> Arc<ActorSystem>

Returns the default system (named "default"), creating it lazily.

This is intentionally not std::default::Default because it returns Arc<ActorSystem> (shared ownership), not an owned value.

Source

pub fn create(name: impl Into<String>) -> Result<Arc<ActorSystem>, SpawnError>

Creates a new named system and registers it in the global systems map.

Returns SpawnError::SystemNameTaken if a system with this name already exists.

Source

pub fn create_with( name: impl Into<String>, config: SystemConfig, ) -> Result<Arc<ActorSystem>, SpawnError>

Creates a new named system with custom configuration.

Returns SpawnError::SystemNameTaken if a system with this name already exists.

Source

pub fn get_named(name: &str) -> Option<Arc<ActorSystem>>

Looks up a named system. Returns None if no system with this name exists.

Source

pub fn all() -> Vec<String>

Lists the names of all registered systems.

Source

pub fn name(&self) -> &str

Returns this system’s name.

Source

pub fn get<A: Actor>(&self, name: &str) -> Option<ActorHandle<A>>

Looks up a named actor, returning a typed handle.

Returns None if the name is not registered or if the registered actor is a different type (type mismatch is silent, matching OTP’s whereis/1 -> undefined semantics).

Source

pub async fn stop(&self, name: &str) -> Result<(), SendError>

Stops a named actor gracefully.

Returns SendError::Closed if no actor with the given name is registered.

Source

pub async fn kill(&self, name: &str) -> Result<(), SendError>

Force-kills a named actor, bypassing all lifecycle callbacks.

Returns SendError::Closed if no actor with the given name is registered.

Source

pub fn registered(&self) -> Vec<String>

Lists all registered actor names in this system.

Source

pub async fn shutdown(&self)

Shuts down all registered actors using the system’s stored policy.

Source

pub async fn shutdown_with(&self, policy: ShutdownPolicy)

Shuts down all registered actors with a custom policy.

All entries are drained from the registry first (releasing locks), then stop signals are sent. This avoids deadlock with RegistryGuard drop handlers that also mutate the registry.

Each actor is given up to per_actor_timeout to stop gracefully. If it does not stop in time, it receives StopReason::Kill. If the global timeout deadline is exceeded, all remaining actors are immediately killed.

Trait Implementations§

Source§

impl Debug for ActorSystem

Source§

fn fmt(&self, f: &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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more