pub struct ActorContext<R: Reactor> { /* private fields */ }Expand description
Runtime handle provided to each lifecycle hook.
bridge is None in test/stub contexts (Phase 1). pd-runtime injects
a real bridge via ActorContext::with_bridge when spawning actors so that
spawn, stop, send_raw, and send_after are fully functional.
Implementations§
Source§impl<R: Reactor> ActorContext<R>
impl<R: Reactor> ActorContext<R>
Sourcepub fn new(path: ActorPath, addr_hash: AddrHash) -> Self
pub fn new(path: ActorPath, addr_hash: AddrHash) -> Self
Create a context without a runtime bridge (Phase 1 / test use).
Sourcepub fn with_bridge(
path: ActorPath,
addr_hash: AddrHash,
bridge: Arc<dyn RuntimeBridge<R>>,
) -> Self
pub fn with_bridge( path: ActorPath, addr_hash: AddrHash, bridge: Arc<dyn RuntimeBridge<R>>, ) -> Self
Create a context with a runtime bridge. Called by pd-runtime at
spawn time.
Sourcepub fn with_namespace_policy(self, policy: NamespacePolicy) -> Self
pub fn with_namespace_policy(self, policy: NamespacePolicy) -> Self
Builder-style method to attach a namespace policy.
Called by the supervisor when spawning actors from a ChildSpec.
pub fn path(&self) -> &ActorPath
pub fn addr_hash(&self) -> AddrHash
Sourcepub fn spawn(&mut self, spec: ChildSpec<R>) -> AddrHash
pub fn spawn(&mut self, spec: ChildSpec<R>) -> AddrHash
Spawn a child actor under this actor’s supervision tree.
Returns the child’s AddrHash (derived immediately from path);
the runtime processes the actual spawn asynchronously.
§Panics
Panics when called without a runtime bridge (Phase 1 / stub contexts).
Sourcepub fn send_raw(
&mut self,
envelope: Envelope,
payload: MessagePayload,
) -> Result<(), SendError>
pub fn send_raw( &mut self, envelope: Envelope, payload: MessagePayload, ) -> Result<(), SendError>
Send a pre-built envelope through the local transport layer.
If a namespace policy is set, the destination is resolved to an
ActorPath and checked against the policy. Unknown destinations
(hash not found in the registry) are allowed through — the runtime
will deliver or drop as appropriate.
Fast path: On the second and subsequent sends to the same local
actor, the cached CachedSendFn is used directly — bypassing the
global TransportRegistry DashMap lookup. The cache is populated on
the first successful delivery and evicted on ActorStopped.
Response envelopes (FLAG_RESPONSE set) always bypass the cache and go
through RuntimeBridge::route so the ResponseRegistry can complete
pending ask() futures.
Returns Err(SendError::PolicyViolation) if the destination path
is not permitted by the current namespace policy.
Returns Err(SendError::ActorStopped) if called without a bridge.
Sourcepub fn stop(&mut self)
pub fn stop(&mut self)
Request that this actor stop after the current message handler returns.
§Panics
Panics when called without a runtime bridge (Phase 1 / stub contexts).
Sourcepub fn reactor(&self) -> &R
pub fn reactor(&self) -> &R
Access the reactor for spawning, time, and async primitives.
§Panics
Panics when called without a runtime bridge (Phase 1 / stub contexts).
Sourcepub fn now(&self) -> Instant
pub fn now(&self) -> Instant
Return the current monotonic time.
Phase 3 routes this through the Reactor trait for deterministic
simulation.
Sourcepub fn send_after(
&self,
delay: Duration,
envelope: Envelope,
payload: MessagePayload,
)
pub fn send_after( &self, delay: Duration, envelope: Envelope, payload: MessagePayload, )
Schedule a message to be delivered after delay.
§Panics
Panics when called without a runtime bridge.
Sourcepub fn lookup_path(&self, path: &ActorPath) -> Option<AddrHash>
pub fn lookup_path(&self, path: &ActorPath) -> Option<AddrHash>
Resolve an actor’s current address by its path.
Returns None if the actor is not currently running or if no bridge
is available (test/stub contexts).
Sourcepub fn cached_sender_for(&mut self, addr: AddrHash) -> Option<CachedSendFn>
pub fn cached_sender_for(&mut self, addr: AddrHash) -> Option<CachedSendFn>
Return a cached direct sender for addr, populating the cache on first call.
Checks addr_cache first; on a miss, delegates to the bridge’s
cached_sender() and inserts the result. Returns None when the
destination is not local (remote / federated / no bridge).
Used by FfiBridge::cached_sender to wire the fresh FFI context’s
addr_cache through to the real RuntimeBridgeImpl.
Trait Implementations§
Source§impl<R: Clone + Reactor> Clone for ActorContext<R>
impl<R: Clone + Reactor> Clone for ActorContext<R>
Source§fn clone(&self) -> ActorContext<R>
fn clone(&self) -> ActorContext<R>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more