The MessageReceiver interface offers the method addHandler (see that it is not "set", but "add") which is expected to add a new handler to the message handling chain. It would be expected that only one of those handlers actually handled the message and the other ignore them (allowing more than one handler to process the message requieres a more complex interface like a decorator, on whith the response from one handler is passed to the next)
In the various implementations of MessageReceiver (UDP and TCP), handlers are added to a list. When a new message arrives, the receiveMessage method iterates on this list and calls each handler.
The problem is that each handler can return either a message or null, but this is not checked. therefore, if the first handler returns a message but the second handler returns null, the last value (that is null) is returned.
protected Message receiveMessage(Message msg) {
// call every handlers
Message ret = null;
for (MessageHandler handler: handlerList) {
try {
ret = handler.process(msg);
}
catch (Exception e) {
logger.log(Level.SEVERE, "A MessageHandler threw an Exception.", e);
}
}
return ret;
}
One possible solution (alredy tested) is to check the return value and stop iterating as soon as a non null value is returned:
ret = handler.process(msg);
if(ret != null) {
break;
}