private void handleTimeouts( RaftMessages.ReceivedInstantClusterIdAwareMessage<?> message ) { if ( message.dispatch( shouldRenewElectionTimeout ) ) { leaderAvailabilityTimers.renewElection(); } }
/** * This should be called after the major recovery operations are complete. Before this is called * this instance cannot become a leader (the timers are disabled) and entries will not be cached * in the in-flight map, because the application process is not running and ready to consume them. */ public synchronized void postRecoveryActions() { leaderAvailabilityTimers.start( this::electionTimeout, clock -> handle( RaftMessages.ReceivedInstantAwareMessage.of( clock.instant(), new RaftMessages.Timeout.Heartbeat( myself ) ) ) ); inFlightCache.enable(); }
public boolean isLeader() { return consensusModule.raftMachine().currentRole() == Role.LEADER; }
private synchronized void electionTimeout( Clock clock ) throws IOException { if ( leaderAvailabilityTimers.isElectionTimedOut() ) { triggerElection( clock ); } }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }
public Factory( ChannelInboundHandler raftMessageHandler, NettyPipelineBuilderFactory pipelineBuilderFactory, LogProvider logProvider ) { super( APPLICATION_PROTOCOL, modifiers -> new RaftProtocolServerInstaller( raftMessageHandler, pipelineBuilderFactory, modifiers, logProvider ) ); } }
static <RM extends RaftMessage> ReceivedInstantAwareMessage<RM> of( Instant receivedAt, RM message ) { return new ReceivedInstantAwareMessageImpl<>( receivedAt, message ); } }
public Factory( NettyPipelineBuilderFactory clientPipelineBuilderFactory, LogProvider logProvider ) { super( APPLICATION_PROTOCOL, modifiers -> new RaftProtocolClientInstaller( clientPipelineBuilderFactory, modifiers, logProvider ) ); } }
private void notifyLeaderChanges( Outcome outcome ) { for ( LeaderListener listener : leaderListeners ) { listener.onLeaderEvent( outcome ); } }
/** * Produces a new LeaderInfo object for a step down event, setting memberId to null but maintaining the current term. */ public LeaderInfo stepDown() { return new LeaderInfo( null, this.term, true ); }
public LeaderAvailabilityHandler( LifecycleMessageHandler<RaftMessages.ReceivedInstantClusterIdAwareMessage<?>> delegateHandler, LeaderAvailabilityTimers leaderAvailabilityTimers, LongSupplier term ) { this.delegateHandler = delegateHandler; this.leaderAvailabilityTimers = leaderAvailabilityTimers; this.shouldRenewElectionTimeout = new ShouldRenewElectionTimeout( term ); }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }
@Override public <T,E extends Exception> T dispatch( Handler<T,E> handler ) throws E { return handler.handle( this ); }