public void messageReceived(ChannelMessage msg) { if (okToProcess(msg.getOptions())) { if (msg.getMessage().getLength() == (START_DATA.length + msg.getUniqueId().length + END_DATA.length) && Arrays.contains(msg.getMessage().getBytesDirect(), 0, START_DATA, 0, START_DATA.length) && Arrays.contains( msg.getMessage().getBytesDirect(), START_DATA.length + msg.getUniqueId().length, END_DATA, 0, END_DATA.length)) { UniqueId id = new UniqueId( msg.getMessage().getBytesDirect(), START_DATA.length, msg.getUniqueId().length); MapEntry original = (MapEntry) messages.get(id); if (original != null) { super.messageReceived(original.msg); messages.remove(id); } else log.warn( "Received a confirmation, but original message is missing. Id:" + Arrays.toString(id.getBytes())); } else { UniqueId id = new UniqueId(msg.getUniqueId()); MapEntry entry = new MapEntry((ChannelMessage) msg.deepclone(), id, System.currentTimeMillis()); messages.put(id, entry); } } else { super.messageReceived(msg); } }
/** * @param order MessageOrder * @return boolean - true if a message expired and was processed */ protected boolean processIncoming(MessageOrder order) { boolean result = false; Member member = order.getMessage().getAddress(); Counter cnt = getInCounter(member); MessageOrder tmp = incoming.get(member); if (tmp != null) { order = MessageOrder.add(tmp, order); } while ((order != null) && (order.getMsgNr() <= cnt.getCounter())) { // we are right on target. process orders if (order.getMsgNr() == cnt.getCounter()) cnt.inc(); else if (order.getMsgNr() > cnt.getCounter()) cnt.setCounter(order.getMsgNr()); super.messageReceived(order.getMessage()); order.setMessage(null); order = order.next; } MessageOrder head = order; MessageOrder prev = null; tmp = order; // flag to empty out the queue when it larger than maxQueue boolean empty = order != null ? order.getCount() >= maxQueue : false; while (tmp != null) { // process expired messages or empty out the queue if (tmp.isExpired(expire) || empty) { // reset the head if (tmp == head) head = tmp.next; cnt.setCounter(tmp.getMsgNr() + 1); if (getForwardExpired()) super.messageReceived(tmp.getMessage()); tmp.setMessage(null); tmp = tmp.next; if (prev != null) prev.next = tmp; result = true; } else { prev = tmp; tmp = tmp.next; } } if (head == null) incoming.remove(member); else incoming.put(member, head); return result; }
@Override public void messageReceived(ChannelMessage msg) { // catch incoming boolean process = true; if (okToProcess(msg.getOptions())) { // check to see if it is a testMessage, if so, process = false process = ((msg.getMessage().getLength() != TCP_FAIL_DETECT.length) || (!Arrays.equals(TCP_FAIL_DETECT, msg.getMessage().getBytes()))); } // end if // ignore the message, it doesnt have the flag set if (process) super.messageReceived(msg); else if (log.isDebugEnabled()) log.debug("Received a failure detector packet:" + msg); }
@Override public void messageReceived(ChannelMessage msg) { if (!okToProcess(msg.getOptions())) { super.messageReceived(msg); return; } int msgnr = XByteBuffer.toInt(msg.getMessage().getBytesDirect(), msg.getMessage().getLength() - 4); msg.getMessage().trim(4); MessageOrder order = new MessageOrder(msgnr, (ChannelMessage) msg.deepclone()); try { inLock.writeLock().lock(); if (processIncoming(order)) processLeftOvers(msg.getAddress(), false); } finally { inLock.writeLock().unlock(); } }