Expand description
§Messaging thread pool
Messaging thread pool is a collection of traits and structs for setting up a simple fixed-sized thread pool which holds a collection of a given type.
Instances of the objects are identified by an id which is unique within the thread pool.
Objects are distributed across the thread pool based on their id and ownership of the object is held there.
Objects are communicated with via a user defined set of messages which effectively form an API. These messages are sent and received over crossbeam channels.
The objects need to implement a set of simple traits and define a set of request/response messages to allow the thread pool infrastructure to handle the objects and to route messages to them.
The lifetimes of the objects are easy to reason about, as is the behaviour of the thread pools themselves.
The original motivation was to provide support for a hierarchy of dependent, long-lived objects, that each required their own thread pools to avoid complex threading dependencies.
Re-exports§
pub use request_response::RequestResponse;pub use id_being_processed::*;pub use pool_item::*;pub use sender_couplet::*;pub use thread_request_response::*;
Modules§
- api_
specification - global_
test_ scope - id_
based_ writer - id_
being_ processed - id_
provider - pool_
item - request_
response - samples
- sender_
and_ receiver_ raw_ mock - sender_
couplet - thread_
request_ response
Macros§
- api_
specification - This macro generates an API enum and implements various generics and conversions for provided types.
Structs§
- IdBased
Blocking - This struct is used to encapsulate the functionality of the IdBasedBlocking struct
- Sender
AndReceiver Mock - This structure enables the mocking of a
crate::ThreadPool - Thread
Pool - This struct represents a pool of threads that can target a particular type of
resource (a resource being a struct that implements
PoolItem)
Constants§
Traits§
- IdTargeted
- This trait is implemented by requests that are targeted at a pool item with an id and by the corresponding responses coming back from said pool item. This trait is used internally by the thread pool to route requests to the appropriate thread in the thread pool.
- Request
With Response - This trait allows for the pairing of requests and responses.
- Sender
AndReceiver - This trait allows a consumer to use a trait instead of the concrete implementation of thread pool.
Unfortunately the send_and_receive are not a precise match for corresponding function in
crate::ThreadPoolitself. This is because of the limitation of the trait return types (it has to return a boxed iterator) - Thread
Safe Sender AndReceiver - This trait is useful when multiple levels are thread pools are used and each thread pool needs to be send and sync in order to be sent through the levels