Struct messaging_thread_pool::samples::RandomsBatch
source · pub struct RandomsBatch<P>where
P: SenderAndReceiver<Randoms>,{
pub id: usize,
pub contained_random_ids: Vec<usize>,
pub id_provider: Arc<dyn IdProvider>,
pub randoms_thread_pool: Arc<P>,
}Expand description
An example of an element that contains a child thread pool
RandomsBatches and Randoms form a hierarchy. A RandomsBatch contains many Randoms.
RandomsBatches are managed by a one thread pool and internally they have a collection of Randoms which are managed in a separate “child” thread pool In this example all of the Randoms share a single thread pool regardless of which RandomsBatch created them
For this reason the RandomsBatches need to share an id_provider which provides globally unique ids (ids, must be unique across the thread pool for obvious reasons)
Fields§
§id: usize§contained_random_ids: Vec<usize>§id_provider: Arc<dyn IdProvider>§randoms_thread_pool: Arc<P>Implementations§
source§impl<P> RandomsBatch<P>where
P: SenderAndReceiver<Randoms> + Send + Sync,
impl<P> RandomsBatch<P>where P: SenderAndReceiver<Randoms> + Send + Sync,
pub fn new(add_request: RandomsBatchAddRequest<P>) -> Self
pub fn randoms_thread_pool(&self) -> &P
pub fn sum_of_sums(&self) -> u128
pub fn contained_random_ids_mut(&mut self) -> &mut Vec<usize>
Trait Implementations§
source§impl<P> Debug for RandomsBatch<P>where
P: SenderAndReceiver<Randoms> + Debug,
impl<P> Debug for RandomsBatch<P>where P: SenderAndReceiver<Randoms> + Debug,
source§impl<P> PoolItem for RandomsBatch<P>where
P: SenderAndReceiver<Randoms> + Send + Sync + Debug,
impl<P> PoolItem for RandomsBatch<P>where P: SenderAndReceiver<Randoms> + Send + Sync + Debug,
§type Init = RandomsBatchAddRequest<P>
type Init = RandomsBatchAddRequest<P>
This is a struct that defines the message that will initiate a new instance
of the struct within the thread pool
§type Api = RandomsBatchApi<P>
type Api = RandomsBatchApi<P>
This is the enum that will define that messaging api that can be used to
communicate with instances of the struct
It will be an enum where each variant will define a request/response pair
of structs
source§fn 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
source§fn 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
source§fn 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.
source§fn 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
source§fn add_pool_item_tracing(&self) -> Option<Vec<Box<dyn GuardDrop>>>
fn add_pool_item_tracing(&self) -> Option<Vec<Box<dyn GuardDrop>>>
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
The implementation needs to return a vec of guards of any subscribers added.
source§fn 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
source§impl<P> RequestWithResponse<RandomsBatch<P>> for RandomsBatchAddRequest<P>where
P: SenderAndReceiver<Randoms> + Send + Sync + Debug,
impl<P> RequestWithResponse<RandomsBatch<P>> for RandomsBatchAddRequest<P>where P: SenderAndReceiver<Randoms> + Send + Sync + Debug,
type Response = AddResponse
source§impl<P> RequestWithResponse<RandomsBatch<P>> for SumOfSumsRequestwhere
P: SenderAndReceiver<Randoms> + Send + Debug + Sync,
impl<P> RequestWithResponse<RandomsBatch<P>> for SumOfSumsRequestwhere P: SenderAndReceiver<Randoms> + Send + Debug + Sync,
ties together the request with a response