Skip to main content

Election

Trait Election 

Source
pub trait Election: Send + Sync {
    type Leader;

    // Required methods
    fn is_leader(&self) -> bool;
    fn in_leader_infancy(&self) -> bool;
    fn register_candidate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        node_info: &'life1 MetasrvNodeInfo,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn all_candidates<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<MetasrvNodeInfo>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn campaign<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn leader<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Leader>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn resign<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn subscribe_leader_change(&self) -> Receiver<LeaderChangeMessage>;

    // Provided method
    fn reset_campaign<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}

Required Associated Types§

Required Methods§

Source

fn is_leader(&self) -> bool

Returns true if current node is the leader.

Source

fn in_leader_infancy(&self) -> bool

When a new leader is born, it may need some initialization operations (asynchronous), this method tells us when these initialization operations can be performed.

note: a new leader will only return true on the first call.

Source

fn register_candidate<'life0, 'life1, 'async_trait>( &'life0 self, node_info: &'life1 MetasrvNodeInfo, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Registers a candidate for the election.

Source

fn all_candidates<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<MetasrvNodeInfo>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets all candidates in the election.

Source

fn campaign<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Campaign waits to acquire leadership in an election.

Multiple sessions can participate in the election, but only one can be the leader at a time.

Source

fn leader<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Self::Leader>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the leader value for the current election.

Source

fn resign<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Releases election leadership so other campaigners may acquire leadership on the election.

Source

fn subscribe_leader_change(&self) -> Receiver<LeaderChangeMessage>

Provided Methods§

Source

fn reset_campaign<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Resets the campaign.

Reset the client and the leader flag if needed.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§