[−][src]Struct splinter::network::dispatch::Dispatcher
Dispatches messages to handlers.
The dispatcher routes messages of a specific message type to one of a set of handlers that have
been supplied via the set_handler
function. It owns a Sender
for sending messages on a
network, which is provided to the handlers. The handlers may use the sender for replying to or
broadcasting messages, as needed.
These messages are run in the same thread as the dispatch function is called. Any asynchronous activity done by a handler must be managed by the handler. These asynchronous operations must return success for the handler immediately, as the expectation is that the dispatcher should not block the current thread.
Message Types (MT) merely need to implement Hash, Eq and Debug (for unknown message type results). Beyond that, there are no other requirements.
Methods
impl<MT: Any + Hash + Eq + Debug + Clone> Dispatcher<MT>
[src]
pub fn new(network_sender: Box<dyn Sender<SendRequest>>) -> Self
[src]
Creates a Dispatcher
Creates a dispatcher with a given Sender
to supply to handlers when they are executed.
pub fn set_handler<T>(
&mut self,
message_type: MT,
handler: Box<dyn Handler<MT, T>>
) where
T: FromMessageBytes,
[src]
&mut self,
message_type: MT,
handler: Box<dyn Handler<MT, T>>
) where
T: FromMessageBytes,
Set a handler for a given Message Type.
This sets a handler for a given message type. Only one handler may exist per message type. If a user wishes to run a series handlers, they must supply a single handler that composes the series.
pub fn dispatch(
&self,
source_peer_id: &str,
message_type: &MT,
message_bytes: Vec<u8>
) -> Result<(), DispatchError>
[src]
&self,
source_peer_id: &str,
message_type: &MT,
message_bytes: Vec<u8>
) -> Result<(), DispatchError>
Dispatch a message by type.
This dispatches a message (in raw byte form) as a given message type. The message will be
handled by a handler that has been set previously via set_handler
, if one exists.
Errors
A DispatchError is returned if either there is no handler for the given message type, or an error occurs while handling the messages (e.g. the message cannot be deserialized).
Auto Trait Implementations
impl<MT> !RefUnwindSafe for Dispatcher<MT>
impl<MT> Send for Dispatcher<MT> where
MT: Send,
MT: Send,
impl<MT> !Sync for Dispatcher<MT>
impl<MT> Unpin for Dispatcher<MT> where
MT: Unpin,
MT: Unpin,
impl<MT> !UnwindSafe for Dispatcher<MT>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoSql for T
fn into_sql<T>(self) -> Self::Expression where
Self: AsExpression<T>,
Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
&'a Self: AsExpression<T>,
impl<T> SafeBorrow<T> for T where
T: ?Sized,
T: ?Sized,
fn borrow_replacement(ptr: &T) -> &T
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,