private Consumer<Transition<State>> dieOnError(final Consumer<Transition<State>> closure) { return transition -> { try { closure.accept(transition); } catch (RuntimeException e) { LOG.error("Caught unchecked exception: " + e, e); stateMachine.transition(State.DEAD); throw e; } }; }
@Override public void onDefeated() { LOG.error("Lost leadership, committing suicide."); stateMachine.transition(State.DEAD); }
@Override public void onLeading(LeaderControl control) { leaderControl.set(control); stateMachine.transition(State.LEADER_AWAITING_REGISTRATION); }
@Subscribe public void registered(DriverRegistered event) { stateMachine.transition(State.ACTIVE); }
/** * Prepares a scheduler to offer itself as a leader candidate. After this call the scheduler will * host a live log replica and start syncing data from the leader via the log until it gets called * upon to lead. * * @return A listener that can be offered for leadership of a distributed election. */ public LeadershipListener prepare() { stateMachine.transition(State.PREPARING_STORAGE); return leadershipListener; }