ServerBuilder

Struct ServerBuilder 

Source
pub struct ServerBuilder<D>{ /* 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>

Source

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
Source

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.

Source

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.

Source

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

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

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

impl<L> LayerExt<L> for L

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more