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<R: RangeBounds<u16>>(self, port: R) -> Self

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

Source

pub fn zmq_heartbeat_port<R: RangeBounds<u16>>(self, port: R) -> Self

Make ZMQ listen at this port for its heartbeat, see BackendServerConfig::zmq_heartbeat_port.

Source

pub fn zmq_event_port<R: RangeBounds<u16>>(self, port: R) -> Self

Make ZMQ listen at this port for its events, see BackendServerConfig::zmq_event_port.

Source

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

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

Source

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

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

§Panics

If the name of the class is invalid, see name::check_tango_class_name, if it is the one of the admin class, or if the server already defines a class of that name.

Source

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

Stop the server when the process terminates, see terminate, which is not the default unless built from the command line, see Self::terminate_on_signals. The server is then stopped as the Kill command of its admin device does, which deletes its devices, see Server::stop_async, and the thread waiting on it returns, see Server::wait. A server still booting gives up its boot, see Self::serve.

Source

pub fn boot_timeout(self, boot_timeout: Duration) -> Self

How long the server is given to boot when served blocking, 30 seconds by default, see Self::serve: the database being reached, every device initialized and every one of them exported. An asynchronous caller bounds Self::serve_async 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, and fails once the server did not boot within its timeout, see Self::boot_timeout, or once the process terminates while it boots, see Self::stop_on_terminate. The boot is then given up wherever it was, so devices it had exported already stay exported in the database until the server is served again.

Source

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

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

Source

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

Serve until the server is stopped, by terminate (on a signal when Self::terminate_on_signals is set) or by the Kill command of its admin device, which deletes its devices: this is Self::serve then Server::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§

impl ServerBuilder

Source

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

Terminate the process on the signals it is asked to terminate with, see terminate::terminate, which a server built from the command line does: Ctrl-C, and SIGTERM and SIGHUP on Unix, the console being closed on Windows. Handling them also stops the server on termination, see Self::stop_on_terminate.

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 calls terminate::terminate from its own handler.

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