pub trait Handler {
    // Required methods
    fn do_handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>;
    fn client_id(&self) -> u64;
    fn for_new_client(
        &self,
        client_id: u64,
        peer_id: PubKey,
        dbid: u64
    ) -> ChannelHandler;
    fn node(&self) -> &Arc<Node>;

    // Provided methods
    fn handle(&self, msg: Message) -> Result<(Box<dyn SerBolt>, Mutations)> { ... }
    fn commit(&self) { ... }
    fn with_persist(
        &self,
        f: impl FnOnce(&Node) -> Result<()>
    ) -> Result<Mutations> { ... }
}
Expand description

A protocol handler The handle function takes an incoming message, handles it and returns a response.

There are two implementations of this trait - RootHandler for node level messages and ChannelHandler for channel level messages.

Required Methods§

source

fn do_handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>

Actual handling

source

fn client_id(&self) -> u64

Unused

source

fn for_new_client( &self, client_id: u64, peer_id: PubKey, dbid: u64 ) -> ChannelHandler

Create a channel handler

source

fn node(&self) -> &Arc<Node>

Get the associated signing node. Note that if you want to perform an operation that can result in a mutation of the node state requiring a persist, and your persister writes to the cloud, you must use Handler::with_persist instead.

Provided Methods§

source

fn handle(&self, msg: Message) -> Result<(Box<dyn SerBolt>, Mutations)>

Handle a message

source

fn commit(&self)

Commit the persister transaction if any

source

fn with_persist(&self, f: impl FnOnce(&Node) -> Result<()>) -> Result<Mutations>

Perform an operation on the Node that requires persistence. The operation must not mutate if it fails (returns an error). You must call Handler::commit after you persist the mutations in the cloud.

Object Safety§

This trait is not object safe.

Implementors§