Package io.hekate.cluster
Interface ClusterTopology
-
- All Superinterfaces:
ClusterTopologySupport
,Iterable<ClusterNode>
- All Known Subinterfaces:
LoadBalancerContext
public interface ClusterTopology extends Iterable<ClusterNode>, ClusterTopologySupport
Immutable snapshot of the cluster topology.Nodes within the cluster topology are sorted based on the comparison rule of
ClusterNode.compareTo(ClusterNode)
method. This rule applies to the following methods:- See Also:
ClusterTopologySupport.topology()
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
contains(ClusterNode node)
Returnstrue
if this topology contains the specified node.boolean
contains(ClusterNodeId id)
Returnstrue
if this topology contains a node with the specified identifier.static ClusterTopology
empty()
Return an empty cluster topology.ClusterTopology
filter(ClusterNodeFilter filter)
Returns a copy of this topology containing only those nodes that match the specified filter.ClusterTopology
filterAll(ClusterFilter filter)
Returns a copy of this topology that contains only those nodes that match the specified filter.ClusterNode
first()
Returns the first node of thenodes()
list ornull
if this topology is empty.ClusterNode
get(ClusterNodeId id)
Returns the node for the specified identifier ornull
if there is no such node within this topology.ClusterHash
hash()
Returns the SHA-256 hash of allcluster node identifiers
of this topology.boolean
isEmpty()
Returnstrue
if this topology doesn't have any nodes.NavigableSet<ClusterNode>
joinOrder()
Returns an immutable set of all nodes ordered by theirjoin order
.ClusterNode
last()
Returns the last node of thenodes()
list ornull
if this topology is empty.ClusterNode
localNode()
Returns local node ornull
if local node is not within this topology.List<ClusterNode>
nodes()
Returns an immutable list of all nodes with consistent ordering based onClusterNode.compareTo(ClusterNode)
method.Set<ClusterNode>
nodeSet()
Returns an immutable set of all nodes within this topology.static ClusterTopology
of(long version, Set<ClusterNode> nodes)
Constructs a new cluster topology.ClusterNode
oldest()
Returns the oldest node of this topology.ClusterNode
random()
Returns a random node of this topology.List<ClusterNode>
remoteNodes()
Returns an immutable list of remote nodes within this topology ordered by theiridentifiers
.int
size()
Returns the number of nodes in this topology.Stream<ClusterNode>
stream()
ReturnsStream
of all nodes from this topology.long
version()
Returns the version of this topology.ClusterNode
youngest()
Returns the youngest node of this topology.-
Methods inherited from interface io.hekate.cluster.ClusterTopologySupport
topology
-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
version
long version()
Returns the version of this topology.This method provides support for tacking changes of the cluster topology. The value of this property is monotonically incremented each time when the cluster topology changes.
Note: Version is local to each node and can differ from node to node.
- Returns:
- Version this topology.
-
hash
ClusterHash hash()
Returns the SHA-256 hash of allcluster node identifiers
of this topology.If this topology is
filtered
then only those nodes that match the filter criteria will be used to compute the hash.- Returns:
- SHA-256 hash of this topology.
-
localNode
ClusterNode localNode()
Returns local node ornull
if local node is not within this topology.- Returns:
- Local node or
null
if local node is not within this topology. - See Also:
ClusterNode.isLocal()
-
nodes
List<ClusterNode> nodes()
Returns an immutable list of all nodes with consistent ordering based onClusterNode.compareTo(ClusterNode)
method. Returns an empty list if there are no nodes within this topology.- Returns:
- Immutable list of all nodes with consistent ordering or an empty list if there are no nodes within this topology.
-
first
ClusterNode first()
Returns the first node of thenodes()
list ornull
if this topology is empty.- Returns:
- The first node of the
nodes()
list ornull
if this topology is empty.
-
last
ClusterNode last()
Returns the last node of thenodes()
list ornull
if this topology is empty.- Returns:
- The last node of the
nodes()
list ornull
if this topology is empty.
-
nodeSet
Set<ClusterNode> nodeSet()
Returns an immutable set of all nodes within this topology. Returns an empty set if there are no nodes within this topology.- Returns:
- Immutable set of all nodes within this topology or an empty list if there are no nodes within this topology.
-
remoteNodes
List<ClusterNode> remoteNodes()
Returns an immutable list of remote nodes within this topology ordered by theiridentifiers
. Returns an empty list if there are no remote nodes within this topology.- Returns:
- Immutable list of remotes node within this topology ordered by their
identifiers
or an empty list if there are no remote nodes within this topology.. - See Also:
ClusterNode.isLocal()
-
joinOrder
NavigableSet<ClusterNode> joinOrder()
Returns an immutable set of all nodes ordered by theirjoin order
. The first element in this set is the oldest node. Returns an empty set if there are no nodes within this topology.- Returns:
- Immutable set of all nodes ordered by their
join order
or an empty set if there are no nodes within this topology.
-
stream
Stream<ClusterNode> stream()
ReturnsStream
of all nodes from this topology.- Returns:
Stream
of all nodes from this topology.
-
contains
boolean contains(ClusterNode node)
Returnstrue
if this topology contains the specified node.- Parameters:
node
- Node to check.- Returns:
true
if this topology contains the specified node.
-
contains
boolean contains(ClusterNodeId id)
Returnstrue
if this topology contains a node with the specified identifier.- Parameters:
id
- Node identifier to check.- Returns:
true
if this topology contains a node with the specified identifier.
-
get
ClusterNode get(ClusterNodeId id)
Returns the node for the specified identifier ornull
if there is no such node within this topology.- Parameters:
id
- Node identifier.- Returns:
- Node for the specified identifier or
null
if there is no such node within this topology.
-
size
int size()
Returns the number of nodes in this topology.- Returns:
- Number of nodes in this topology.
-
isEmpty
boolean isEmpty()
Returnstrue
if this topology doesn't have any nodes.- Returns:
true
if this topology doesn't have any nodes.
-
oldest
ClusterNode oldest()
Returns the oldest node of this topology. Returnsnull
if this topology is empty.The oldest node is the node with the lowest
join order
.- Returns:
- Oldest node of this topology or
null
if this topology is empty.
-
youngest
ClusterNode youngest()
Returns the youngest node of this topology. Returnsnull
if this topology is empty.The youngest node is the node with the highest
join order
.- Returns:
- Youngest node within of this topology or
null
if this topology is empty.
-
random
ClusterNode random()
Returns a random node of this topology. Returnsnull
if this topology is empty.- Returns:
- Random node or
null
if this topology is empty.
-
filterAll
ClusterTopology filterAll(ClusterFilter filter)
Returns a copy of this topology that contains only those nodes that match the specified filter. Thetopology version
will be preserved in the returned copy.- Parameters:
filter
- Filter.- Returns:
- Copy of this topology that contains only those nodes that match the specified filter.
-
filter
ClusterTopology filter(ClusterNodeFilter filter)
Returns a copy of this topology containing only those nodes that match the specified filter. Thetopology version
will be preserved in the returned copy.- Parameters:
filter
- Filter.- Returns:
- Copy of this topology that contains only those nodes that match the specified filter.
-
of
static ClusterTopology of(long version, Set<ClusterNode> nodes)
Constructs a new cluster topology.
-
empty
static ClusterTopology empty()
Return an empty cluster topology.
-
-