pub struct Raft<T>where
T: TypeConfig,{
pub node_id: u32,
pub role: RaftRole<T>,
pub ctx: RaftContext<T>,
/* private fields */
}Fields§
§node_id: u32§role: RaftRole<T>§ctx: RaftContext<T>Implementations§
Source§impl<T> Raft<T>where
T: TypeConfig,
impl<T> Raft<T>where
T: TypeConfig,
pub fn new( node_id: u32, role: RaftRole<T>, storage: RaftStorageHandles<T>, transport: <T as TypeConfig>::TR, handlers: RaftCoreHandlers<T>, membership: Arc<<T as TypeConfig>::M>, signal_params: SignalParams, node_config: Arc<RaftNodeConfig>, ) -> Raft<T>
Sourcepub fn register_leader_change_listener(
&mut self,
tx: Sender<Option<LeaderInfo>>,
)
pub fn register_leader_change_listener( &mut self, tx: Sender<Option<LeaderInfo>>, )
Register a listener for leader election events.
The listener will receive LeaderInfo updates:
- Some(LeaderInfo) when a leader is elected
- None when no leader exists (during election)
§Performance
Event-driven notification (no polling), multi-subscriber support via watch channel
pub async fn join_cluster(&self) -> Result<(), Error>
pub async fn run(&mut self) -> Result<(), Error>
Sourcepub async fn handle_role_event(
&mut self,
role_event: RoleEvent,
) -> Result<(), Error>
pub async fn handle_role_event( &mut self, role_event: RoleEvent, ) -> Result<(), Error>
handle_role_event will be responsbile to process role trasnsition and
role state events.
pub fn register_new_commit_listener( &mut self, tx: UnboundedSender<NewCommitData>, )
pub fn notify_new_commit(&self, new_commit_data: NewCommitData)
Sourcepub fn event_sender(&self) -> Sender<RaftEvent>
pub fn event_sender(&self) -> Sender<RaftEvent>
Returns a cloned event sender for external use.
This provides controlled access to send validated RaftEvents to the Raft core. Events sent through this sender are still processed through the normal validation pipeline in the main event loop.
§Security Note
While this provides access to the event channel, all events are still validated
by the Raft state machine before being applied. The event handler in handle_raft_event
performs necessary checks based on current term, role, and state.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Raft<T>
impl<T> !RefUnwindSafe for Raft<T>
impl<T> Send for Raft<T>
impl<T> Sync for Raft<T>
impl<T> Unpin for Raft<T>
impl<T> !UnwindSafe for Raft<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request