private void receiveEmptyMessage(final EmptyMessage message, final RawData raw) { /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.receiveEmptyMessage(message); } // MessageInterceptor might have canceled if (!message.isCanceled()) { // CoAP Ping if (message.getType() == Type.CON || message.getType() == Type.NON) { LOGGER.log(Level.FINER, "responding to ping from {0}", raw.getInetSocketAddress()); reject(message); } else { Exchange exchange = matcher.receiveEmptyMessage(message); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); coapstack.receiveEmptyMessage(exchange, message); } } } } }
private void reject(Message message) { EmptyMessage rst = EmptyMessage.newRST(message); // sending directly through connector, not stack, thus set token rst.setToken(new byte[0]); for (MessageInterceptor interceptor:interceptors) interceptor.sendEmptyMessage(rst); // MessageInterceptor might have canceled if (!rst.isCanceled()) connector.send(serializer.serialize(rst)); }
interceptor.sendRequest(request);
rst.setDestinationPort(raw.getPort()); for (MessageInterceptor interceptor:interceptors) interceptor.sendEmptyMessage(rst); connector.send(serializer.serialize(rst)); log.append(" and reset"); interceptor.receiveRequest(request); interceptor.receiveResponse(response); interceptor.receiveEmptyMessage(message);
@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)); } }
private void receiveResponse(final Response response, final RawData raw) { /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.receiveResponse(response); } // MessageInterceptor might have canceled if (!response.isCanceled()) { Exchange exchange = matcher.receiveResponse(response, raw.getCorrelationContext()); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); response.setRTT(System.currentTimeMillis() - exchange.getTimestamp()); coapstack.receiveResponse(exchange, response); } else if (response.getType() != Type.ACK) { LOGGER.log(Level.FINE, "Rejecting unmatchable response from {0}", raw.getInetSocketAddress()); reject(response); } } }
private void receiveRequest(final Request request, final RawData raw) { // set request attributes from raw data request.setScheme(raw.isSecure() ? CoAP.COAP_SECURE_URI_SCHEME : CoAP.COAP_URI_SCHEME); request.setSenderIdentity(raw.getSenderIdentity()); /* * Logging here causes significant performance loss. * If necessary, add an interceptor that logs the messages, * e.g., the MessageTracer. */ for (MessageInterceptor interceptor:interceptors) { interceptor.receiveRequest(request); } // MessageInterceptor might have canceled if (!request.isCanceled()) { Exchange exchange = matcher.receiveRequest(request); if (exchange != null) { exchange.setEndpoint(CoapEndpoint.this); coapstack.receiveRequest(exchange, 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) { 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)); } } }
messageInterceptor.sendRequest(request);
@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)); } }