@Override public void sendRequest(Exchange exchange, final Request request) { exchange.setObserver(exchangeObserver); exchangeStore.registerOutboundRequestWithTokenOnly(exchange); LOGGER.log(Level.FINE, "Tracking open request using {0}", new Object[] { request.getTokenString() }); }
/** * Constructs a new observe relation. * * @param endpoint the observing endpoint * @param resource the observed resource * @param exchange the exchange that tries to establish the observe relation */ public ObserveRelation(ObservingEndpoint endpoint, Resource resource, Exchange exchange) { if (endpoint == null) throw new NullPointerException(); if (resource == null) throw new NullPointerException(); if (exchange == null) throw new NullPointerException(); this.endpoint = endpoint; this.resource = resource; this.exchange = exchange; this.established = false; this.key = getSource().toString() + "#" + exchange.getRequest().getTokenString(); }
/** * Constructs a new observe relation. * * @param endpoint the observing endpoint * @param resource the observed resource * @param exchange the exchange that tries to establish the observe relation */ public ObserveRelation(ObservingEndpoint endpoint, Resource resource, Exchange exchange) { if (endpoint == null) throw new NullPointerException(); if (resource == null) throw new NullPointerException(); if (exchange == null) throw new NullPointerException(); this.endpoint = endpoint; this.resource = resource; this.exchange = exchange; this.established = false; this.key = getSource().toString() + "#" + exchange.getRequest().getTokenString(); }
@Override public void sendRequest(final Exchange exchange, final Request request) { observe(exchange); exchangeStore.registerOutboundRequest(exchange); if (LOGGER.isLoggable(Level.FINER)) { LOGGER.log( Level.FINER, "Tracking open request [MID: {0}, Token: {1}]", new Object[] { request.getMID(), request.getTokenString() }); } }
/** * Formats a {@link Request} into a readable String representation. * * @param r the Request * @return the pretty print */ public static String prettyPrint(Request r) { StringBuilder sb = new StringBuilder(); sb.append("==[ CoAP Request ]=============================================").append(System.lineSeparator()); sb.append(String.format("MID : %d", r.getMID())).append(System.lineSeparator()); sb.append(String.format("Token : %s", r.getTokenString())).append(System.lineSeparator()); sb.append(String.format("Type : %s", r.getType().toString())).append(System.lineSeparator()); sb.append(String.format("Method : %s", r.getCode().toString())).append(System.lineSeparator()); sb.append(String.format("Options: %s", r.getOptions().toString())).append(System.lineSeparator()); sb.append(String.format("Payload: %d Bytes", r.getPayloadSize())).append(System.lineSeparator()); if (r.getPayloadSize() > 0 && MediaTypeRegistry.isPrintable(r.getOptions().getContentFormat())) { sb.append("---------------------------------------------------------------").append(System.lineSeparator()); sb.append(r.getPayloadString()); sb.append(System.lineSeparator()); } sb.append("==============================================================="); return sb.toString(); }
/** * Formats a {@link Request} into a readable String representation. * * @param r the Request * @return the pretty print */ public static String prettyPrint(Request r) { StringBuilder sb = new StringBuilder(); sb.append("==[ CoAP Request ]=============================================").append(System.lineSeparator()); sb.append(String.format("MID : %d", r.getMID())).append(System.lineSeparator()); sb.append(String.format("Token : %s", r.getTokenString())).append(System.lineSeparator()); sb.append(String.format("Type : %s", r.getType().toString())).append(System.lineSeparator()); sb.append(String.format("Method : %s", r.getCode().toString())).append(System.lineSeparator()); sb.append(String.format("Options: %s", r.getOptions().toString())).append(System.lineSeparator()); sb.append(String.format("Payload: %d Bytes", r.getPayloadSize())).append(System.lineSeparator()); if (r.getPayloadSize() > 0 && MediaTypeRegistry.isPrintable(r.getOptions().getContentFormat())) { sb.append("---------------------------------------------------------------").append(System.lineSeparator()); sb.append(r.getPayloadString()); sb.append(System.lineSeparator()); } sb.append("==============================================================="); return sb.toString(); }
/** * Reactive Observe cancellation: Cancel the observe relation by forgetting, * which will trigger a RST. For TCP, {{@link #proactiveCancel()} will be * executed. */ public void reactiveCancel() { Request request = this.request; if (CoAP.isTcpScheme(request.getScheme())) { LOGGER.log(Level.INFO, "Change to cancel the observe {0} proactive over TCP.", request.getTokenString()); proactiveCancel(); } else { // cancel old ongoing request cancel(); } }
@Override public void onTimeout() { ObserveRelation relation = exchange.getRelation(); LOGGER.log( Level.INFO, "Notification for token [{0}] timed out. Canceling all relations with source [{1}]", new Object[]{ relation.getExchange().getRequest().getTokenString(), relation.getSource() }); relation.cancelAll(); }
@Override public String toString() { String payload = getPayloadTracingString(); return String.format("%s-%-6s MID=%5d, Token=%s, OptionSet=%s, %s", getType(), getCode(), getMID(), getTokenString(), getOptions(), payload); }
@Override public String toString() { String payload = getPayloadTracingString(); return String.format("%s-%-6s MID=%5d, Token=%s, OptionSet=%s, %s", getType(), getCode(), getMID(), getTokenString(), getOptions(), payload); }
@Override public void onTimeout() { ObserveRelation relation = exchange.getRelation(); LOGGER.info("Notification " + relation.getExchange().getRequest().getTokenString() + " timed out. Cancel all relations with source " + relation.getSource()); relation.cancelAll(); }
@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(); } } }
public CoapMessage(Request request, boolean incoming) { this(incoming, request.getType(), request.getMID(), request.getTokenString(), request.getOptions(), request .getPayload()); this.code = request.getCode().toString(); }
payload.append(request.getTokenString());
protected final void appendRequestDetails(final Request request) { if (request.isCanceled()) { buffer.append("CANCELED "); } buffer.append(request.getType()).append(" [MID=").append(request.getMID()) .append(", T=").append(request.getTokenString()).append("], ") .append(request.getCode()).append(", /").append(request.getOptions().getUriPathString()); appendBlockOption(1, request.getOptions().getBlock1()); appendBlockOption(2, request.getOptions().getBlock2()); appendObserveOption(request.getOptions()); appendSize1(request.getOptions()); appendEtags(request.getOptions()); }
Request request = this.request; if (request.isCanceled()) { throw new IllegalStateException("observe request already canceled! token " + request.getTokenString());
Request request = this.request; if (request.isCanceled()) { throw new IllegalStateException("observe request already canceled! token " + request.getTokenString());