pub trait Router<TKey, TMsg>: State{
// Required methods
fn route_message(
&mut self,
job: Job<TKey, TMsg>,
pool_size: usize,
worker_hint: Option<usize>,
worker_pool: &mut HashMap<usize, WorkerProperties<TKey, TMsg>>,
) -> Result<RouteResult<TKey, TMsg>, Box<dyn Error + Send + Sync>>;
fn choose_target_worker(
&mut self,
job: &Job<TKey, TMsg>,
pool_size: usize,
worker_hint: Option<usize>,
worker_pool: &HashMap<usize, WorkerProperties<TKey, TMsg>>,
) -> Option<usize>;
fn is_factory_queueing(&self) -> bool;
}Expand description
A routing mode controls how a request is routed from the factory to a designated worker
Required Methods§
Sourcefn route_message(
&mut self,
job: Job<TKey, TMsg>,
pool_size: usize,
worker_hint: Option<usize>,
worker_pool: &mut HashMap<usize, WorkerProperties<TKey, TMsg>>,
) -> Result<RouteResult<TKey, TMsg>, Box<dyn Error + Send + Sync>>
fn route_message( &mut self, job: Job<TKey, TMsg>, pool_size: usize, worker_hint: Option<usize>, worker_pool: &mut HashMap<usize, WorkerProperties<TKey, TMsg>>, ) -> Result<RouteResult<TKey, TMsg>, Box<dyn Error + Send + Sync>>
Route a Job based on the specific routing methodology
job- The job to be routedpool_size- The size of the ACTIVE worker pool (excluding draining workers)worker_hint- If provided, this is a “hint” at which worker should receive the job, if available.worker_pool- The current worker pool, which may contain draining workers
Returns RouteResult::Handled if the job was routed successfully, otherwise RouteResult::Backlog is returned indicating that the job should be enqueued in the factory’s internal queue.
Sourcefn choose_target_worker(
&mut self,
job: &Job<TKey, TMsg>,
pool_size: usize,
worker_hint: Option<usize>,
worker_pool: &HashMap<usize, WorkerProperties<TKey, TMsg>>,
) -> Option<usize>
fn choose_target_worker( &mut self, job: &Job<TKey, TMsg>, pool_size: usize, worker_hint: Option<usize>, worker_pool: &HashMap<usize, WorkerProperties<TKey, TMsg>>, ) -> Option<usize>
Identifies if a job CAN be routed, and to which worker, without requiring dequeueing the job
This prevents the need to support pushing jobs that have been dequeued, but no worker is available to accept the job, back into the front of the queue. And given the single-threaded nature of a Factory, this is safe to call outside of a locked context. It is assumed that if this returns [Some(WorkerId)], then the job is guaranteed to be routed, as internal state to the router may be updated.
job- A reference to the job to be routedpool_size- The size of the ACTIVE worker pool (excluding draining workers)worker_hint- If provided, this is a “hint” at which worker should receive the job, if available.worker_pool- The current worker pool, which may contain draining workers
Returns None if no worker can be identified or no worker is avaialble to accept the job, otherwise [Some(WorkerId)] indicating the target worker is returned