Skip to main content

ControlServer

Struct ControlServer 

Source
pub struct ControlServer<H>
where H: LifecycleHandle + Clone + Send + Sync + 'static,
{ /* private fields */ }
Expand description

HTTP server that hosts the control plane router.

Generic over H, which must implement lightshuttle_runtime::LifecycleHandle. The handle is held inside a crate::ControlState and shared across all route handlers via axum’s state mechanism.

§Usage

  1. Call bind to open a listener (loopback only, no authentication).
  2. Build a crate::ControlState with the project name and handle.
  3. Construct a ControlServer via ControlServer::new.
  4. Await ControlServer::serve with a shutdown future.

For in-process integration tests, use ControlServer::into_router to get the raw axum router and drive it with tower::ServiceExt::oneshot without opening a TCP socket.

Implementations§

Source§

impl<H> ControlServer<H>
where H: LifecycleHandle + Clone + Send + Sync + 'static,

Source

pub fn new(state: ControlState<H>) -> Self

Build a server from the given shared state.

The state holds the project name, the lifecycle handle, and the Prometheus metrics renderer. It is moved into the axum router when ControlServer::serve or ControlServer::into_router is called.

Source

pub fn into_router(self) -> Router

Consume the server and return the underlying axum::Router.

Useful for in-process integration tests: pass the router to tower::ServiceExt::oneshot to send synthetic requests without the overhead of a real TCP bind.

Source

pub async fn serve<F>(self, listener: TcpListener, shutdown: F) -> Result<()>
where F: Future<Output = ()> + Send + 'static,

Run the control plane on listener until shutdown resolves.

Starts accepting connections immediately. When shutdown resolves, axum performs a graceful shutdown: it stops accepting new connections and waits for in-flight requests to complete before returning.

§Errors

Propagates any std::io::Error from the underlying TCP accept loop.

§Example
use std::net::SocketAddr;
use lightshuttle_control::{ControlState, ControlServer, bind};

let addr: SocketAddr = "127.0.0.1:9090".parse().unwrap();
let listener = bind(addr).await?;
let state = ControlState::new("my-project", MyHandle);
let server = ControlServer::new(state);

// Shutdown when Ctrl-C is received.
server
    .serve(listener, async { tokio::signal::ctrl_c().await.ok(); })
    .await

Auto Trait Implementations§

§

impl<H> Freeze for ControlServer<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for ControlServer<H>
where H: RefUnwindSafe,

§

impl<H> Send for ControlServer<H>

§

impl<H> Sync for ControlServer<H>

§

impl<H> Unpin for ControlServer<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for ControlServer<H>
where H: UnsafeUnpin,

§

impl<H> UnwindSafe for ControlServer<H>
where H: UnwindSafe,

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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