Skip to main content

Server

Struct Server 

Source
pub struct Server {
    pub state_rx: Receiver<ServingState>,
    /* private fields */
}

Fields§

§state_rx: Receiver<ServingState>

Implementations§

Source§

impl Server

Source§

impl Server

Source

pub fn into_router(self) -> (Routes, JoinHandle<Result<(), ServerError>>)

Return the configured TsoServiceServer<TsoServiceImpl> as a tonic Routes value plus a JoinHandle for the spawned leader-watch task, so callers can mount tsoracle’s service alongside their own services on a shared tonic listener instead of binding a dedicated port.

The JoinHandle payload is Result<(), ServerError> so embedders can observe leader-watch termination. The task never returns Ok(()): every termination — driver error, panic, or clean EOF on the leadership stream (surfaced as ServerError::WatchStreamClosed) — publishes ServingState::NotServing { leader_endpoint: None } before returning, so all subsequent RPCs fail fast with FAILED_PRECONDITION. Embedders who never inspect the handle still get fail-safe behavior.

The Server::serve() method is a thin wrapper over this — it calls into_router, builds a tonic Server, and binds a listener.

Source

pub async fn serve(self, addr: SocketAddr) -> Result<(), ServerError>

Source

pub async fn serve_with_shutdown( self, addr: SocketAddr, shutdown: impl Future<Output = ()> + Send + 'static, ) -> Result<(), ServerError>

Run the gRPC server until either the caller’s shutdown fires or the leader-watch task terminates.

Three outcomes:

  1. shutdown fires first → tonic drains in-flights and returns Ok. The watch handle is aborted; any error it had been about to return is forfeited (the process is shutting down anyway).
  2. Watch returns Ok(Err(e)) → poisoned state is already published; cancel_tx triggers tonic’s graceful shutdown; in-flight GetTs calls whose try_grant already succeeded complete with the timestamps they were allocated; new calls fail fast. Returns Err(e).
  3. Watch task panics → returns Err(ServerError::WatchPanic{..}) with the panic payload stringified. Same drain semantics as (2).
Source

pub async fn serve_with_listener( self, listener: TcpListener, shutdown: impl Future<Output = ()> + Send + 'static, ) -> Result<(), ServerError>

Run the gRPC server on a caller-provided TcpListener until either the caller-provided shutdown fires or the leader-watch task terminates.

Use this instead of Self::serve_with_shutdown when you need to observe the OS-picked port (127.0.0.1:0) before clients connect, or when you want to wrap the listener in an outer adapter before passing it in. The listening socket is owned by the caller and passed here; tsoracle starts accepting on it immediately.

Three outcomes:

  1. shutdown fires first → tonic drains in-flights and returns Ok. The watch handle is aborted; any error it had been about to return is forfeited (the process is shutting down anyway).
  2. Watch returns Ok(Err(e)) → poisoned state is already published; the caller-provided shutdown is cancelled internally so tonic begins graceful shutdown; in-flight GetTs calls whose try_grant already succeeded complete with the timestamps they were allocated; new calls fail fast. Returns Err(e).
  3. Watch task panics → returns Err(ServerError::WatchPanic{..}) with the panic payload stringified. Same drain semantics as (2).

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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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<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