com.fasterxml.clustermate.client.NodesForKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clustermate-client Show documentation
Show all versions of clustermate-client Show documentation
Building blocks for client libraries that access
ClusterMate-based service.
package com.fasterxml.clustermate.client;
/**
* Container class for an ordered set of references to server nodes
* that should be contacted for accessing content for given
* key, based on key hash based matching.
*/
public class NodesForKey
{
private final static ClusterServerNode[] NO_NODES = new ClusterServerNode[0];
private final int _version;
private final ClusterServerNode[] _nodes;
/*
/**********************************************************************
/* Construction
/**********************************************************************
*/
public NodesForKey(int version, ClusterServerNode[] nodes)
{
_version = version;
_nodes = nodes;
}
public static NodesForKey empty(int version) {
return new NodesForKey(version, NO_NODES);
}
/*
/**********************************************************************
/* Accessors
/**********************************************************************
*/
public int version() { return _version; }
public int size() { return _nodes.length; }
public ClusterServerNode node(int index) {
return _nodes[index];
}
/*
/**********************************************************************
/* Overrides
/**********************************************************************
*/
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("[Nodes (").append(_nodes.length).append(") ");
for (int i = 0, end = _nodes.length; i < end; ++i) {
if (i > 0) {
sb.append(", ");
}
ClusterServerNode node = _nodes[i];
sb.append(node.getAddress()).append(": ranges=");
sb.append(node.getActiveRange()).append('/').append(node.getPassiveRange());
}
sb.append(")");
return sb.toString();
}
}