Skip to main content

ServerHandle

Struct ServerHandle 

Source
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

Source

pub fn crypto_provider(&self) -> Option<&dyn CryptoProvider>

Borrow the configured CryptoProvider, if one was plugged. The default builder does not install one.

Source

pub fn command_extension(&self) -> Option<Arc<dyn CommandExtension>>

Borrow the crate::embed::CommandExtension installed at build time, if any.

Source

pub fn listen_addr(&self) -> Option<SocketAddr>

Local listen address (post-bind), if a listen: was configured.

Source

pub fn dyn_listen_addr(&self) -> Option<SocketAddr>

Local dnode listen address (post-bind), if a dyn_listen: was configured.

Source

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();
Source

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).

Source

pub fn stats(&self) -> Snapshot

Latest stats snapshot.

Source

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.

Source

pub fn describe_stats(&self) -> Vec<MetricSpec>

Manifest of every metric the engine emits.

Source

pub fn peers(&self) -> Vec<PeerSnapshot>

Snapshot of every peer in the cluster.

Source

pub fn datacenters(&self) -> Vec<DatacenterSnapshot>

Snapshot of every datacenter and its racks.

Source

pub fn ring(&self) -> RingSnapshot

Snapshot of the token ring.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ServerHandle

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,