Skip to main content

NodeStateMachine

Struct NodeStateMachine 

Source
pub struct NodeStateMachine { /* private fields */ }
Expand description

Manages state transitions for a replication node.

encapsulates the current replicator state, validates transitions, and tracks timing.

All methods are thread-safe. The state machine enforces that only valid transitions are permitted according to the replication protocol.

Implementations§

Source§

impl NodeStateMachine

Source

pub fn new() -> Self

Create a new state machine starting in the Detached state.

Source

pub fn get_state(&self) -> NodeState

Get the current state.

Source

pub fn get_state_change_time(&self) -> Instant

Get the time at which the last state change occurred.

Source

pub fn get_transition_count(&self) -> u64

Get the total number of state transitions.

Source

pub fn transition_to(&self, new_state: NodeState) -> Result<NodeState>

Transition to a new state, validating the transition is legal.

Returns the previous state on success.

§Errors

Returns RepError::InvalidStateTransition if the transition from the current state to the new state is not permitted.

Source

pub fn can_transition_to(&self, new_state: NodeState) -> bool

Check if a transition to the given state is valid from the current state.

Source

pub fn time_in_state(&self) -> Duration

Get the time spent in the current state.

Trait Implementations§

Source§

impl Default for NodeStateMachine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V