@Override public void start() throws Exception { mJournalSystem.start(); try { mLeaderSelector.start(getRpcAddress()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } startMasters(false); LOG.info("Secondary started"); while (!Thread.interrupted()) { mLeaderSelector.waitForState(State.PRIMARY); if (gainPrimacy()) { mLeaderSelector.waitForState(State.SECONDARY); losePrimacy(); } } }
@Override public void stop() throws Exception { super.stop(); if (mLeaderSelector != null) { mLeaderSelector.stop(); } }
try (Scoped scoped = mLeaderSelector.onStateChange(state -> unstable.set(true))) { if (mLeaderSelector.getState() != State.PRIMARY) { unstable.set(true);
try (Scoped scoped = mLeaderSelector.onStateChange(state -> unstable.set(true))) { if (mLeaderSelector.getState() != State.PRIMARY) { unstable.set(true);
mJournalSystem.start(); try { mLeaderSelector.start(getRpcAddress()); } catch (IOException e) { LOG.error(e.getMessage(), e); if (mServingThread == null) { mLeaderSelector.waitForState(State.PRIMARY); LOG.info("Transitioning from secondary to primary"); mJournalSystem.gainPrimacy(); } else { mLeaderSelector.waitForState(State.SECONDARY); LOG.info("Transitioning from primary to secondary"); stopServing();
@Override public void stop() throws Exception { super.stop(); if (mLeaderSelector != null) { mLeaderSelector.stop(); } }
@Override public void start() throws Exception { mJournalSystem.start(); try { mLeaderSelector.start(getRpcAddress()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } startMasters(false); LOG.info("Secondary started"); while (!Thread.interrupted()) { mLeaderSelector.waitForState(State.PRIMARY); if (gainPrimacy()) { mLeaderSelector.waitForState(State.SECONDARY); losePrimacy(); } } }
@Override public void stop() throws Exception { super.stop(); if (mLeaderSelector != null) { mLeaderSelector.stop(); } }