pub struct ServerBuilder<D>where
D: RequestDispatcher,{ /* private fields */ }Expand description
ABCI server builder that creates and starts ABCI server
Create new server with ServerBuilder::new(), configure it as needed, and
finalize using ServerBuilder::build(). This will create and start new
ABCI server.
Use Server::next_client() to accept connection from ABCI client
(Tenderdash) and start processing incoming requests. Each incoming
connection will be processed using app.
§Examples
struct MyAbciApplication {};
impl tenderdash_abci::Application for MyAbciApplication {};
let app = MyAbciApplication {};
let bind_address = "unix:///tmp/abci.sock";
let server = tenderdash_abci::ServerBuilder::new(app, &bind_address).build().expect("server failed");
loop {
if let Err(tenderdash_abci::Error::Cancelled()) = server.next_client() {
break;
}
}Implementations§
Source§impl<'a, App: RequestDispatcher + 'a> ServerBuilder<App>
impl<'a, App: RequestDispatcher + 'a> ServerBuilder<App>
Sourcepub fn new(app: App, address: &str) -> Self
pub fn new(app: App, address: &str) -> Self
Create new server builder.
§Arguments
address- address in URI format, pointing either to TCP address and port (eg.tcp://0.0.0.0:1234,tcp://[::1]:1234) or Unix socket (unix:///var/run/abci.sock)app- request dispatcher, most likely implementation of Application trait
Sourcepub fn build(self) -> Result<Box<dyn Server + 'a>, Error>
pub fn build(self) -> Result<Box<dyn Server + 'a>, Error>
Build and start the ABCI server.
§Return
Returns Server which provides Server::next_client()
method. Call it in a loop to accept and process incoming
connections.
Sourcepub fn with_cancel_token(self, cancel: CancellationToken) -> Self
pub fn with_cancel_token(self, cancel: CancellationToken) -> Self
Set a CancellationToken token to support graceful shutdown.
Call CancellationToken::cancel() to stop the server gracefully.
Sourcepub fn with_runtime(self, runtime_handle: Handle) -> Self
pub fn with_runtime(self, runtime_handle: Handle) -> Self
Set tokio Runtime to use.
By default, current tokio runtime is used. If no runtime is active (Handle::try_current() returns error), new multi-threaded runtime is started. If this is not what you want, use ServerBuilder::with_runtime() to provide handler to correct Tokio runtime.
§Example
use tokio::runtime::{Handle, Runtime};
use tenderdash_abci::{RequestDispatcher, ServerBuilder, CancellationToken, Application};
// Your custom RequestDispatcher implementation
struct MyApp;
impl Application for MyApp {}
// Create a Tokio runtime
let runtime = Runtime::new().unwrap();
let runtime_handle = runtime.handle().clone();
// Create an instance of your RequestDispatcher implementation
let app = MyApp;
// Create cancellation token
let cancel = CancellationToken::new();
// Create a ServerBuilder instance and set the runtime using with_runtime()
let server = ServerBuilder::new(app, "tcp://0.0.0.0:17534")
.with_runtime(runtime_handle)
.with_cancel_token(cancel)
.build();In this example, we first create a Tokio runtime and get its handle.
Then we create an instance of our MyApp struct that implements the
RequestDispatcher trait. We create a ServerBuilder instance by
calling new() with our MyApp instance and then use the
with_runtime() method to set the runtime handle. Finally, you can
continue building your server and eventually run it.
Auto Trait Implementations§
impl<D> !Freeze for ServerBuilder<D>
impl<D> RefUnwindSafe for ServerBuilder<D>where
D: RefUnwindSafe,
impl<D> Send for ServerBuilder<D>where
D: Send,
impl<D> Sync for ServerBuilder<D>where
D: Sync,
impl<D> Unpin for ServerBuilder<D>where
D: Unpin,
impl<D> UnwindSafe for ServerBuilder<D>where
D: UnwindSafe,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].