Trait reactor::Handler

source ·
pub trait Handler: Send + Iterator<Item = Action<Self::Listener, Self::Transport>> {
    type Listener: Resource;
    type Transport: Resource;
    type Command: Debug + Send;

    fn tick(&mut self, time: Duration);
    fn handle_timer(&mut self);
    fn handle_listener_event(
        &mut self,
        id: <Self::Listener as Resource>::Id,
        event: <Self::Listener as Resource>::Event,
        time: Duration
    ); fn handle_transport_event(
        &mut self,
        id: <Self::Transport as Resource>::Id,
        event: <Self::Transport as Resource>::Event,
        time: Duration
    ); fn handle_command(&mut self, cmd: Self::Command); fn handle_error(&mut self, err: Error<Self::Listener, Self::Transport>); fn handover_listener(&mut self, listener: Self::Listener); fn handover_transport(&mut self, transport: Self::Transport); }
Expand description

A service which handles I/O events generated in the Reactor.

Required Associated Types§

Type for a listener resource.

Listener resources are resources which may spawn more resources and can’t be written to. A typical example of a listener resource is a std::net::TcpListener, however this may also be a special form of a peripheral device or something else.

Type for a transport resource.

Transport is a “full” resource which can be read from - and written to. Usual files, network connections, database connections etc are all fall into this category.

A command which may be sent to the Handler from outside of the Reactor, including other threads.

The handler object is owned by the reactor runtime and executes always in the context of the reactor runtime thread. Thus, if other (micro)services within the app needs to communicate to the handler they have to use this data type, which usually is an enumeration for a set of commands supported by the handler.

The commands are sent by using reactor Controller API.

Required Methods§

Method called by the reactor on the start of each event loop once the poll has returned.

Method called by the reactor when a previously set timeout is fired.

Related: Action::SetTimer.

Method called by the reactor upon an I/O event on a listener resource.

Since listener doesn’t support writing, it can be only a read event (indicating that a new resource can be spawned from the listener).

Method called by the reactor upon I/O event on a transport resource.

Method called by the reactor when a Self::Command is received for the Handler.

The commands are sent via Controller from outside of the reactor, including other threads.

Method called by the reactor on any kind of error during the event loop, including errors of the poll syscall or I/O errors returned as a part of the poll result events.

See Error for the details on errors which may happen.

Method called by the reactor upon receiving Action::UnregisterListener.

Passes the listener resource to the Handler when it is already not a part of the reactor poll. From this point of time it is safe to send the resource to other threads (like workers) or close the resource.

Method called by the reactor upon receiving Action::UnregisterTransport.

Passes the transport resource to the Handler when it is already not a part of the reactor poll. From this point of time it is safe to send the resource to other threads (like workers) or close the resource.

Implementors§