if (getCluster().getMyAddress() != null && msg.getSrc() != null && getCluster().getMyAddress().equals(msg.getSrc()))
return; // discard own (cannot set the flag because it screws up th control channel. not much to do about it - annoing up handler in JChannel)
final byte[] buffer = msg.getRawBuffer();
if (buffer.length == 0)
return; // probably just a flush
final Message message = Message.fromByteArray(buffer);
final Address source = msg.getSrc();
if (message.isResponse()) {
final Deque<Message> pending = pendingReply.get(message.getNode());
if (pending != null) {
boolean res = pending.removeLastOccurrence(message); // relies on Message.equals that matches request/reply
if (res)
LOG.debug("Message {} is a reply! (removing from pending)", message);
}
}
if (message.isResponse()) {
final BroadcastEntry entry = pendingBroadcasts.get(message.getMessageId());
if (entry != null) {
if (message.getType() != Message.Type.ACK) {// this is a response - no need to wait for further acks
LOG.debug("Message {} is a reply to a broadcast! (discarding pending)", message);
pendingBroadcasts.remove(message.getMessageId());
} else
removeFromPendingBroadcasts(message.getMessageId(), message.getNode());
}
}
final short sourceNode = getNode(source);
if (sourceNode < 0)
throw new RuntimeException("Node not found for source address " + source);
message.setNode(sourceNode);
receive(message);
} catch (Exception ex) {
LOG.error("Error receiving message", ex);
}
}