Struct workflow_rpc::server::RpcServer
source · pub struct RpcServer { /* private fields */ }Expand description
RpcServer - a server-side object that listens
for incoming websocket connections and delegates interaction
with them to the supplied interfaces: RpcHandler (for RPC server
management) and Interface (for method and notification dispatch).
Implementations§
source§impl RpcServer
impl RpcServer
sourcepub fn new<ServerContext, ConnectionContext, Protocol, Ops>(
rpc_handler: Arc<dyn RpcHandler<Context = ConnectionContext>>,
interface: Arc<Interface<ServerContext, ConnectionContext, Ops>>,
counters: Option<Arc<WebSocketCounters>>,
enable_async_handling: bool,
) -> RpcServer
pub fn new<ServerContext, ConnectionContext, Protocol, Ops>( rpc_handler: Arc<dyn RpcHandler<Context = ConnectionContext>>, interface: Arc<Interface<ServerContext, ConnectionContext, Ops>>, counters: Option<Arc<WebSocketCounters>>, enable_async_handling: bool, ) -> RpcServer
Create a new RpcServer supplying an Arc of the previously-created
RpcHandler trait and the Interface struct.
This method takes 4 generics:
ConnectionContext: a struct used asRpcHandler::Contextto represent the connection. This struct is passed to each RPC method and notification call.ServerContext: a struct supplied to theInterfaceat the Interface creation time. This struct is passed to each RPC method and notification call.Protocol: A protocol type used for the RPC message serialization and deserialization (this can be omitted by usingRpcServer::new_with_encoding)Ops: A data type (index or anenum) representing the RPC method or notification.
sourcepub fn new_with_encoding<ServerContext, ConnectionContext, Ops, Id>(
encoding: Encoding,
rpc_handler: Arc<dyn RpcHandler<Context = ConnectionContext>>,
interface: Arc<Interface<ServerContext, ConnectionContext, Ops>>,
counters: Option<Arc<WebSocketCounters>>,
enable_async_handling: bool,
) -> RpcServer
pub fn new_with_encoding<ServerContext, ConnectionContext, Ops, Id>( encoding: Encoding, rpc_handler: Arc<dyn RpcHandler<Context = ConnectionContext>>, interface: Arc<Interface<ServerContext, ConnectionContext, Ops>>, counters: Option<Arc<WebSocketCounters>>, enable_async_handling: bool, ) -> RpcServer
Create a new RpcServer supplying an Arc of the previously-created
RpcHandler trait and the Interface struct.
This method takes 4 generics:
ConnectionContext: a struct used asRpcHandler::Contextto represent the connection. This struct is passed to each RPC method and notification call.ServerContext: a struct supplied to theInterfaceat the Interface creation time. This struct is passed to each RPC method and notification call.Ops: A data type (index or anenum) representing the RPC method or notification.Id: A data type representing a messageId- this type must implement theid::Generatortrait. Implementation for default Ids such asId32andId64can be found in theidmodule.
This function call receives an encoding: Encoding argument containing
Encoding::Borsh or Encoding::SerdeJson, based on which it will
instantiate the corresponding protocol handler (BorshProtocol or
JsonProtocol respectively).
enable_async_handling is a boolean flag that determines if the server
should spawn a new async task for each incoming message. If set to false,
the server will handle message intake synchronously where each message
is posted to the underlying handler one-at-a-time. (i.e. RPC awaits for the
message intake processing to be complete before the next message arrives).
If true, each message is dispatched via a new async task.
sourcepub async fn bind(&self, addr: &str) -> WebSocketResult<TcpListener>
pub async fn bind(&self, addr: &str) -> WebSocketResult<TcpListener>
Bind network interface address to the TcpListener
sourcepub async fn listen(
&self,
listener: TcpListener,
config: Option<WebSocketConfig>,
) -> WebSocketResult<()>
pub async fn listen( &self, listener: TcpListener, config: Option<WebSocketConfig>, ) -> WebSocketResult<()>
Start listening for incoming RPC connections on the supplied TcpListener
sourcepub fn stop(&self) -> WebSocketResult<()>
pub fn stop(&self) -> WebSocketResult<()>
Signal the listening task to stop
sourcepub async fn join(&self) -> WebSocketResult<()>
pub async fn join(&self) -> WebSocketResult<()>
Blocks until the listening task has stopped
sourcepub async fn stop_and_join(&self) -> WebSocketResult<()>
pub async fn stop_and_join(&self) -> WebSocketResult<()>
Signal the listening task to stop and block until it has stopped
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RpcServer
impl !RefUnwindSafe for RpcServer
impl Send for RpcServer
impl Sync for RpcServer
impl Unpin for RpcServer
impl !UnwindSafe for RpcServer
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.