use of co.cask.cdap.common.zookeeper.coordination.ResourceCoordinator in project cdap by caskdata.
the class DistributedStreamService method performLeaderElection.
/**
* Elect one leader among the {@link DistributedStreamService}s running in different Twill runnables.
*/
private void performLeaderElection() {
// Start the resource coordinator that will map Streams to Stream handlers
leaderElection = new LeaderElection(// TODO: Should unify this leader election with DistributedStreamFileJanitorService
zkClient, "/election/" + STREAMS_COORDINATOR, new ElectionHandler() {
@Override
public void leader() {
LOG.info("Became Stream handler leader. Starting resource coordinator.");
resourceCoordinator = new ResourceCoordinator(getCoordinatorZKClient(), discoveryServiceClient, new BalancedAssignmentStrategy());
resourceCoordinator.startAndWait();
updateRequirement();
}
@Override
public void follower() {
LOG.info("Became Stream handler follower.");
if (resourceCoordinator != null) {
resourceCoordinator.stopAndWait();
}
}
});
leaderElection.start();
}
Aggregations