pub struct ServerHandle { /* private fields */ }Expand description
Cloneable handle to a running Server.
The handle is the public control surface: shutdown, reload, stats, events, request injection, topology snapshots.
Implementations§
Source§impl ServerHandle
impl ServerHandle
Sourcepub fn crypto_provider(&self) -> Option<&dyn CryptoProvider>
pub fn crypto_provider(&self) -> Option<&dyn CryptoProvider>
Borrow the configured CryptoProvider, if one was
plugged. The default builder does not install one.
Sourcepub fn command_extension(&self) -> Option<Arc<dyn CommandExtension>>
pub fn command_extension(&self) -> Option<Arc<dyn CommandExtension>>
Borrow the crate::embed::CommandExtension installed
at build time, if any.
Sourcepub fn listen_addr(&self) -> Option<SocketAddr>
pub fn listen_addr(&self) -> Option<SocketAddr>
Local listen address (post-bind), if a listen: was
configured.
Sourcepub fn dyn_listen_addr(&self) -> Option<SocketAddr>
pub fn dyn_listen_addr(&self) -> Option<SocketAddr>
Local dnode listen address (post-bind), if a
dyn_listen: was configured.
Sourcepub fn subscribe_events(&self) -> EventStream
pub fn subscribe_events(&self) -> EventStream
Subscribe to the ServerEvent broadcast.
§Examples
let server = ServerBuilder::new("p")
.listen("127.0.0.1:0".parse().unwrap())
.dyn_listen("127.0.0.1:0".parse().unwrap())
.data_store(DataStore::Redis)
.servers(vec![dynomite::conf::ConfServer::parse("127.0.0.1:6379:1").unwrap()])
.tokens_str("0")
.build().unwrap();
let handle = server.start().await.unwrap();
let _events = handle.subscribe_events();
handle.shutdown().await.unwrap();Sourcepub fn events(&self) -> Arc<EventManager> ⓘ
pub fn events(&self) -> Arc<EventManager> ⓘ
Borrow the EventManager handle that publishes
structured cluster-event payloads (PeerUp, PeerDown,
GossipRoundComplete, etc.).
Returned as Arc so embedders can hold a long-lived
reference and pass it across crate boundaries (notably to
dyniak, which publishes AAE start/complete events).
Sourcepub fn stats_handle(&self) -> Arc<Stats> ⓘ
pub fn stats_handle(&self) -> Arc<Stats> ⓘ
Borrow the live Stats aggregator as a shared handle.
Returns the same Arc<Stats> the runtime publishes to,
so an embedder can read counters as they update without
going through the periodic snapshot path. Useful for
in-process metrics integrations that prefer a pull model
(Prometheus scrape, OpenTelemetry pull readers) over the
push-on-flush path exposed by MetricsSink.
The returned handle is Clone; callers may share it
across threads. The aggregator outlives the handle for as
long as the ServerHandle tree is alive.
Sourcepub fn describe_stats(&self) -> Vec<MetricSpec>
pub fn describe_stats(&self) -> Vec<MetricSpec>
Manifest of every metric the engine emits.
Sourcepub fn peers(&self) -> Vec<PeerSnapshot>
pub fn peers(&self) -> Vec<PeerSnapshot>
Snapshot of every peer in the cluster.
Sourcepub fn datacenters(&self) -> Vec<DatacenterSnapshot>
pub fn datacenters(&self) -> Vec<DatacenterSnapshot>
Snapshot of every datacenter and its racks.
Sourcepub fn ring(&self) -> RingSnapshot
pub fn ring(&self) -> RingSnapshot
Snapshot of the token ring.
Sourcepub async fn inject_request(&self, req: Msg) -> Result<Msg, EmbedError>
pub async fn inject_request(&self, req: Msg) -> Result<Msg, EmbedError>
Inject a parsed request as if it had arrived from a client. Returns the response message.
This is the test/embedding entry point that bypasses the
proxy listener. The dispatcher computes a routing plan; if
the plan resolves to the local datastore, the
Datastore::dispatch
hook is invoked. If the plan resolves to a remote peer
co-located in the same process (via the in-process
registry), the request is forwarded to that peer’s
datastore and its response is returned.
Sourcepub async fn reload(&self, cfg: Config) -> Result<(), EmbedError>
pub async fn reload(&self, cfg: Config) -> Result<(), EmbedError>
Reload the configuration. Validates the new Config
before any state is touched; on failure the running config
is left untouched.
This is the in-process equivalent of SIGHUP. The C
reference’s dynomite_reload_conf (in
_/dynomite/src/dynomite.c) re-reads the YAML from disk;
the embedding API takes the Config directly.
Sourcepub async fn shutdown(&self) -> Result<(), EmbedError>
pub async fn shutdown(&self) -> Result<(), EmbedError>
Graceful shutdown.
Cancels every background task, deregisters from the
in-process peer registry, drains the join set, and
returns. Idempotent: calling shutdown after a previous
shutdown (or after ServerHandle::join returned)
completes successfully without doing any work.
Sourcepub async fn join(&self)
pub async fn join(&self)
Wait for every background task to complete.
Unlike ServerHandle::shutdown, join does not request
cancellation: it parks the caller until the runtime tasks
(gossip, stats aggregator, accept loops, metrics flusher)
finish on their own. The intended use is the
“start-then-park” pattern in long-running embedders that
drive shutdown from a separate signal handler:
let handle = ServerBuilder::new("p")
.listen("127.0.0.1:0".parse().unwrap())
.dyn_listen("127.0.0.1:0".parse().unwrap())
.data_store(DataStore::Redis)
.servers(vec![dynomite::conf::ConfServer::parse("127.0.0.1:6379:1").unwrap()])
.tokens_str("0")
.build().unwrap()
.start().await.unwrap();
let shutdown = handle.clone();
tokio::spawn(async move {
// Replace with `tokio::signal::ctrl_c().await.unwrap();`
// in a real embedder.
shutdown.shutdown().await.unwrap();
});
handle.join().await;join resolves once every task spawned by
Server::start has returned. Calling join repeatedly
is safe; the second call returns immediately because the
task set is drained on the first.
Trait Implementations§
Source§impl Clone for ServerHandle
impl Clone for ServerHandle
Source§fn clone(&self) -> ServerHandle
fn clone(&self) -> ServerHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more