Java Code Examples for org.apache.curator.framework.recipes.leader.LeaderSelector#close()

The following examples show how to use org.apache.curator.framework.recipes.leader.LeaderSelector#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CuratorLeaderElectionManager.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: CuratorLeaderElectionManager.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source File: CuratorLeaderElectionManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: CuratorLeaderElectionManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 5
Source File: ZkLeaderElection.java    From xian with Apache License 2.0 5 votes vote down vote up
/**
 * 如果参与了选举,那么退出主节点选举
 *
 * @deprecated curator的选举算法有问题,在最后一个唯一节点,同时也是主节点退出选举时,它抛出java.lang.InterruptedException。
 * 所以请直接依赖zk断开连接的方式退出节点选举,而不是调用本方法来退出选举
 */
public static void stop() {
    synchronized (lock) {
        if (singleton == null) return;
        LeaderSelector leaderSelector = singleton.leaderSelector;
        if (leaderSelector == null) {
            return;
        }
        LOG.info("节点退出zk选举");
        leaderSelector.close();
        singleton = null;
        LOG.info("退出选举 完毕");
    }
}