/** * This method also cleans up the Matcher state by eventually calling the * exchange observer. */ public void setTimedOut() { this.timedOut = true; // clean up this.setComplete(); }
/** * This method also cleans up the Matcher state by eventually calling the * exchange observer. */ public void setTimedOut() { this.timedOut = true; // clean up this.setComplete(); }
@Override public void sendEmptyMessage(final Exchange exchange, final EmptyMessage message) { // ensure Token is set message.setToken(new byte[0]); if (message.getType() == Type.RST && exchange != null) { // We have rejected the request or response exchange.setComplete(); } }
public void sendEmptyMessage(Exchange exchange, EmptyMessage message) { // ensure Token is set message.setToken(new byte[0]); if (message.getType() == Type.RST && exchange != null) { // We have rejected the request or response exchange.setComplete(); } }
@Override public void run() { if (!exchange.isComplete()) { if (exchange.getRequest() == null) { LOGGER.log(Level.INFO, "Block1 transfer timed out: {0}", exchange.getCurrentRequest()); } else { LOGGER.log(Level.INFO, "Block2 transfer timed out: {0}", exchange.getRequest()); } exchange.setComplete(); } } }
@Override public void run() { if (!exchange.isComplete()) { if (exchange.getRequest()==null) { LOGGER.info("Block1 transfer timed out: " + exchange.getCurrentRequest()); } else { LOGGER.info("Block2 transfer timed out: " + exchange.getRequest()); } exchange.setComplete(); } } }
@Override public void receiveResponse(final Exchange exchange, final Response response) { if (!response.getOptions().hasObserve()) { exchange.setComplete(); } if (hasDeliverer()) { // notify request that response has arrived deliverer.deliverResponse(exchange, response); } else { LOGGER.severe("Top of CoAP stack has no deliverer to deliver response"); } }
@Override public void run() { if(exchange.getResponse() == null) { exchange.getCurrentRequest().setCanceled(true); } exchange.setComplete(); } }, multicastMaxLifetime, TimeUnit.MILLISECONDS);
@Override public void onCancel() { if (!exchange.isComplete()) { LOGGER.log(Level.FINE, "completing canceled request [MID={0}, token={1}]", new Object[]{ exchange.getRequest().getMID(), exchange.getRequest().getTokenString() }); exchange.setComplete(); } } }
@Override public void receiveResponse(Exchange exchange, Response response) { if (!response.getOptions().hasObserve() && !exchange.getCurrentRequest().isMulticast()) exchange.setComplete(); if (deliverer != null) { deliverer.deliverResponse(exchange, response); // notify request that response has arrived } else { LOGGER.severe("Top of CoAP stack has no deliverer to deliver response"); } }
@Override public void sendResponse(Exchange exchange, Response response) { if (response.getDestination() == null) throw new NullPointerException("Response has no destination address"); if (response.getDestinationPort() == 0) throw new NullPointerException("Response has no destination port"); matcher.sendResponse(exchange, response); /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) interceptor.sendResponse(response); // MessageInterceptor might have canceled if (response.isCanceled()) { if (null != exchange) { exchange.setComplete(); } } else { connector.send(serializer.serialize(response)); } }
@Override public void sendEmptyMessage(Exchange exchange, EmptyMessage message) { if (message.getDestination() == null) throw new NullPointerException("Message has no destination address"); if (message.getDestinationPort() == 0) throw new NullPointerException("Message has no destination port"); matcher.sendEmptyMessage(exchange, message); /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) interceptor.sendEmptyMessage(message); // MessageInterceptor might have canceled if (message.isCanceled()) { if (null != exchange) { exchange.setComplete(); } } else { connector.send(serializer.serialize(message)); } } }
/** * Cancel this observe relation. This methods invokes the cancel methods of * the resource and the endpoint. */ public void cancel() { LOGGER.log(Level.FINE, "Canceling observe relation {0} with {1}", new Object[]{getKey(), resource.getURI()}); // stop ongoing retransmissions if (exchange.getResponse()!=null) exchange.getResponse().cancel(); setEstablished(false); resource.removeObserveRelation(this); endpoint.removeObserveRelation(this); exchange.setComplete(); }
/** * Cancel this observe relation. This methods invokes the cancel methods of * the resource and the endpoint. */ public void cancel() { LOGGER.fine("Canceling observe relation "+getKey()+" with "+resource.getURI()); // stop ongoing retransmissions if (exchange.getResponse()!=null) exchange.getResponse().cancel(); setEstablished(false); resource.removeObserveRelation(this); endpoint.removeObserveRelation(this); exchange.setComplete(); }
exchange.setComplete(); } else { connector.send(serializer.serialize(request));
@Override public void sendResponse(Exchange exchange, Response response) { assertMessageHasDestinationAddress(response); matcher.sendResponse(exchange, response); /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.sendResponse(response); } // MessageInterceptor might have canceled if (response.isCanceled()) { if (null != exchange) { exchange.setComplete(); } } else { connector.send(serializer.serializeResponse(response)); } }
@Override public void sendEmptyMessage(Exchange exchange, EmptyMessage message) { assertMessageHasDestinationAddress(message); matcher.sendEmptyMessage(exchange, message); /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.sendEmptyMessage(message); } // MessageInterceptor might have canceled if (message.isCanceled()) { if (null != exchange) { exchange.setComplete(); } } else { connector.send(serializer.serializeEmptyMessage(message)); } }
exchange.setComplete();
exchange.setComplete();
/** * Verifies that canceling a message that has no MID set does not throw an exception. * */ @Test public void testExchangeObserverToleratesUnsentMessages() { // GIVEN a request that has no MID and has not been sent yet UdpMatcher matcher = newMatcher(false); Request request = Request.newGet(); request.setDestination(dest.getAddress()); request.setDestinationPort(dest.getPort()); Exchange exchange = new Exchange(request, Origin.LOCAL); exchange.setRequest(request); assertFalse(request.hasMID()); matcher.observe(exchange); // WHEN the request is canceled and thus the message exchange completes exchange.setComplete(); // THEN the matcher's exchange observer does not throw an exception }