Struct messaging_thread_pool::samples::RandomsBatch
source · pub struct RandomsBatch {
pub id: usize,
pub contained_random_ids: Vec<usize>,
pub id_provider: SizedIdProvider,
pub randoms_thread_pool: Arc<ThreadPool<Randoms>>,
}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: SizedIdProvider§randoms_thread_pool: Arc<ThreadPool<Randoms>>Implementations§
source§impl RandomsBatch
impl RandomsBatch
pub fn new(add_request: RandomsBatchAddRequest) -> Self
pub fn randoms_thread_pool(&self) -> &ThreadPool<Randoms>
pub fn sum_of_sums(&self) -> u128
pub fn contained_random_ids_mut(&mut self) -> &mut Vec<usize>
Trait Implementations§
source§impl Debug for RandomsBatch
impl Debug for RandomsBatch
source§impl PoolItem for RandomsBatch
impl PoolItem for RandomsBatch
§type Init = RandomsBatchAddRequest
type Init = RandomsBatchAddRequest
This is a struct that defines the message that will initiate a new instance
of the struct within the thread pool Read more
§type Api = RandomsBatchApi
type Api = RandomsBatchApi
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 Read more
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 Read more
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 Read more
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 Read more
source§fn 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 Read more
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 Read more