/** * Acquire the leadership * @param id identify of the current participant * @param leaderPath the leader node path * @param listener the leader listener * @return the leadership */ public Leader acquireLeader(String id, String leaderPath, LeaderListener listener){ return new Leader(client, id, leaderPath, listener); }
/** * Get the current leader host * @return the current leader host */ public String getLeader(){ return leader.getLeader(); }
/** * Is the leader or not * @return return true if I'm the leader, or false */ public Boolean isLeader(){ return leader.isLeader(); }
@Override public void doShutdown() { clientFailover.shutdown(); serverFailover.shutdown(); zkCleaner.shutdown(); leader.release(); if (scheduler != null){ scheduler.shutdown(); } }
@Override public void run() { if (!Objects.equal(host.get(), getLeader())){ Logs.warn("The server({}) isn't the leader, maybe disconnect unexpectedly.", host.get()); // shutdown the client failover clientFailover.shutdown(); // shutdown the zk cleaner zkCleaner.shutdown(); // require the leader leader.reaquireLeader(); // shutdown the scheduler scheduler.shutdown(); } } }