in twill-zookeeper/src/main/java/org/apache/twill/internal/zookeeper/LeaderElection.java [99:134]
protected void doStop() {
final SettableFuture<String> completion = SettableFuture.create();
Futures.addCallback(completion, new FutureCallback<String>() {
@Override
public void onSuccess(String result) {
try {
notifyStopped();
} finally {
executor.shutdown();
}
}
@Override
public void onFailure(Throwable t) {
try {
notifyFailed(t);
} finally {
executor.shutdown();
}
}
}, Threads.SAME_THREAD_EXECUTOR);
executor.execute(new Runnable() {
@Override
public void run() {
if (state != State.CANCELLED) {
// becomeFollower has to be called before deleting node to make sure no two active leader.
if (state == State.LEADER) {
becomeFollower();
}
state = State.CANCELLED;
doDeleteNode(completion);
}
}
});
}