pub trait Service: Send {
fn service_id(&self) -> &str;
fn service_type(&self) -> &str;
fn start(
&mut self,
service_registry: &dyn ServiceNetworkRegistry
) -> Result<(), ServiceStartError>;
fn stop(
&mut self,
service_registry: &dyn ServiceNetworkRegistry
) -> Result<(), ServiceStopError>;
fn destroy(self: Box<Self>) -> Result<(), ServiceDestroyError>;
fn purge(&mut self) -> Result<(), InternalError>;
fn handle_message(
&self,
message_bytes: &[u8],
message_context: &ServiceMessageContext
) -> Result<(), ServiceError>;
fn as_any(&self) -> &dyn Any;
}
Expand description
A Service provides message handling for a given service type.
Required Methods
fn service_id(&self) -> &str
fn service_id(&self) -> &str
This service’s ID
This ID must be unique within the context of a circuit, but not necessarily unique within the context of a splinter node, as a whole.
fn service_type(&self) -> &str
fn service_type(&self) -> &str
This service’s type
A service type broadly identifies the kinds of messages that this service handles or emits.
fn start(
&mut self,
service_registry: &dyn ServiceNetworkRegistry
) -> Result<(), ServiceStartError>
fn start(
&mut self,
service_registry: &dyn ServiceNetworkRegistry
) -> Result<(), ServiceStartError>
Starts the service
At start time, the service should register itself with the network when its ready to receive messages.
fn stop(
&mut self,
service_registry: &dyn ServiceNetworkRegistry
) -> Result<(), ServiceStopError>
fn stop(
&mut self,
service_registry: &dyn ServiceNetworkRegistry
) -> Result<(), ServiceStopError>
Stops Starts the service
The service should unregister itself with the network.
Clean-up any resources before the service is removed. Consumes the service (which, given the use of dyn traits, this must take a boxed Service instance).
fn purge(&mut self) -> Result<(), InternalError>
fn purge(&mut self) -> Result<(), InternalError>
Purge any persistent state maintained by this service.
fn handle_message(
&self,
message_bytes: &[u8],
message_context: &ServiceMessageContext
) -> Result<(), ServiceError>
fn handle_message(
&self,
message_bytes: &[u8],
message_context: &ServiceMessageContext
) -> Result<(), ServiceError>
Handle any incoming message intended for this service instance.
Messages recevied by this service are provided in raw bytes. The format of the service