Trait Event

Source
pub trait Event:
    Send
    + Sync
    + Debug {
    // Required methods
    fn handle<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<(), SimNetError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn duration(&self) -> Duration;
    fn summary(&self) -> String;

    // Provided method
    fn handle_network<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _phantom: &'life1 SimNet,
    ) -> Pin<Box<dyn Future<Output = Result<(), SimNetError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

The unit of execution for the simulator. Using handle(), simnet can schedule executions in the network. If you want to send a message for example, you would want to implement a MessageDeliveryEvent much on the lines expressed in simnet tests. You can also do other more advanced concepts such as node churn, or even simulate process spawns in a distributed system. For example, one can implement a SystemActorSimEvent in order to spawn a system actor.

Required Methods§

Source

fn handle<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), SimNetError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

This is the method that will be called when the simulator fires the event at a particular time instant. Examples: For messages, it will be delivering the message to the dst’s receiver queue. For a proc spawn, it will be creating the proc object and instantiating it. For any event that manipulates the network (like adding/removing nodes etc.) implement handle_network().

Source

fn duration(&self) -> Duration

The latency of the event. This could be network latency, induced latency (sleep), or GPU work latency.

Source

fn summary(&self) -> String

A user-friendly summary of the event

Provided Methods§

Source

fn handle_network<'life0, 'life1, 'async_trait>( &'life0 mut self, _phantom: &'life1 SimNet, ) -> Pin<Box<dyn Future<Output = Result<(), SimNetError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

This is the method that will be called when the simulator fires the event Unless you need to make changes to the network, you do not have to implement this. Only implement handle() method for all non-simnet requirements.

Implementors§