pub struct Server {
pub state_rx: Receiver<ServingState>,
/* private fields */
}Fields§
§state_rx: Receiver<ServingState>Implementations§
Source§impl Server
impl Server
Sourcepub fn into_router(self) -> (Routes, JoinHandle<Result<(), ServerError>>)
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.
pub async fn serve(self, addr: SocketAddr) -> Result<(), ServerError>
Sourcepub async fn serve_with_shutdown(
self,
addr: SocketAddr,
shutdown: impl Future<Output = ()> + Send + 'static,
) -> Result<(), ServerError>
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:
shutdownfires 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).- Watch returns
Ok(Err(e))→ poisoned state is already published;cancel_txtriggers tonic’s graceful shutdown; in-flightGetTscalls whosetry_grantalready succeeded complete with the timestamps they were allocated; new calls fail fast. ReturnsErr(e). - Watch task panics → returns
Err(ServerError::WatchPanic{..})with the panic payload stringified. Same drain semantics as (2).
Sourcepub async fn serve_with_listener(
self,
listener: TcpListener,
shutdown: impl Future<Output = ()> + Send + 'static,
) -> Result<(), ServerError>
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:
shutdownfires first → tonic drains in-flights and returnsOk. The watch handle is aborted; any error it had been about to return is forfeited (the process is shutting down anyway).- Watch returns
Ok(Err(e))→ poisoned state is already published; the caller-provided shutdown is cancelled internally so tonic begins graceful shutdown; in-flightGetTscalls whosetry_grantalready succeeded complete with the timestamps they were allocated; new calls fail fast. ReturnsErr(e). - Watch task panics → returns
Err(ServerError::WatchPanic{..})with the panic payload stringified. Same drain semantics as (2).
Auto Trait Implementations§
impl Freeze for Server
impl !RefUnwindSafe for Server
impl Send for Server
impl Sync for Server
impl Unpin for Server
impl UnsafeUnpin for Server
impl !UnwindSafe for Server
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request