Skip to main content

Router

Trait Router 

Source
pub trait Router<TKey, TMsg>: State
where TKey: JobKey, TMsg: Message,
{ // 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§

Source

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 routed
  • pool_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.

Source

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 routed
  • pool_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

Source

fn is_factory_queueing(&self) -> bool

Returns a flag indicating if the factory does discard/overload management (true) or if is handled by the workers worker(s) (false)

Implementors§

Source§

impl<TKey, TMsg> Router<TKey, TMsg> for KeyPersistentRouting<TKey, TMsg>
where TKey: JobKey, TMsg: Message,

Source§

impl<TKey, TMsg> Router<TKey, TMsg> for QueuerRouting<TKey, TMsg>
where TKey: JobKey, TMsg: Message,

Source§

impl<TKey, TMsg> Router<TKey, TMsg> for RoundRobinRouting<TKey, TMsg>
where TKey: JobKey, TMsg: Message,

Source§

impl<TKey, TMsg> Router<TKey, TMsg> for StickyQueuerRouting<TKey, TMsg>
where TKey: JobKey, TMsg: Message,

Source§

impl<TKey, TMsg, THasher> Router<TKey, TMsg> for CustomRouting<TKey, TMsg, THasher>
where TKey: JobKey, TMsg: Message, THasher: CustomHashFunction<TKey> + 'static,

Source§

impl<TKey, TMsg, TRouter, TRateLimit> Router<TKey, TMsg> for RateLimitedRouter<TRouter, TRateLimit>
where TKey: JobKey, TMsg: Message, TRouter: Router<TKey, TMsg>, TRateLimit: RateLimiter,