acton_core::prelude

Struct ManagedAgent

Source
pub struct ManagedAgent<AgentState, ManagedAgent: Default + Send + Debug + 'static> {
    pub model: ManagedAgent,
    /* private fields */
}
Expand description

A managed agent is a wrapper around an actor that provides a set of lifecycle hooks and message handling reactors.

Fields§

§model: ManagedAgent

The actor model.

Implementations§

Source§

impl<State: Default + Send + Debug + 'static> ManagedAgent<Idle, State>

Source

pub fn act_on<M>( &mut self, message_processor: impl for<'a> Fn(&'a mut ManagedAgent<Started, State>, &'a mut MessageContext<M>) -> Pin<Box<dyn Future<Output = ()> + Sync + Send + 'static>> + Send + Sync + 'static, ) -> &mut Self
where M: ActonMessage + Clone + Send + Sync + 'static,

Adds an asynchronous message handler for a specific message type.

§Parameters
  • message_processor: The function to handle the message.
Source

pub fn after_start<F, Fut>(&mut self, f: F) -> &mut Self
where F: for<'b> Fn(&'b ManagedAgent<Started, State>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + Sync + 'static,

Sets the reactor to be called when the actor wakes up.

§Parameters
  • life_cycle_event_reactor: The function to be called.
Source

pub fn before_start<F, Fut>(&mut self, f: F) -> &mut Self
where F: for<'b> Fn(&'b ManagedAgent<Started, State>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + Sync + 'static,

Sets the reactor to be called when the actor wakes up.

§Parameters
  • life_cycle_event_reactor: The function to be called.
Source

pub fn after_stop<F, Fut>(&mut self, f: F) -> &mut Self
where F: for<'b> Fn(&'b ManagedAgent<Started, State>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + Sync + 'static,

Sets the reactor to be called when the actor stops processing messages in its mailbox.

§Parameters
  • life_cycle_event_reactor: The function to be called.
Source

pub fn before_stop<F, Fut>(&mut self, f: F) -> &mut Self
where F: for<'b> Fn(&'b ManagedAgent<Started, State>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + Sync + 'static,

Sets the reactor to be called just before the actor stops processing messages in its mailbox.

§Parameters
  • life_cycle_event_reactor: The function to be called.
Source

pub async fn create_child( &self, name: String, ) -> Result<ManagedAgent<Idle, State>>

Creates and supervises a new actor with the given ID and state.

§Parameters
  • id: The identifier for the new actor.
§Returns

A new Actor instance in the idle state.

Source

pub async fn start(self) -> AgentHandle

Starts the actor and transitions it to the running state.

Source§

impl<Agent: Default + Send + Debug + 'static> ManagedAgent<Started, Agent>

Source

pub fn new_envelope(&self) -> Option<OutboundEnvelope>

Creates a new outbound envelope for the actor.

§Returns

An optional OutboundEnvelope if the context’s outbox is available.

Source

pub fn new_parent_envelope(&self) -> Option<OutboundEnvelope>

Creates a new parent envelope for the actor.

§Returns

A clone of the parent’s return envelope.

Source§

impl<ActorState, ManagedEntity: Default + Send + Debug + 'static> ManagedAgent<ActorState, ManagedEntity>

Source

pub fn id(&self) -> &Ern

Returns the unique identifier of the actor.

Source

pub fn name(&self) -> &str

Returns the name of the actor.

Source

pub fn handle(&self) -> &AgentHandle

Returns the handle of the actor.

Source

pub fn parent(&self) -> &Option<AgentHandle>

Returns the parent of the actor.

Source

pub fn broker(&self) -> &AgentHandle

Returns the broker of the actor.

Source

pub fn runtime(&self) -> &AgentRuntime

Returns the app runtime.

Trait Implementations§

Source§

impl<ActorState, ManagedEntity: Default + Send + Debug + 'static> Debug for ManagedAgent<ActorState, ManagedEntity>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<State: Default + Send + Debug + 'static> Default for ManagedAgent<Idle, State>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<State: Default + Send + Debug + 'static> From<ManagedAgent<Idle, State>> for ManagedAgent<Started, State>

Source§

fn from(value: ManagedAgent<Idle, State>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<AgentState, ManagedAgent> !Freeze for ManagedAgent<AgentState, ManagedAgent>

§

impl<AgentState, ManagedAgent> !RefUnwindSafe for ManagedAgent<AgentState, ManagedAgent>

§

impl<AgentState, ManagedAgent> Send for ManagedAgent<AgentState, ManagedAgent>
where AgentState: Send,

§

impl<AgentState, ManagedAgent> Sync for ManagedAgent<AgentState, ManagedAgent>
where ManagedAgent: Sync, AgentState: Sync,

§

impl<AgentState, ManagedAgent> Unpin for ManagedAgent<AgentState, ManagedAgent>
where ManagedAgent: Unpin, AgentState: Unpin,

§

impl<AgentState, ManagedAgent> !UnwindSafe for ManagedAgent<AgentState, ManagedAgent>

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> Same for T

Source§

type Output = T

Should always be Self
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