@Named @ThreadSafe public final class ComputeTopologyProvider extends java.lang.Object implements TopologyProvider<java.io.Serializable>, CommunicationFacility
Modifier and Type | Class and Description |
---|---|
private class |
ComputeTopologyProvider.IdsListener |
Modifier and Type | Field and Description |
---|---|
private @Nullable org.jgrapht.Graph<java.io.Serializable,AnnotatedEdge> |
cachedTopology |
private java.util.Map<HazelcastObjectNames.ConfigurationKey,java.lang.Object> |
configurationMap |
private ISet<java.io.Serializable> |
idsSet
Global set of IDs.
|
private java.util.concurrent.locks.ReentrantReadWriteLock |
lock |
private static org.slf4j.Logger |
logger |
private boolean |
needUpgrade |
private Topology<java.io.Serializable> |
topology |
private WorkerCommunication |
workerCommunication |
Constructor and Description |
---|
ComputeTopologyProvider(HazelcastInstance hazelcastInstance,
WorkerCommunication workerCommunication) |
Modifier and Type | Method and Description |
---|---|
void |
addNodes(java.util.Set<java.io.Serializable> ids)
Add nodes to the current topology.
|
boolean |
areNeighbours(java.io.Serializable first,
java.io.Serializable second)
Check if the
second is a neighbour of first in this exact direction |
private void |
markForUpgrade() |
java.util.Map<java.io.Serializable,java.util.Set<java.lang.String>> |
neighboursOf(java.io.Serializable id)
Returns neighbours (according to the current topology).
|
java.util.Map<java.lang.String,java.io.Serializable> |
neighboursOfByAnnotation(java.io.Serializable id)
Returns neighbours (according to the current topology).
|
<T extends java.io.Serializable> |
onMessage(WorkerMessage<T> workerMessage)
Handles a message.
|
void |
reset() |
void |
setTopology(Topology<java.io.Serializable> topology)
Set the new topology function.
|
void |
start() |
java.util.Set<WorkerMessage.Type> |
subscribedTypes()
Returns a set of message types that this listener wants to subscribe to.
|
private static final org.slf4j.Logger logger
private final WorkerCommunication workerCommunication
private final java.util.Map<HazelcastObjectNames.ConfigurationKey,java.lang.Object> configurationMap
private final ISet<java.io.Serializable> idsSet
Global set of IDs.
private final java.util.concurrent.locks.ReentrantReadWriteLock lock
private Topology<java.io.Serializable> topology
private @Nullable org.jgrapht.Graph<java.io.Serializable,AnnotatedEdge> cachedTopology
private boolean needUpgrade
@Inject public ComputeTopologyProvider(HazelcastInstance hazelcastInstance, WorkerCommunication workerCommunication)
public <T extends java.io.Serializable> boolean onMessage(WorkerMessage<T> workerMessage)
CommunicationFacility
Handles a message.
Only messages directed to this node will be passed with this method, so implementers do not need to check whether they are recipients.
onMessage
in interface CommunicationFacility
T
- a type of the payload.workerMessage
- a received message (for the current node).public java.util.Set<WorkerMessage.Type> subscribedTypes()
CommunicationFacility
Returns a set of message types that this listener wants to subscribe to.
subscribedTypes
in interface CommunicationFacility
public void start()
start
in interface CommunicationFacility
public void reset()
reset
in interface CommunicationFacility
public void setTopology(Topology<java.io.Serializable> topology)
TopologyProvider
Set the new topology function.
setTopology
in interface TopologyProvider<java.io.Serializable>
topology
- a function used to generate topologiespublic void addNodes(java.util.Set<java.io.Serializable> ids)
TopologyProvider
Add nodes to the current topology.
addNodes
in interface TopologyProvider<java.io.Serializable>
ids
- IDs of the nodes to addpublic java.util.Map<java.io.Serializable,java.util.Set<java.lang.String>> neighboursOf(java.io.Serializable id)
TopologyProvider
Returns neighbours (according to the current topology).
neighboursOf
in interface TopologyProvider<java.io.Serializable>
id
- id of the workplace to look up neighbours#addNodes
) and values are sets of annotations assigned by the topology function to this neighbourpublic java.util.Map<java.lang.String,java.io.Serializable> neighboursOfByAnnotation(java.io.Serializable id)
TopologyProvider
Returns neighbours (according to the current topology).
Warning: values may be duplicated if single neighbour has multiple annotations on its edges.
neighboursOfByAnnotation
in interface TopologyProvider<java.io.Serializable>
id
- id of the workplace to look up neighbours#addNodes
public boolean areNeighbours(java.io.Serializable first, java.io.Serializable second)
TopologyProvider
Check if the second
is a neighbour of first
in this exact direction
areNeighbours
in interface TopologyProvider<java.io.Serializable>
first
- first idsecond
- second itprivate void markForUpgrade()