Struct batch_system::Router [−][src]
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: Ns
control_scheduler: Cs
state_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]
N: Fsm,
C: Fsm,
Ns: FsmScheduler<Fsm = N> + Clone,
Cs: FsmScheduler<Fsm = C> + Clone,
pub(crate) fn new(
control_box: BasicMailbox<C>,
normal_scheduler: Ns,
control_scheduler: Cs,
state_cnt: Arc<AtomicUsize>
) -> Router<N, C, Ns, Cs>
[src]
control_box: BasicMailbox<C>,
normal_scheduler: Ns,
control_scheduler: Cs,
state_cnt: Arc<AtomicUsize>
) -> Router<N, C, Ns, Cs>
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]
F: FnMut(&BasicMailbox<N>) -> Option<R>,
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]
&self,
addr: u64,
msg: N::Message
) -> Either<Result<(), TrySendError<N::Message>>, N::Message>
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]
&self,
addr: u64,
msg: N::Message
) -> Result<(), TrySendError<N::Message>>
Send the message to specified address.
pub fn force_send(
&self,
addr: u64,
msg: N::Message
) -> Result<(), SendError<N::Message>>
[src]
&self,
addr: u64,
msg: N::Message
) -> Result<(), SendError<N::Message>>
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]
&self,
msg: C::Message
) -> Result<(), TrySendError<C::Message>>
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
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,
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,
Cs: Unpin,
Ns: Unpin,
impl<N, C, Ns, Cs> UnwindSafe for Router<N, C, Ns, Cs> where
Cs: UnwindSafe,
Ns: UnwindSafe,
Cs: UnwindSafe,
Ns: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> Sealed<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,