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>>
) -> RpcServerwhere
ServerContext: Clone + Send + Sync + 'static,
ConnectionContext: Clone + Send + Sync + 'static,
Protocol: ProtocolHandler<ServerContext, ConnectionContext, Ops> + Send + Sync + 'static,
Ops: OpsT,
pub fn new<ServerContext, ConnectionContext, Protocol, Ops>(
rpc_handler: Arc<dyn RpcHandler<Context = ConnectionContext>>,
interface: Arc<Interface<ServerContext, ConnectionContext, Ops>>
) -> RpcServerwhere
ServerContext: Clone + Send + Sync + 'static,
ConnectionContext: Clone + Send + Sync + 'static,
Protocol: ProtocolHandler<ServerContext, ConnectionContext, Ops> + Send + Sync + 'static,
Ops: OpsT,
Create a new RpcServer supplying an Arc of the previsouly-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>>
) -> RpcServerwhere
ServerContext: Clone + Send + Sync + 'static,
ConnectionContext: Clone + Send + Sync + 'static,
Ops: OpsT,
Id: IdT,
pub fn new_with_encoding<ServerContext, ConnectionContext, Ops, Id>(
encoding: Encoding,
rpc_handler: Arc<dyn RpcHandler<Context = ConnectionContext>>,
interface: Arc<Interface<ServerContext, ConnectionContext, Ops>>
) -> RpcServerwhere
ServerContext: Clone + Send + Sync + 'static,
ConnectionContext: Clone + Send + Sync + 'static,
Ops: OpsT,
Id: IdT,
Create a new RpcServer supplying an Arc of the previsouly-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
SerdeJsonProtocol respectively).
sourcepub async fn listen(&self, addr: &str) -> WebSocketResult<()>
pub async fn listen(&self, addr: &str) -> WebSocketResult<()>
Start listening for incoming RPC connections on the addr
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 !RefUnwindSafe for RpcServer
impl Send for RpcServer
impl Sync for RpcServer
impl Unpin for RpcServer
impl !UnwindSafe for RpcServer
Blanket Implementations§
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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 + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
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.