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: ManagedAgentThe actor model.
Implementations§
Source§impl<State: Default + Send + Debug + 'static> ManagedAgent<Idle, State>
impl<State: Default + Send + Debug + 'static> ManagedAgent<Idle, State>
Sourcepub 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
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
Adds an asynchronous message handler for a specific message type.
§Parameters
message_processor: The function to handle the message.
Sourcepub fn after_start<F, Fut>(&mut self, f: F) -> &mut Self
pub fn after_start<F, Fut>(&mut self, f: F) -> &mut Self
Sets the reactor to be called when the actor wakes up.
§Parameters
life_cycle_event_reactor: The function to be called.
Sourcepub fn before_start<F, Fut>(&mut self, f: F) -> &mut Self
pub fn before_start<F, Fut>(&mut self, f: F) -> &mut Self
Sets the reactor to be called when the actor wakes up.
§Parameters
life_cycle_event_reactor: The function to be called.
Sourcepub fn after_stop<F, Fut>(&mut self, f: F) -> &mut Self
pub fn after_stop<F, Fut>(&mut self, f: F) -> &mut Self
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.
Sourcepub fn before_stop<F, Fut>(&mut self, f: F) -> &mut Self
pub fn before_stop<F, Fut>(&mut self, f: F) -> &mut Self
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.
Sourcepub async fn create_child(
&self,
name: String,
) -> Result<ManagedAgent<Idle, State>>
pub async fn create_child( &self, name: String, ) -> Result<ManagedAgent<Idle, State>>
Sourcepub async fn start(self) -> AgentHandle
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>
impl<Agent: Default + Send + Debug + 'static> ManagedAgent<Started, Agent>
Sourcepub fn new_envelope(&self) -> Option<OutboundEnvelope>
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.
Sourcepub fn new_parent_envelope(&self) -> Option<OutboundEnvelope>
pub fn new_parent_envelope(&self) -> Option<OutboundEnvelope>
Source§impl<ActorState, ManagedEntity: Default + Send + Debug + 'static> ManagedAgent<ActorState, ManagedEntity>
impl<ActorState, ManagedEntity: Default + Send + Debug + 'static> ManagedAgent<ActorState, ManagedEntity>
Sourcepub fn handle(&self) -> &AgentHandle
pub fn handle(&self) -> &AgentHandle
Returns the handle of the actor.
Sourcepub fn parent(&self) -> &Option<AgentHandle>
pub fn parent(&self) -> &Option<AgentHandle>
Returns the parent of the actor.
Sourcepub fn broker(&self) -> &AgentHandle
pub fn broker(&self) -> &AgentHandle
Returns the broker of the actor.
Sourcepub fn runtime(&self) -> &AgentRuntime
pub fn runtime(&self) -> &AgentRuntime
Returns the app runtime.