@Test public void testLeaveIfNotLeader() throws Exception { ZookeeperLeaderElector firstElector = newZookeeperLeaderElector(); ZookeeperLeaderElector secondElector = newZookeeperLeaderElector(); assertThat(firstElector.join()).isTrue(); awaitLeaderActivation(); assertThat(firstElector.leaveIfNotLeader()).isFalse(); assertThat(secondElector.join()).isTrue(); assertThat(secondElector.leaveIfNotLeader()).isTrue(); }
@Override public boolean leaveIfNotLeader() { synchronized (leaderElectionProcessRef) { LeaderElectionProcess process = leaderElectionProcessRef.get(); if (process == null) { return false; } if (process.leaveIfNotLeader()) { leaderElectionProcessRef.set(null); return true; } } return false; }
ZookeeperLeaderElector implements LeaderElector { @Override public boolean leaveIfNotLeader() { synchronized (leaderElectionProcessRef) { LeaderElectionProcess process = leaderElectionProcessRef.get(); if (process == null) { return false; } if (process.leaveIfNotLeader()) { leaderElectionProcessRef.set(null); return true; } } return false; } }
ZookeeperLeaderElector implements LeaderElector { @Override public boolean leaveIfNotLeader() { synchronized (leaderElectionProcessRef) { LeaderElectionProcess process = leaderElectionProcessRef.get(); if (process == null) { return false; } if (process.leaveIfNotLeader()) { leaderElectionProcessRef.set(null); return true; } } return false; } @Inject  ZookeeperLeaderElector(LeaderActivator leaderActivator,
                                  CuratorService curatorService,
                                  ZookeeperPaths zookeeperPaths,
                                  MasterDescription masterDescription,
                                  TitusRuntime titusRuntime); }
ZookeeperLeaderElector implements LeaderElector { @Override public boolean leaveIfNotLeader() { synchronized (leaderElectionProcessRef) { LeaderElectionProcess process = leaderElectionProcessRef.get(); if (process == null) { return false; } if (process.leaveIfNotLeader()) { leaderElectionProcessRef.set(null); return true; } } return false; } @Inject  ZookeeperLeaderElector(LeaderActivator leaderActivator,
                                  CuratorService curatorService,
                                  ZookeeperPaths zookeeperPaths,
                                  MasterDescription masterDescription,
                                  TitusRuntime titusRuntime); @PreDestroy void shutdown(); @Override boolean join(); @Override boolean leaveIfNotLeader(); @Override Observable<MasterState> awaitElection(); }
ZookeeperLeaderElector implements LeaderElector { @Override public boolean leaveIfNotLeader() { synchronized (leaderElectionProcessRef) { LeaderElectionProcess process = leaderElectionProcessRef.get(); if (process == null) { return false; } if (process.leaveIfNotLeader()) { leaderElectionProcessRef.set(null); return true; } } return false; } @Inject  ZookeeperLeaderElector(LeaderActivator leaderActivator,
                                  CuratorService curatorService,
                                  ZookeeperPaths zookeeperPaths,
                                  MasterDescription masterDescription,
                                  TitusRuntime titusRuntime); @PreDestroy void shutdown(); @Override boolean join(); @Override boolean leaveIfNotLeader(); @Override Observable<MasterState> awaitElection();  }