[−][src]Struct srvzio::manager::ServiceManager
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: Service
s are started in order, and stopped
in reverse order.
Parameters
service_box
: aBox
containing an instance of implementation of theService
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 Service
s, in order of registration
fn await_started(&mut self)
[src]
Wait for all registered Service
s 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 Service
s, in reverse order of registration
fn await_stopped(&mut self)
[src]
Wait for all registered Service
s 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
impl !Send for ServiceManager
impl !Sync for ServiceManager
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom 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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto 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<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,