@Named public final class DefaultUnicastMessenger extends java.lang.Object implements UnicastMessenger, CommunicationFacility
Modifier and Type | Field and Description |
---|---|
private java.util.Set<WorkerAddress> |
computeNeighbours
Addresses of workers - collected by the messenger itself.
|
private java.util.Set<UnicastMessageListener<java.io.Serializable>> |
listeners |
private WorkerAddress |
localWorkerAddress |
private static org.slf4j.Logger |
log |
private TopologyService |
topologyService
Topology service - needed for obtaining the node-level neighbours.
|
private WorkerCommunication |
workerCommunication |
Constructor and Description |
---|
DefaultUnicastMessenger(TopologyService topologyService,
WorkerCommunication workerCommunication) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addNeighbour(WorkerAddress workerAddress) |
WorkerAddress |
address() |
private void |
broadcastMyAddress() |
java.util.Set<WorkerAddress> |
neighbours() |
<T extends java.io.Serializable> |
onMessage(WorkerMessage<T> workerMessage)
Handles a message.
|
<T extends java.io.Serializable> |
registerListener(UnicastMessageListener<T> listener)
Registers a listener that will receive all incoming messages target for this address (obtained via
UnicastMessenger.address() ). |
<T extends java.io.Serializable> |
removeListener(UnicastMessageListener<T> listener)
Removes the listener.
|
void |
reset() |
<T extends java.io.Serializable> |
send(java.util.Set<WorkerAddress> receivers,
T message)
Sends the message to the specified workers.
|
<T extends java.io.Serializable> |
send(WorkerAddress receiver,
T message)
Sends the message to the specified worker.
|
void |
start() |
java.util.Set<WorkerMessage.Type> |
subscribedTypes()
Returns a set of message types that this listener wants to subscribe to.
|
java.lang.String |
toString() |
private static final org.slf4j.Logger log
private final java.util.Set<UnicastMessageListener<java.io.Serializable>> listeners
private final java.util.Set<WorkerAddress> computeNeighbours
Addresses of workers - collected by the messenger itself.
private final WorkerAddress localWorkerAddress
private final TopologyService topologyService
Topology service - needed for obtaining the node-level neighbours.
private final WorkerCommunication workerCommunication
@Inject public DefaultUnicastMessenger(TopologyService topologyService, WorkerCommunication workerCommunication)
public WorkerAddress address()
address
in interface UnicastMessenger
public java.util.Set<WorkerAddress> neighbours()
neighbours
in interface UnicastMessenger
public <T extends java.io.Serializable> void send(WorkerAddress receiver, T message)
UnicastMessenger
Sends the message to the specified worker.
send
in interface UnicastMessenger
T
- a type of the payload.receiver
- a recipient of the message.message
- a message to send.public <T extends java.io.Serializable> void send(java.util.Set<WorkerAddress> receivers, T message)
UnicastMessenger
Sends the message to the specified workers.
send
in interface UnicastMessenger
T
- a type of the payload.receivers
- a set of recipients of the message.message
- a message to send.public <T extends java.io.Serializable> void registerListener(UnicastMessageListener<T> listener)
UnicastMessenger
Registers a listener that will receive all incoming messages target for this address (obtained via UnicastMessenger.address()
).
registerListener
in interface UnicastMessenger
T
- a type of the payload.listener
- a listener to register.public <T extends java.io.Serializable> void removeListener(UnicastMessageListener<T> listener)
UnicastMessenger
Removes the listener.
removeListener
in interface UnicastMessenger
T
- a type of the payload.listener
- a listener to remove.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
private void broadcastMyAddress()
void addNeighbour(WorkerAddress workerAddress)
public java.lang.String toString()
toString
in class java.lang.Object