[][src]Struct srvzio::manager::ServiceManager

pub struct ServiceManager { /* fields omitted */ }

Manages an internal collection of Services

This implements a simple Composite Pattern that allows to manages a group of Service in a coordinated fashion.

Services are start()ed in the order they are registered, and stop()ped in the reverse order. Also, a ServiceManager is also a Service, so further composition is possible.

The design implies that in your application, you would hand over all the instances of Service to a ServiceManager, that will then orchestrate their starting and stopping.

Thanks to the use of Composite Pattern, it can contain further instances of ServiceManager, allowing for the creation of complex DAG diagrams of services, with expressive relationship between them.

Methods

impl ServiceManager[src]

pub fn new() -> Self[src]

Constructor

pub fn register(&mut self, service_box: Box<dyn Service>)[src]

Register an instance of Service.

The order of registration is important: Services are started in order, and stopped in reverse order.

Parameters

  • service_box: a Box containing an instance of implementation of the Service trait

pub fn wait_termination_signal_then_stop(&mut self)[src]

Wait for the Process to receive a termination signal, then stop this ServiceManager.

It's strongly advised to use this method only onces, for the root ServiceManager, at the end of the main() thread.

Trait Implementations

impl Service for ServiceManager[src]

fn start(&mut self)[src]

Start all registered Services, in order of registration

fn await_started(&mut self)[src]

Wait for all registered Services to be started, in order of registration

fn start_and_await(&mut self)[src]

Start and then wait for all registered Service, in order of registration

This is different then calling start() and then await_started(), because this method will wait for a Service to be started, before moving to the next one.

This can be used to implement a gracefull start.

fn stop(&mut self)[src]

Stop all registered Services, in reverse order of registration

fn await_stopped(&mut self)[src]

Wait for all registered Services to be stopped, in reverse order of registration

fn stop_and_await(&mut self)[src]

Stop and then wait for all registered Service, in reverse order of registration

This is different then calling stop() and then await_stopped(), because this method will wait for a Service to be stopped, before moving to the next one.

This can be used to implement a gracefull stop.

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]