@Named @ThreadSafe public final class DefaultBroadcastMessenger extends java.lang.Object implements BroadcastMessenger, CommunicationFacility
Modifier and Type | Field and Description |
---|---|
private java.util.Set<BroadcastMessageListener<java.io.Serializable>> |
listeners |
private static org.slf4j.Logger |
log |
private TopologyService |
topologyService |
private WorkerCommunication |
workerCommunication |
Constructor and Description |
---|
DefaultBroadcastMessenger(WorkerCommunication workerCommunication,
TopologyService topologyService) |
Modifier and Type | Method and Description |
---|---|
<T extends java.io.Serializable> |
onMessage(WorkerMessage<T> workerMessage)
Handles a message.
|
<T extends java.io.Serializable> |
registerListener(BroadcastMessageListener<T> listener)
Registers a listener that will receive all incoming messages.
|
<T extends java.io.Serializable> |
removeListener(BroadcastMessageListener<T> listener)
Removes the listener.
|
void |
reset() |
void |
send(java.io.Serializable message)
Sends the message to all neighbouring workers.
|
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<BroadcastMessageListener<java.io.Serializable>> listeners
private final TopologyService topologyService
private final WorkerCommunication workerCommunication
@Inject public DefaultBroadcastMessenger(WorkerCommunication workerCommunication, TopologyService topologyService)
public void send(java.io.Serializable message)
BroadcastMessenger
Sends the message to all neighbouring workers.
send
in interface BroadcastMessenger
message
- a message to send.public <T extends java.io.Serializable> void registerListener(BroadcastMessageListener<T> listener)
BroadcastMessenger
Registers a listener that will receive all incoming messages.
registerListener
in interface BroadcastMessenger
T
- a type of the payload.listener
- a listener to register.public <T extends java.io.Serializable> void removeListener(BroadcastMessageListener<T> listener)
BroadcastMessenger
Removes the listener.
removeListener
in interface BroadcastMessenger
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
public java.lang.String toString()
toString
in class java.lang.Object