Skip to main content

KeyedWorkerPool

Struct KeyedWorkerPool 

Source
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>,

Source

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.

Source

pub fn affinity(&self, key: &K) -> Option<A::Nonce>

Return the stable slot currently bound to key.

Source

pub fn backlog_len(&self) -> usize

Source

pub fn worker_phase(&self, worker: A::Nonce) -> Option<WorkerPhase>

Trait Implementations§

Source§

impl<A, K, J, R, C, S> Behavior for KeyedWorkerPool<A, K, J, R, C, S>
where A: Address, A::Nonce: From<u64>, K: Eq, J: Clone, C: Behavior<Addr = A, Msg = PoolAssignment<J>, Ph = Never>, S: AffinitySelector<K, A::Nonce>,

Source§

type Addr = A

Source§

type Msg = KeyedPoolMessage<A, K, J, R>

Source§

type Event = SupervisionEvent<User<A, KeyedPoolMessage<A, K, J, R>>>

Source§

type Sends = SupervisorSends<A, PoolBehaviorSends<A, J, R, C>, C>

Source§

type Ph = Never

Source§

type Error = PoolError<<A as Address>::Nonce>

Source§

type Birth = Births<Proxy<C>>

Source§

fn init(&mut self) -> BehaviorActed<Self>

Produce initialization actions before the first event is accepted. Read more
Source§

fn transition(&mut self, event: Self::Event) -> BehaviorActed<Self>

Fold exactly one event into explicit actions and the next behavior. Read more
Source§

fn receive( &mut self, from: Self::Addr, message: Self::Msg, ) -> BehaviorActed<Self>
where Self: Sized,

Fold one user communication through the composed protocol. Read more
Source§

fn on<Input>(&mut self, input: Input) -> BehaviorActed<Self>
where Self: Sized, Self::Event: EventInput<Input>,

Inject one supported semantic input and fold it through this behavior. Read more

Auto Trait Implementations§

§

impl<A, K, J, R, C, S> Freeze for KeyedWorkerPool<A, K, J, R, C, S>
where S: Freeze,

§

impl<A, K, J, R, C, S> RefUnwindSafe for KeyedWorkerPool<A, K, J, R, C, S>

§

impl<A, K, J, R, C, S> Send for KeyedWorkerPool<A, K, J, R, C, S>
where S: Send, K: Send, <A as Address>::Nonce: Send, J: Send, A: Send,

§

impl<A, K, J, R, C, S> Sync for KeyedWorkerPool<A, K, J, R, C, S>
where S: Sync, K: Sync, <A as Address>::Nonce: Sync, J: Sync, A: Sync,

§

impl<A, K, J, R, C, S> Unpin for KeyedWorkerPool<A, K, J, R, C, S>
where S: Unpin, K: Unpin, <A as Address>::Nonce: Unpin, J: Unpin, A: Unpin,

§

impl<A, K, J, R, C, S> UnsafeUnpin for KeyedWorkerPool<A, K, J, R, C, S>
where S: UnsafeUnpin,

§

impl<A, K, J, R, C, S> UnwindSafe for KeyedWorkerPool<A, K, J, R, C, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.