Class TcpDiscoveryNodesRing
- java.lang.Object
-
- org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNodesRing
-
public class TcpDiscoveryNodesRing extends Object
Convenient way to represent topology forTcpDiscoverySpi
-
-
Field Summary
Fields Modifier and Type Field Description static IgnitePredicate<TcpDiscoveryNode>VISIBLE_NODESVisible nodes filter.
-
Constructor Summary
Constructors Constructor Description TcpDiscoveryNodesRing()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(TcpDiscoveryNode node)Adds node to topology, also initializes node last update time with current system time.Collection<TcpDiscoveryNode>allNodes()Gets all nodes in the topology.voidclear()Removes all remote nodes, leaves only local node.Collection<TcpDiscoveryNode>clientNodes()@Nullable TcpDiscoveryNodecoordinator()Finds coordinator in the topology.@Nullable TcpDiscoveryNodecoordinator(@Nullable Collection<TcpDiscoveryNode> excluded)Finds coordinator in the topology filtering excluded nodes from the search.booleanhasRemoteNodes()Checks whether the topology has remote nodes in.booleanhasRemoteServerNodes()Checks whether the topology has remote server nodes in.longincrementTopologyVersion()Increments topology version and gets new value.voidlocalNode(TcpDiscoveryNode locNode)Sets local node.longmaxInternalOrder()IgniteProductVersionminimumNodeVersion()@Nullable TcpDiscoveryNodenextNode()Finds next node in the topology.@Nullable TcpDiscoveryNodenextNode(@Nullable Collection<TcpDiscoveryNode> excluded)Finds next node in the topology filtering excluded nodes from search.longnextNodeOrder()Increments topology version and gets new value.@Nullable TcpDiscoveryNodenode(UUID nodeId)Finds node by ID.@Nullable TcpDiscoveryNodepreviousNode(@Nullable Collection<TcpDiscoveryNode> excluded)Finds previous node in the topology filtering excluded nodes from search.TcpDiscoveryNodepreviousNodeOf(TcpDiscoveryNode ringNode)Collection<TcpDiscoveryNode>remoteNodes()Gets remote nodes.@Nullable TcpDiscoveryNoderemoveNode(UUID nodeId)Removes node from the topology.voidrestoreTopology(Iterable<TcpDiscoveryNode> nodes, long topVer)Restores topology from parameters values.Collection<TcpDiscoveryNode>serverNodes()longtopologyVersion()Gets current topology version.booleantopologyVersion(long topVer)Sets new topology version.StringtoString()Collection<TcpDiscoveryNode>visibleNodes()Gets visible nodes in the topology.Collection<TcpDiscoveryNode>visibleRemoteNodes()Gets visible remote nodes in the topology.
-
-
-
Field Detail
-
VISIBLE_NODES
public static final IgnitePredicate<TcpDiscoveryNode> VISIBLE_NODES
Visible nodes filter.
-
-
Method Detail
-
minimumNodeVersion
public IgniteProductVersion minimumNodeVersion()
- Returns:
- Minimum node version.
-
localNode
public void localNode(TcpDiscoveryNode locNode)
Sets local node.- Parameters:
locNode- Local node.
-
allNodes
public Collection<TcpDiscoveryNode> allNodes()
Gets all nodes in the topology.- Returns:
- Collection of all nodes.
-
visibleNodes
public Collection<TcpDiscoveryNode> visibleNodes()
Gets visible nodes in the topology.- Returns:
- Collection of visible nodes.
-
remoteNodes
public Collection<TcpDiscoveryNode> remoteNodes()
Gets remote nodes.- Returns:
- Collection of remote nodes in grid.
-
visibleRemoteNodes
public Collection<TcpDiscoveryNode> visibleRemoteNodes()
Gets visible remote nodes in the topology.- Returns:
- Collection of visible remote nodes.
-
clientNodes
public Collection<TcpDiscoveryNode> clientNodes()
- Returns:
- Client nodes.
-
serverNodes
public Collection<TcpDiscoveryNode> serverNodes()
- Returns:
- Server nodes.
-
hasRemoteNodes
public boolean hasRemoteNodes()
Checks whether the topology has remote nodes in.- Returns:
trueif the topology has remote nodes in.
-
hasRemoteServerNodes
public boolean hasRemoteServerNodes()
Checks whether the topology has remote server nodes in.- Returns:
trueif the topology has remote server nodes in.
-
add
public boolean add(TcpDiscoveryNode node)
Adds node to topology, also initializes node last update time with current system time.- Parameters:
node- Node to add.- Returns:
trueif such node was added and did not present previously in the topology.
-
maxInternalOrder
public long maxInternalOrder()
- Returns:
- Max internal order.
-
restoreTopology
public void restoreTopology(Iterable<TcpDiscoveryNode> nodes, long topVer)
Restores topology from parameters values.This method is called when new node receives topology from coordinator. In this case all nodes received are remote for local.
Also initializes nodes last update time with current system time.
- Parameters:
nodes- List of remote nodes.topVer- Topology version.
-
node
@Nullable public @Nullable TcpDiscoveryNode node(UUID nodeId)
Finds node by ID.- Parameters:
nodeId- Node id to find.- Returns:
- Node with ID provided or
nullif not found.
-
removeNode
@Nullable public @Nullable TcpDiscoveryNode removeNode(UUID nodeId)
Removes node from the topology.- Parameters:
nodeId- ID of the node to remove.- Returns:
trueif node was removed.
-
clear
public void clear()
Removes all remote nodes, leaves only local node.This should be called when SPI should be disconnected from topology and reconnected back after.
-
coordinator
@Nullable public @Nullable TcpDiscoveryNode coordinator()
Finds coordinator in the topology.- Returns:
- Coordinator node that gives versions to topology (node with the smallest order).
-
coordinator
@Nullable public @Nullable TcpDiscoveryNode coordinator(@Nullable @Nullable Collection<TcpDiscoveryNode> excluded)
Finds coordinator in the topology filtering excluded nodes from the search.This may be used when handling current coordinator leave or failure.
- Parameters:
excluded- Nodes to exclude from the search (optional).- Returns:
- Coordinator node among remaining nodes or
nullif all nodes are excluded.
-
nextNode
@Nullable public @Nullable TcpDiscoveryNode nextNode()
Finds next node in the topology.- Returns:
- Next node.
-
nextNode
@Nullable public @Nullable TcpDiscoveryNode nextNode(@Nullable @Nullable Collection<TcpDiscoveryNode> excluded)
Finds next node in the topology filtering excluded nodes from search.This may be used when detecting and handling nodes failure.
- Parameters:
excluded- Nodes to exclude from the search (optional). If provided, cannot contain local node.- Returns:
- Next node or
nullif all nodes were filtered out or topology contains less than two nodes.
-
previousNode
@Nullable public @Nullable TcpDiscoveryNode previousNode(@Nullable @Nullable Collection<TcpDiscoveryNode> excluded)
Finds previous node in the topology filtering excluded nodes from search.This may be used when detecting and handling nodes failure.
- Parameters:
excluded- Nodes to exclude from the search (optional). If provided, cannot contain local node.- Returns:
- Previous node or
nullif all nodes were filtered out or topology contains less than two nodes.
-
previousNodeOf
public TcpDiscoveryNode previousNodeOf(TcpDiscoveryNode ringNode)
- Parameters:
ringNode- Node for which to find a predecessor.- Returns:
- Previous node of the given node in the ring.
- Throws:
IllegalArgumentException- If the given node was not found in the ring.
-
topologyVersion
public long topologyVersion()
Gets current topology version.- Returns:
- Current topology version.
-
topologyVersion
public boolean topologyVersion(long topVer)
Sets new topology version.- Parameters:
topVer- New topology version (should be greater than current, otherwise no-op).- Returns:
Trueif topology has been changed.
-
incrementTopologyVersion
public long incrementTopologyVersion()
Increments topology version and gets new value.- Returns:
- Topology version (incremented).
-
nextNodeOrder
public long nextNodeOrder()
Increments topology version and gets new value.- Returns:
- Topology version (incremented).
-
-