Trait messaging_thread_pool::PoolItem
source · pub trait PoolItem: Debugwhere
Self: Sized,
Self::Init: Send + IdTargeted + RequestWithResponse<Self, Response = AddResponse>,
Self::Api: Debug + Send + IdTargeted,{
type Init;
type Api;
// Required methods
fn process_message(
&mut self,
request: Self::Api
) -> ThreadRequestResponse<Self>;
fn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>;
// Provided methods
fn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self> { ... }
fn name(&self) -> &str { ... }
fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse> { ... }
fn add_element_request_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)> { ... }
fn add_pool_thread_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)> { ... }
}Expand description
This is the trait that needs to be implemented by a struct in order that it can be managed by the thread pool infrastructure
Required Associated Types§
Required Methods§
sourcefn process_message(&mut self, request: Self::Api) -> ThreadRequestResponse<Self>
fn process_message(&mut self, request: Self::Api) -> ThreadRequestResponse<Self>
This is the function that will define how the struct processes the messages that it receives. It will typically consist of a match statement that will discriminate amongst the various messages type defined in the Api
sourcefn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>
fn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>
This function defines how a new struct will be created when it receives The Init message. It returns the created new instance of the struct
Provided Methods§
sourcefn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self>
fn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self>
The function called if an item with the specified is not found The default behaviour is to panic
sourcefn shutdown_pool(&self) -> Vec<ThreadShutdownResponse>
fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse>
This function is a hook that is called when the pool is shutting down.
sourcefn add_element_request_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
fn add_element_request_tracing( id: usize ) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
This method is called to optionally add tracing before each message is processed. The tracing is removed once the message is processed. If the tracing is being written to a file it is important that the file is not truncated
sourcefn add_pool_thread_tracing(
id: usize
) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
fn add_pool_thread_tracing( id: usize ) -> Option<(DefaultGuard, Vec<WorkerGuard>)>
This method provides any required tracing in the pool items thread pool threads This tracing is added when the thread is spawned and remains in place until the thread dies
Implementors§
source§impl PoolItem for Randoms
impl PoolItem for Randoms
The implementation of this trait allows the Randoms struct to be used in the thread pool infrastructure