Skip to main content

ServerBuilder

Struct ServerBuilder 

Source
pub struct ServerBuilder { /* private fields */ }
Expand description

What a server is built with, and served by, see Self::serve.

Implementations§

Source§

impl ServerBuilder

Source

pub fn new(exe: &str, inst: &str) -> Self

Build a server named exe/inst, after the executable running it and the name of the instance of that executable, which is how it is registered in the database.

Source

pub fn backend(self, backend: Arc<dyn Backend>) -> Self

The backend to serve with, the default one if none is given, see default_backend.

Source

pub fn database(self, database: DatabaseProxy) -> Self

The database to register in, the one of the environment if none is given.

Source

pub fn host(self, host: &str) -> Self

The host to listen at, see BackendServerConfig::host.

Source

pub fn port(self, port: u16) -> Self

The port to listen at, see BackendServerConfig::port.

Source

pub fn local(self, local: bool) -> Self

Enable or disable registration of the this server’s devices into the local registry, which allow [DevProxy] created in this same process to access the the device directly without going through the backend’s wire protocol.

Source

pub fn class<M: Model>(self, def: ClassDef<M>) -> Result<Self>

Define a class in that server, whose devices the database can then list.

Source

pub fn stop_on_signal(self, stop_on_signal: bool) -> Self

Stop the server on the signals the process is asked to terminate with, which is the default: Ctrl-C, and SIGTERM and SIGHUP on Unix, the console being closed on Windows. The server is then stopped as the Kill command of its admin device does, see Server::stop, and the thread waiting on it deletes its devices, see ServerHandle::wait.

There is a single handler of these signals per process, which serving fails to install if the application installed one of its own: this is then disabled, and the application stops the server itself.

Source

pub fn serve(self) -> Result<ServerHandle>

Start serving: the backend is acquired, every class is made from its definition, and the admin device is added and synchronized, which boots the whole server.

This fails if the admin device fails to initialize, which is what a server that cannot reach its database does: it would have nothing to serve.

This blocks, see Self::serve_async for what does not.

Source

pub fn run(self) -> Result<()>

Serve until the server is stopped, by a signal or the Kill command of its admin device, then delete its devices: this is Self::serve then ServerHandle::wait, which is all the main thread of most servers does.

Source

pub async fn run_async(self) -> Result<()>

Serve until the server is stopped, see Self::run.

Source

pub async fn serve_async(self) -> Result<ServerHandle>

Start serving, see Self::serve, resolving once the whole server is booted.

Source§

impl ServerBuilder

Source

pub fn from_args() -> Self

Build the server from the command line of this process, see ServerArgs, which is what launching a server usually takes. The process exits with its usage when the command line is invalid or asks for help.

See Self::from_raw_args for what the server is named after.

Source

pub fn from_raw_args(exec: Option<&str>, args: Option<&ServerArgs>) -> Self

Build the server named after that executable and the instance of that command line, see ServerArgs, which is also where it listens. The logs of the process are printed at the level it asks for.

With no executable given, the server is named after the one of this process, as cppTango names it: the name the process was run under, without its directory nor the suffix of the platform’s executables, which is what the Starter of a host runs a server by. Giving one keeps the name of the server whatever its file is called.

With no command line given, the one of this process is parsed, as Self::from_args does; a server with options of its own parses it itself and gives what it flattened, see ServerArgs.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Model for T
where T: Send + Sync + 'static,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more