pub trait ServiceDispatcher: Send + Sync {
// Required methods
fn method_ids(&self) -> Vec<u64>;
fn dispatch(
&self,
cx: &Context,
payload: Vec<u8>,
registry: &mut ChannelRegistry,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
}Expand description
Trait for dispatching requests to a service.
The dispatcher handles both simple and channeling methods uniformly. Stream binding is done via reflection (Poke) on the deserialized args.
Required Methods§
Sourcefn method_ids(&self) -> Vec<u64>
fn method_ids(&self) -> Vec<u64>
Returns the method IDs this dispatcher handles.
Used by RoutedDispatcher to determine which methods to route
to which dispatcher.
Sourcefn dispatch(
&self,
cx: &Context,
payload: Vec<u8>,
registry: &mut ChannelRegistry,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
fn dispatch( &self, cx: &Context, payload: Vec<u8>, registry: &mut ChannelRegistry, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'static>>
Dispatch a request and send the response via the task channel.
The dispatcher is responsible for:
- Looking up the method by
cx.method_id() - Deserializing arguments from payload
- Patching channel IDs from
cx.channels()into deserialized args viapatch_channel_ids() - Binding any Tx/Rx streams via the registry
- Calling the service method
- Sending Data/Close messages for any Tx streams
- Sending the Response message via DriverMessage::Response
By using a single channel for Data/Close/Response, correct ordering is guaranteed: all stream Data and Close messages are sent before the Response.
The cx.channels() contains channel IDs from the Request message framing,
in declaration order. For a ForwardingDispatcher, this enables transparent proxying
without parsing the payload.
Returns a boxed future with 'static lifetime so it can be spawned.
Implementations should clone their service into the future to achieve this.
r[impl channeling.allocation.caller] - Stream IDs are from Request.channels (caller allocated).