pub struct ServerBuilder { /* private fields */ }Expand description
What a server is built with, and served by, see Self::serve.
Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn new(exe: &str, inst: &str) -> Self
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.
Sourcepub fn backend(self, backend: Arc<dyn Backend>) -> Self
pub fn backend(self, backend: Arc<dyn Backend>) -> Self
The backend to serve with, the default one if none is given, see
default_backend.
Sourcepub fn database(self, database: DatabaseProxy) -> Self
pub fn database(self, database: DatabaseProxy) -> Self
The database to register in, the one of the environment if none is given.
Sourcepub fn host(self, host: &str) -> Self
pub fn host(self, host: &str) -> Self
The host to listen at, see BackendServerConfig::host.
Sourcepub fn port<R: RangeBounds<u16>>(self, port: R) -> Self
pub fn port<R: RangeBounds<u16>>(self, port: R) -> Self
The port to listen at, see BackendServerConfig::port.
Sourcepub fn zmq_heartbeat_port<R: RangeBounds<u16>>(self, port: R) -> Self
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.
Sourcepub fn zmq_event_port<R: RangeBounds<u16>>(self, port: R) -> Self
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.
Sourcepub fn local(self, local: bool) -> Self
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.
Sourcepub fn class<M: Model>(self, def: ClassDef<M>) -> Self
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.
Sourcepub fn stop_on_terminate(self, stop_on_terminate: bool) -> Self
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.
Sourcepub fn boot_timeout(self, boot_timeout: Duration) -> Self
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.
Sourcepub fn serve(self) -> Result<ServerHandle>
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.
Sourcepub async fn serve_async(self) -> Result<ServerHandle>
pub async fn serve_async(self) -> Result<ServerHandle>
Start serving, see Self::serve, resolving once the whole server is booted.
Sourcepub fn run(self) -> Result<()>
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§impl ServerBuilder
impl ServerBuilder
Sourcepub fn terminate_on_signals(self, terminate_on_signals: bool) -> Self
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.
Sourcepub fn from_args() -> Self
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.
Sourcepub fn from_raw_args(exec: Option<&str>, args: Option<&ServerArgs>) -> Self
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.