pub struct KeyedWorkerPool<A: Address, K, J, R, C, S>where
K: Eq,
C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>,
S: AffinitySelector<K, A::Nonce>,{ /* private fields */ }Expand description
A worker pool whose admitted keys remain bound to stable worker slots.
The selector chooses a stable proxy nonce only when a key is first
admitted. Replacement incarnations remain behind that proxy, so they do
not alter affinity. KeyedPoolMessage::Rebalance is the sole transition
that changes an established binding, and jobs accepted before it retain
their original target.
Keys must have a concrete equality relation; a key type without Eq cannot
form an affinity table:
use behavior::{Actions, Delivery, KeyedWorkerPool, MailAddr, Never, NoBirths};
struct NonKey(f64);
struct Worker;
#[behavior::behavior(
addr = MailAddr,
message = behavior::PoolAssignment<u8>,
sends = Vec<Delivery<MailAddr, Never>>,
births = NoBirths,
error = Never,
)]
impl Worker {
fn init(&mut self) -> behavior::Acted<MailAddr, Never, Vec<Delivery<MailAddr, Never>>, NoBirths, Never> {
Ok(Actions::cont())
}
fn receive(&mut self, _: MailAddr, _: behavior::PoolAssignment<u8>) -> behavior::Acted<MailAddr, Never, Vec<Delivery<MailAddr, Never>>, NoBirths, Never> {
Ok(Actions::cont())
}
}
let _: Option<KeyedWorkerPool<MailAddr, NonKey, u8, (), Worker, fn(&NonKey) -> u64>> = None;Implementations§
Source§impl<A, K, J, R, C, S> KeyedWorkerPool<A, K, J, R, C, S>where
A: Address,
K: Eq,
C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>,
S: AffinitySelector<K, A::Nonce>,
impl<A, K, J, R, C, S> KeyedWorkerPool<A, K, J, R, C, S>where
A: Address,
K: Eq,
C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>,
S: AffinitySelector<K, A::Nonce>,
Sourcepub fn new(
nonces: fn(usize) -> A::Nonce,
count: usize,
build: fn(usize) -> C,
backlog_capacity: usize,
interruption: InterruptionPolicy,
restart_policy: RestartPolicy,
max_restarts: u32,
restart_window: Duration,
selector: S,
) -> Result<Self, PoolConfigError<A::Nonce>>
pub fn new( nonces: fn(usize) -> A::Nonce, count: usize, build: fn(usize) -> C, backlog_capacity: usize, interruption: InterruptionPolicy, restart_policy: RestartPolicy, max_restarts: u32, restart_window: Duration, selector: S, ) -> Result<Self, PoolConfigError<A::Nonce>>
Construct a key-persistent pool over the same fixed supervised slots as
WorkerPool. The selector is pure and is consulted once per
previously unseen key. It chooses behavior policy; runtime route
resolution remains outside this type.
§Errors
Returns PoolConfigError::NoWorkers for an empty topology or
PoolConfigError::DuplicateWorker for a repeated stable nonce.
Sourcepub fn affinity(&self, key: &K) -> Option<A::Nonce>
pub fn affinity(&self, key: &K) -> Option<A::Nonce>
Return the stable slot currently bound to key.