Skip to main content

ntex_server/
lib.rs

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