use of org.apache.curator.framework.recipes.leader.LeaderSelector in project BRFS by zhangnianli.
the class CuratorLeaderSelectorClient method removeAllSelector.
/**
* 概述:移除path下的所有leader监听器
* @param path 监听的path
* @user <a href=mailto:weizheng@bonree.com>魏征</a>
*/
public void removeAllSelector(String path) {
List<LeaderSelector> leaderSelectors = selectorMap.get(path);
if (leaderSelectors != null) {
for (LeaderSelector selector : leaderSelectors) {
selector.close();
}
leaderSelectors.clear();
selectorMap.remove(path);
}
}
use of org.apache.curator.framework.recipes.leader.LeaderSelector in project BRFS by zhangnianli.
the class CuratorLeaderSelectorClient method removeSelectorById.
/**
* 概述:不能跨client移除,只能移除本client中的selector
* @param path
* @param id
* @user <a href=mailto:weizheng@bonree.com>魏征</a>
*/
public void removeSelectorById(String path, String id) {
List<LeaderSelector> leaderSelectors = selectorMap.get(path);
if (leaderSelectors != null) {
Iterator<LeaderSelector> it = leaderSelectors.iterator();
while (it.hasNext()) {
LeaderSelector selector = it.next();
if (StringUtils.equals(selector.getId(), id)) {
selector.close();
it.remove();
}
}
if (leaderSelectors.size() == 0) {
selectorMap.remove(path);
}
}
}
use of org.apache.curator.framework.recipes.leader.LeaderSelector in project nifi by apache.
the class CuratorLeaderElectionManager method unregister.
@Override
public synchronized void unregister(final String roleName) {
registeredRoles.remove(roleName);
final LeaderRole leaderRole = leaderRoles.remove(roleName);
if (leaderRole == null) {
logger.info("Cannot unregister Leader Election Role '{}' becuase that role is not registered", roleName);
return;
}
final LeaderSelector leaderSelector = leaderRole.getLeaderSelector();
if (leaderSelector == null) {
logger.info("Cannot unregister Leader Election Role '{}' becuase that role is not registered", roleName);
return;
}
leaderSelector.close();
logger.info("This node is no longer registered to be elected as the Leader for Role '{}'", roleName);
}
use of org.apache.curator.framework.recipes.leader.LeaderSelector in project nifi by apache.
the class CuratorLeaderElectionManager method stop.
@Override
public synchronized void stop() {
stopped = true;
for (final Map.Entry<String, LeaderRole> entry : leaderRoles.entrySet()) {
final LeaderRole role = entry.getValue();
final LeaderSelector selector = role.getLeaderSelector();
try {
selector.close();
} catch (final Exception e) {
logger.warn("Failed to close Leader Selector for {}", entry.getKey(), e);
}
}
leaderRoles.clear();
if (curatorClient != null) {
curatorClient.close();
curatorClient = null;
}
logger.info("{} stopped and closed", this);
}
use of org.apache.curator.framework.recipes.leader.LeaderSelector in project coprhd-controller by CoprHD.
the class BackupScheduler method startLeaderSelector.
/**
* Called when initializing Spring bean, make sure only one node(leader node) performs backup job
*/
public void startLeaderSelector() throws InterruptedException {
while (!coordinator.getCoordinatorClient().isConnected()) {
log.info("waiting for connecting to zookeeper");
try {
Thread.sleep(BackupConstants.BACKUP_WAINT_BEFORE_RETRY_ZK_CONN);
} catch (InterruptedException e) {
log.warn("Exception while sleeping,ignore", e);
throw e;
}
}
singletonInstance = this;
if (drUtil.isStandby()) {
log.info("Current site is standby, disable BackupScheduler");
return;
}
this.cfg = new SchedulerConfig(coordinator, this.encryptionProvider, this.dbClient);
LeaderSelector leaderSelector = coordinator.getCoordinatorClient().getLeaderSelector(coordinator.getCoordinatorClient().getSiteId(), BackupConstants.BACKUP_LEADER_PATH, new BackupLeaderSelectorListener());
leaderSelector.autoRequeue();
leaderSelector.start();
}
Aggregations