thrift_runtime_server (thrift_runtime v0.7.0)
View SourceSupervision root of a Thrift server: one acceptor, restartable.
start_link(Opts) takes the same map as thrift_runtime_acceptor (plus an
optional name); the acceptor is a permanent child, so a crashing
listener comes back. All configuration is given here at creation time.
Example:
{ok, Server} = thrift_runtime_server:start_link(#{port => 0, handler => my_handler, service => my_service}),
{ok, Port} = thrift_runtime_server:port(Server).Multiplexed (several services on one port, clients opt in with the
multiplex option on the client side):
{ok, Server} = thrift_runtime_server:start_link(#{
port => 0,
services => #{
<<"First">> => #{handler => first_handler, service => first_service},
<<"Second">> => #{handler => second_handler, service => second_service}
}
}).
Summary
Functions
Returns the bound port (useful with port = 0).
Starts the server supervision tree.
Stops the server: the acceptor and, through it, all connections.
Stops the server, optionally draining first.
Types
-type options() :: thrift_runtime_acceptor:options().
Functions
-spec port(pid() | atom()) -> {ok, inet:port_number()}.
Returns the bound port (useful with port = 0).
Starts the server supervision tree.
A failed init answers {error, Reason} only: the trapping around the
start shields the caller from the failed supervisor's exit race, the
same dance thrift_runtime_client does.
Stops the server: the acceptor and, through it, all connections.
Stops the server, optionally draining first.
With #{drain := Timeout} the acceptor closes the listen socket, lets
in-flight calls finish (up to Timeout; infinity allowed) and lets
pending accepts unwind, then the supervision tree is stopped as by
stop/1 — whatever the deadline leaves over is terminated the normal
supervised way, so a connection stuck past the deadline fails its
calls. Without the key this is plain stop/1.