Struct batch_system::Router[][src]

pub struct Router<N: Fsm, C: Fsm, Ns, Cs> {
    normals: Arc<Mutex<NormalMailMap<N>>>,
    caches: Cell<LruCache<u64, BasicMailbox<N>>>,
    pub(crate) control_box: BasicMailbox<C>,
    pub(crate) normal_scheduler: Ns,
    control_scheduler: Cs,
    state_cnt: Arc<AtomicUsize>,
    shutdown: Arc<AtomicBool>,
}

Router route messages to its target mailbox.

Every fsm has a mailbox, hence it’s necessary to have an address book that can deliver messages to specified fsm, which is exact router.

In our abstract model, every batch system has two different kind of fsms. First is normal fsm, which does the common work like peers in a raftstore model or apply delegate in apply model. Second is control fsm, which does some work that requires a global view of resources or creates missing fsm for specified address. Normal fsm and control fsm can have different scheduler, but this is not required.

Fields

normals: Arc<Mutex<NormalMailMap<N>>>caches: Cell<LruCache<u64, BasicMailbox<N>>>control_box: BasicMailbox<C>normal_scheduler: Nscontrol_scheduler: Csstate_cnt: Arc<AtomicUsize>shutdown: Arc<AtomicBool>

Implementations

impl<N, C, Ns, Cs> Router<N, C, Ns, Cs> where
    N: Fsm,
    C: Fsm,
    Ns: FsmScheduler<Fsm = N> + Clone,
    Cs: FsmScheduler<Fsm = C> + Clone
[src]

pub(crate) fn new(
    control_box: BasicMailbox<C>,
    normal_scheduler: Ns,
    control_scheduler: Cs,
    state_cnt: Arc<AtomicUsize>
) -> Router<N, C, Ns, Cs>
[src]

pub fn is_shutdown(&self) -> bool[src]

The Router has been already shutdown or not.

fn check_do<F, R>(&self, addr: u64, f: F) -> CheckDoResult<R> where
    F: FnMut(&BasicMailbox<N>) -> Option<R>, 
[src]

A helper function that tries to unify a common access pattern to mailbox.

Generally, when sending a message to a mailbox, cache should be check first, if not found, lock should be acquired.

Returns None means there is no mailbox inside the normal registry. Some(None) means there is expected mailbox inside the normal registry but it returns None after apply the given function. Some(Some) means the given function returns Some and cache is updated if it’s invalid.

pub fn register(&self, addr: u64, mailbox: BasicMailbox<N>)[src]

Register a mailbox with given address.

pub fn register_all(&self, mailboxes: Vec<(u64, BasicMailbox<N>)>)[src]

pub fn mailbox(&self, addr: u64) -> Option<Mailbox<N, Ns>>[src]

Get the mailbox of specified address.

pub fn control_mailbox(&self) -> Mailbox<C, Cs>[src]

Get the mailbox of control fsm.

pub fn try_send(
    &self,
    addr: u64,
    msg: N::Message
) -> Either<Result<(), TrySendError<N::Message>>, N::Message>
[src]

Try to send a message to specified address.

If Either::Left is returned, then the message is sent. Otherwise, it indicates mailbox is not found.

pub fn send(
    &self,
    addr: u64,
    msg: N::Message
) -> Result<(), TrySendError<N::Message>>
[src]

Send the message to specified address.

pub fn force_send(
    &self,
    addr: u64,
    msg: N::Message
) -> Result<(), SendError<N::Message>>
[src]

Force sending message to specified address despite the capacity limit of mailbox.

pub fn send_control(
    &self,
    msg: C::Message
) -> Result<(), TrySendError<C::Message>>
[src]

Force sending message to control fsm.

pub fn broadcast_normal(&self, msg_gen: impl FnMut() -> N::Message)[src]

Try to notify all normal fsm a message.

pub fn broadcast_shutdown(&self)[src]

Try to notify all fsm that the cluster is being shutdown.

pub fn close(&self, addr: u64)[src]

Close the mailbox of address.

pub fn clear_cache(&self)[src]

pub fn state_cnt(&self) -> &Arc<AtomicUsize>[src]

pub fn alive_cnt(&self) -> Arc<AtomicUsize>[src]

pub fn trace(&self) -> RouterTrace[src]

Trait Implementations

impl<N: Fsm, C: Fsm, Ns: Clone, Cs: Clone> Clone for Router<N, C, Ns, Cs>[src]

Auto Trait Implementations

impl<N, C, Ns, Cs> !RefUnwindSafe for Router<N, C, Ns, Cs>

impl<N, C, Ns, Cs> Send for Router<N, C, Ns, Cs> where
    Cs: Send,
    Ns: Send

impl<N, C, Ns, Cs> !Sync for Router<N, C, Ns, Cs>

impl<N, C, Ns, Cs> Unpin for Router<N, C, Ns, Cs> where
    Cs: Unpin,
    Ns: Unpin

impl<N, C, Ns, Cs> UnwindSafe for Router<N, C, Ns, Cs> where
    Cs: UnwindSafe,
    Ns: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T> Sealed<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]