synchronized(exchange) { failedCount = exchange.getFailedTransmissionCount() + 1; exchange.setFailedTransmissionCount(failedCount);
synchronized(exchange) { failedCount = exchange.getFailedTransmissionCount() + 1; exchange.setFailedTransmissionCount(failedCount);
/** * When we receive a Confirmable response, we acknowledge it and it also * counts as acknowledgment for the request. If the response is a duplicate, * we stop it here and do not forward it to the upper layer. */ @Override public void receiveResponse(final Exchange exchange, final Response response) { exchange.setFailedTransmissionCount(0); exchange.getCurrentRequest().setAcknowledged(true); LOGGER.finest("Cancel any retransmission"); exchange.setRetransmissionHandle(null); if (response.getType() == Type.CON && !exchange.getRequest().isCanceled()) { LOGGER.finer("Response is confirmable, send ACK"); EmptyMessage ack = EmptyMessage.newACK(response); sendEmptyMessage(exchange, ack); } if (response.isDuplicate()) { LOGGER.fine("Response is duplicate, ignore it"); } else { super.receiveResponse(exchange, response); } }
/** * When we receive a Confirmable response, we acknowledge it and it also * counts as acknowledgment for the request. If the response is a duplicate, * we stop it here and do not forward it to the upper layer. */ @Override public void receiveResponse(final Exchange exchange, final Response response) { exchange.setFailedTransmissionCount(0); exchange.getCurrentRequest().setAcknowledged(true); exchange.setRetransmissionHandle(null); if (response.getType() == Type.CON && !exchange.getRequest().isCanceled()) { LOGGER.finer("acknowledging CON response"); EmptyMessage ack = EmptyMessage.newACK(response); sendEmptyMessage(exchange, ack); } if (response.isDuplicate()) { LOGGER.fine("ignoring duplicate response"); } else { upper().receiveResponse(exchange, response); } }
public void testRegisterOutboundRequestAcceptsRetransmittedRequest() { Exchange exchange = newOutboundRequest(); store.registerOutboundRequest(exchange); // WHEN registering the same request as a re-transmission exchange.setFailedTransmissionCount(1); store.registerOutboundRequest(exchange); // THEN the store contains the re-transmitted request KeyMID key = KeyMID.fromOutboundMessage(exchange.getCurrentRequest()); Exchange exchangeFromStore = store.get(key); assertThat(exchangeFromStore, is(exchange)); assertThat(exchangeFromStore.getFailedTransmissionCount(), is(1)); }
/** * If we receive an ACK or RST, we mark the outgoing request or response * as acknowledged or rejected respectively and cancel its retransmission. */ @Override public void receiveEmptyMessage(final Exchange exchange, final EmptyMessage message) { exchange.setFailedTransmissionCount(0); // TODO: If this is an observe relation, the current response might not // be the one that is being acknowledged. The current response might // already be the next NON notification. if (message.getType() == Type.ACK) { if (exchange.getOrigin() == Origin.LOCAL) { exchange.getCurrentRequest().setAcknowledged(true); } else { exchange.getCurrentResponse().setAcknowledged(true); } } else if (message.getType() == Type.RST) { if (exchange.getOrigin() == Origin.LOCAL) { exchange.getCurrentRequest().setRejected(true); } else { exchange.getCurrentResponse().setRejected(true); } } else { LOGGER.warning("Empty messgae was not ACK nor RST: "+message); } LOGGER.finer("Cancel retransmission"); exchange.setRetransmissionHandle(null); super.receiveEmptyMessage(exchange, message); }
/** * If we receive an ACK or RST, we mark the outgoing request or response as * acknowledged or rejected respectively and cancel its retransmission. */ @Override public void receiveEmptyMessage(final Exchange exchange, final EmptyMessage message) { exchange.setFailedTransmissionCount(0); // TODO: If this is an observe relation, the current response might not // be the one that is being acknowledged. The current response might // already be the next NON notification. if (message.getType() == Type.ACK) { if (exchange.isOfLocalOrigin()) { exchange.getCurrentRequest().setAcknowledged(true); } else { exchange.getCurrentResponse().setAcknowledged(true); } } else if (message.getType() == Type.RST) { if (exchange.isOfLocalOrigin()) { exchange.getCurrentRequest().setRejected(true); } else { exchange.getCurrentResponse().setRejected(true); } } else { LOGGER.log(Level.WARNING, "received empty message that is neither ACK nor RST: {0}", message); } exchange.setRetransmissionHandle(null); upper().receiveEmptyMessage(exchange, message); }