ntex_server/
lib.rs

1#![deny(rust_2018_idioms, unreachable_pub, missing_debug_implementations)]
2#![allow(clippy::let_underscore_future)]
3
4use ntex_service::ServiceFactory;
5
6mod manager;
7pub mod net;
8mod pool;
9mod server;
10mod signals;
11mod wrk;
12
13pub use self::pool::WorkerPool;
14pub use self::server::Server;
15pub use self::signals::{signal, Signal};
16pub use self::wrk::{Worker, WorkerStatus, WorkerStop};
17
18/// Worker id
19#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
20pub struct WorkerId(usize);
21
22impl WorkerId {
23    pub(self) fn next(&mut self) -> WorkerId {
24        let id = WorkerId(self.0);
25        self.0 += 1;
26        id
27    }
28}
29
30#[allow(async_fn_in_trait)]
31/// Worker service factory.
32pub trait ServerConfiguration: Send + Clone + 'static {
33    type Item: Send + 'static;
34    type Factory: ServiceFactory<Self::Item> + 'static;
35
36    /// Create service factory for handling `WorkerMessage<T>` messages.
37    async fn create(&self) -> Result<Self::Factory, ()>;
38
39    /// Server is paused.
40    fn paused(&self) {}
41
42    /// Server is resumed.
43    fn resumed(&self) {}
44
45    /// Server is stopped
46    fn terminate(&self) {}
47
48    /// Server is stopped
49    async fn stop(&self) {}
50}