Skip to main content

Workload

Trait Workload 

Source
pub trait Workload: MaybeSendSync + 'static {
    type Dispatcher: MessageDispatcher<Workload = Self>;

Show 16 methods // Provided methods fn on_start<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_ready<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_stop<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_error<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 ErrorEvent, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_signaling_connecting<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: Option<&'life1 C>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_signaling_connected<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: Option<&'life1 C>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_signaling_disconnected<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_websocket_connecting<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_websocket_connected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_websocket_disconnected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_webrtc_connecting<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_webrtc_connected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_webrtc_disconnected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_credential_renewed<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 CredentialEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_credential_expiring<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 CredentialEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... } fn on_mailbox_backpressure<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 BackpressureEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait { ... }
}
Expand description

Workload — Executable Actor workload

Represents a complete Actor instance, composed of:

  • an associated MessageDispatcher (Workload::Dispatcher) that knows how to decode and route incoming RPC envelopes;
  • sixteen observation hooks grouped by category (see below), each with a meaningful default that emits a tracing record so unmodified workloads produce useful operational logs out of the box.

§Design

  • Bidirectional association: Workload::Dispatcher and MessageDispatcher::Workload refer to each other so that generated dispatchers can access the user-implemented workload type.
  • Meaningful defaults: every hook has a tracing-emitting default (info / debug / warn / error levels tuned per hook). Users override only the hooks whose behaviour they want to extend.
  • Auto-implementation: the code generator emits impl<T: Handler> Workload for Wrapper<T> { type Dispatcher = Router<T>; } which inherits every default implementation. Generated wrappers thus get 16 hooks “for free”.

§Hook categories

Hooks are organised into six categories. Override only the hooks you need.

§Lifecycle (4) — fallible

Lifecycle hooks return ActorResult; errors propagate and abort startup (for on_start) or are logged by the framework (for the others).

§Signaling (3) — infallible

§Transport — WebSocket (3) — infallible

§Transport — WebRTC P2P (3) — infallible

§Credential (2) — infallible

§Mailbox (1) — infallible

§Code Generation Example

// User-implemented Handler
pub struct MyEchoService { /* ... */ }

impl EchoServiceHandler for MyEchoService {
    async fn echo<C: Context>(
        &self,
        req: EchoRequest,
        ctx: &C,
    ) -> ActorResult<EchoResponse> {
        Ok(EchoResponse { reply: format!("Echo: {}", req.message) })
    }
}

// Code-generated Workload wrapper — inherits all 16 defaults.
pub struct EchoServiceWorkload<T: EchoServiceHandler>(pub T);

impl<T: EchoServiceHandler> Workload for EchoServiceWorkload<T> {
    type Dispatcher = EchoServiceRouter<T>;
}

Required Associated Types§

Source

type Dispatcher: MessageDispatcher<Workload = Self>

Associated dispatcher type.

Provided Methods§

Source

fn on_start<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when the node has started.

Use this to initialise business resources, start timers, etc. Returning Err aborts node startup.

Source

fn on_ready<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when signaling is connected and registration is complete: the node is now discoverable and may serve requests.

Source

fn on_stop<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when the node receives a shutdown signal.

Use this to release business resources and persist state.

Source

fn on_error<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 ErrorEvent, ) -> Pin<Box<dyn Future<Output = Result<(), ActrError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when the framework catches a runtime error.

See ErrorEvent and ErrorCategory for the structure of the argument. Use this for alerting, logging, or graceful degradation.

Source

fn on_signaling_connecting<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: Option<&'life1 C>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when signaling connection attempt begins.

ctx is None during the initial connection (before the node has obtained its identity) and Some for every subsequent reconnect.

Source

fn on_signaling_connected<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: Option<&'life1 C>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when signaling connection is established. Actor is online.

ctx is None during the initial connection and Some for every subsequent reconnect.

Source

fn on_signaling_disconnected<'life0, 'life1, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when signaling connection is lost. Actor is offline.

Source

fn on_websocket_connecting<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when a WebSocket connection attempt to a peer begins.

Source

fn on_websocket_connected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when a WebSocket connection to a peer is established.

Source

fn on_websocket_disconnected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when a WebSocket connection to a peer is lost.

Source

fn on_webrtc_connecting<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when a WebRTC P2P connection attempt to a peer begins.

Source

fn on_webrtc_connected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when a WebRTC P2P connection to a peer is established.

event.relayed carries whether the selected ICE candidate pair traverses a TURN relay (Some(true)) or is a direct P2P connection (Some(false)).

Source

fn on_webrtc_disconnected<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 PeerEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when a WebRTC P2P connection to a peer is lost.

Source

fn on_credential_renewed<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 CredentialEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when the current credential is renewed (initial registration or subsequent refresh).

Source

fn on_credential_expiring<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 CredentialEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called when the active credential is approaching its expiry.

The warning lead time is controlled by HyperConfig::credential_expiry_warning on the hyper layer.

Source

fn on_mailbox_backpressure<'life0, 'life1, 'life2, 'async_trait, C>( &'life0 self, _ctx: &'life1 C, event: &'life2 BackpressureEvent, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, C: 'async_trait + Context, Self: Sync + 'async_trait,

Called once per incident when the persistent mailbox queue length crosses the configured backpressure threshold.

Fires once per cross (rising edge); the framework resets the triggered flag once the queue falls below the threshold again.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§