Skip to main content

ActorContext

Struct ActorContext 

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

Source

pub fn new(path: ActorPath, addr_hash: AddrHash) -> Self

Create a context without a runtime bridge (Phase 1 / test use).

Source

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.

Source

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.

Source

pub fn path(&self) -> &ActorPath

Source

pub fn addr_hash(&self) -> AddrHash

Source

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).

Source

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.

Source

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).

Source

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).

Source

pub fn now(&self) -> Instant

Return the current monotonic time.

Phase 3 routes this through the Reactor trait for deterministic simulation.

Source

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.

Source

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).

Source

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>

Source§

fn clone(&self) -> ActorContext<R>

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<R: Reactor> Debug for ActorContext<R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for ActorContext<R>

§

impl<R> !RefUnwindSafe for ActorContext<R>

§

impl<R> Send for ActorContext<R>

§

impl<R> Sync for ActorContext<R>

§

impl<R> Unpin for ActorContext<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for ActorContext<R>

§

impl<R> !UnwindSafe for ActorContext<R>

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.