public class EventReactor extends java.lang.Object implements MessageListener
MendelMessage
instances).Constructor and Description |
---|
EventReactor(java.lang.Object handlerObject,
EventMap eventMap)
Creates an EventReactor with the default
BasicEventWrapper
EventWrapper implementation. |
EventReactor(java.lang.Object handlerObject,
EventWrapper wrapper)
Creates an EventReactor with a custom EventWrapper implementation.
|
Modifier and Type | Method and Description |
---|---|
protected void |
linkEventHandlers()
This method links incoming event types to their relevant event handlers
found in the handlerObject.
|
void |
onConnect(NetworkDestination endpoint)
Called when a connection is established with a remote endpoint.
|
void |
onDisconnect(NetworkDestination endpoint)
Called when the MessageListener has been disconnected from a remote
endpoint.
|
void |
onMessage(MendelMessage message)
Called when a message is ready to be processed.
|
void |
processNextEvent()
Retrieves the next message from the queue, and calls the appropriate
event handler method to process the message.
|
MendelMessage |
wrapEvent(Event e)
Convenience function for wrapping an outgoing event with this
EventReactor's
EventWrapper implementation. |
public EventReactor(java.lang.Object handlerObject, EventMap eventMap)
BasicEventWrapper
EventWrapper implementation.handlerObject
- an Object instance that contains the implementations
for event handlers, denoted by the EventHandler
annotation.eventMap
- a EventMap implementation that provides a mapping from
integer identification numbers to specific classes that represent an
event.public EventReactor(java.lang.Object handlerObject, EventWrapper wrapper)
handlerObject
- an Object instance that contains the implementations
for event handlers, denoted by the EventHandler
annotation.wrapper
- A problem-specific EventWrapper
implementation.protected void linkEventHandlers()
public void processNextEvent() throws EventException, java.io.IOException, java.lang.InterruptedException, SerializationException
EventException
- when the incoming event is unknown, or errors
occur while trying to call the appropriate handler methodjava.lang.InterruptedException
- if the calling thread is interrupted while
waiting for a new message to arrivejava.io.IOException
SerializationException
public void onConnect(NetworkDestination endpoint)
MessageListener
onConnect
in interface MessageListener
public void onDisconnect(NetworkDestination endpoint)
MessageListener
onDisconnect
in interface MessageListener
public void onMessage(MendelMessage message)
MessageListener
MessageRouter
instance). To avoid
hurting performance, the implementation of onMessage must be lightweight.
In fact, blocking in this method implementation can cause serious
problems.
An example use case could involve placing incoming messages in a blocking queue and then having another thread process them. If the queue gets too full, then it may be appropriate to block here (thus blocking the Selector thread) to slow the rate of incoming messages from the network.
onMessage
in interface MessageListener
message
- MendelMessage that was received; null if the connection
has been terminated.public MendelMessage wrapEvent(Event e) throws java.io.IOException
EventWrapper
implementation.java.io.IOException