org.apache.curator.framework.recipes.locks.LockInternals Java Examples

The following examples show how to use org.apache.curator.framework.recipes.locks.LockInternals. 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: ClusterStateHolder.java    From hermes with Apache License 2.0 6 votes vote down vote up
private void updateLeaderInfo() {
	List<ChildData> children = m_leaderLatchPathChildrenCache.getCurrentData();

	if (children != null && !children.isEmpty()) {
		List<String> childrenNames = new ArrayList<>(children.size());
		Map<String, byte[]> nameDataMapping = new HashMap<>(children.size());
		for (ChildData child : children) {
			if (child.getData() != null && child.getData().length > 0) {
				String name = ZKPathUtils.lastSegment(child.getPath());
				childrenNames.add(name);
				nameDataMapping.put(name, child.getData());
			}
		}

		List<String> sortedChildren = LockInternals.getSortedChildren("latch-", new LockInternalsSorter() {

			@Override
			public String fixForSorting(String str, String lockName) {
				return StandardLockInternalsDriver.standardFixForSorting(str, lockName);
			}
		}, childrenNames);

		m_leader.set(ZKSerializeUtils.deserialize(nameDataMapping.get(sortedChildren.get(0)), HostPort.class));
	}
}
 
Example #2
Source File: AbstractLeaderElector.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Override
public List<String> getAllServers() {

    String leaderElectPath = getLeaderElectPath();
    CuratorFramework curatorFramework = zkClient.get();
    List<String> children = null;
    List<String> result = new LinkedList<>();
    try {
        children = curatorFramework.getChildren().forPath(leaderElectPath);
        children = LockInternals.getSortedChildren("latch-", sorter, children);

        for (String child : children) {
            String currentPath = leaderElectPath + "/" + child;
            result.add(new String(curatorFramework.getData().forPath(currentPath)));
        }
    } catch (Exception e) {
        logger.error("[getAllServers]", e);
    }
    return result;
}
 
Example #3
Source File: LeaderLatch.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * Returns the set of current participants in the leader selection
 * </p>
 * <p>
 * <p>
 * <B>NOTE</B> - this method polls the ZK server. Therefore it can possibly
 * return a value that does not match {@link #hasLeadership()} as hasLeadership
 * uses a local field of the class.
 * </p>
 *
 * @return participants
 * @throws Exception ZK errors, interruptions, etc.
 */
public Collection<Participant> getParticipants() throws Exception
{
    Collection<String> participantNodes = LockInternals.getParticipantNodes(client, latchPath, LOCK_NAME, sorter);
    return LeaderSelector.getParticipants(client, participantNodes);
}
 
Example #4
Source File: LeaderLatch.java    From xian with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * Return the id for the current leader. If for some reason there is no
 * current leader, a dummy participant is returned.
 * </p>
 * <p>
 * <p>
 * <B>NOTE</B> - this method polls the ZK server. Therefore it can possibly
 * return a value that does not match {@link #hasLeadership()} as hasLeadership
 * uses a local field of the class.
 * </p>
 *
 * @return leader
 * @throws Exception ZK errors, interruptions, etc.
 */
public Participant getLeader() throws Exception
{
    Collection<String> participantNodes = LockInternals.getParticipantNodes(client, latchPath, LOCK_NAME, sorter);
    return LeaderSelector.getLeader(client, participantNodes);
}
 
Example #5
Source File: LeaderLatch.java    From curator with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * Returns the set of current participants in the leader selection
 * </p>
 * <p>
 * <p>
 * <B>NOTE</B> - this method polls the ZK server. Therefore it can possibly
 * return a value that does not match {@link #hasLeadership()} as hasLeadership
 * uses a local field of the class.
 * </p>
 *
 * @return participants
 * @throws Exception ZK errors, interruptions, etc.
 */
public Collection<Participant> getParticipants() throws Exception
{
    Collection<String> participantNodes = LockInternals.getParticipantNodes(client, latchPath, LOCK_NAME, sorter);
    return LeaderSelector.getParticipants(client, participantNodes);
}
 
Example #6
Source File: LeaderLatch.java    From curator with Apache License 2.0 2 votes vote down vote up
/**
 * <p>
 * Return the id for the current leader. If for some reason there is no
 * current leader, a dummy participant is returned.
 * </p>
 * <p>
 * <p>
 * <B>NOTE</B> - this method polls the ZK server. Therefore it can possibly
 * return a value that does not match {@link #hasLeadership()} as hasLeadership
 * uses a local field of the class.
 * </p>
 *
 * @return leader
 * @throws Exception ZK errors, interruptions, etc.
 */
public Participant getLeader() throws Exception
{
    Collection<String> participantNodes = LockInternals.getParticipantNodes(client, latchPath, LOCK_NAME, sorter);
    return LeaderSelector.getLeader(client, participantNodes);
}