[][src]Trait splinter::service::Service

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 handle_message(
        &self,
        message_bytes: &[u8],
        message_context: &ServiceMessageContext
    ) -> Result<(), ServiceError>;
fn as_any(&self) -> &dyn Any; }

A Service provides message handling for a given service type.

Required methods

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

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>

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>

Stops Starts the service

The service should unregister itself with the network.

fn destroy(self: Box<Self>) -> Result<(), ServiceDestroyError>

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

fn as_any(&self) -> &dyn Any

Cast the service as &dyn Any.

This allows for downcasting the Service to a specific implementation.

Loading content...

Implementors

impl Service for AdminService[src]

impl Service for Scabbard[src]

Loading content...