/** * Formats a {@link CoapResponse} into a readable String representation. * * @param r the CoapResponse * @return the pretty print */ public static String prettyPrint(CoapResponse r) { return prettyPrint(r.advanced()); }
/** * Marks the relation as canceled and invokes the the handler's failed() * method. */ @Override protected void failed() { relation.setCanceled(true); super.failed(); } }
public CaliforniumHandler() { super(System.out, new CaliforniumFormatter()); this.setLevel(Level.ALL); }
@Override public ServerInterface newServer(NetworkConfig config, int... ports) { CoapServer server = new CoapServer(config, ports); return server; } };
@Override public synchronized void stop() { if (!started) return; started = false; // If we have no endpoint this means that we never start coap server if (currentEndpoint == null) return; coapServer.stop(); }
/** * Creates a {@link CoapClient} that uses the same executor as this resource * and one of the endpoints that this resource belongs to. If no executor is * defined by this resource or any parent, the client will not have an * executor (it still works). If this resource is not yet added to a server * or the server has no endpoints, the client has no specific endpoint and * will use Californium's default endpoint. * * @param uri the URI string * @return the CoAP client */ public CoapClient createClient(String uri) { return createClient().setURI(uri); }
/** * Performs a CoAP ping using the default timeout for requests. * * @return success of the ping */ public boolean ping() { return ping(this.timeout); }
@Override public void run() { reregister(); } }, timeout, TimeUnit.MILLISECONDS);
@Override public void onResponse(final Response response) { succeeded(response != null ? new CoapResponse(response) : null); }
/** * Sends an advanced synchronous request that has to be configured by the developer. * * @param request the custom request * @return the CoAP response */ public CoapResponse advanced(Request request) { assignClientUriIfEmpty(request); return synchronous(request); }
/** * Sends an advanced asynchronous request that has to be configured by the * developer. * @param handler the response handler * @param request the custom request */ public void advanced(CoapHandler handler, Request request) { assignClientUriIfEmpty(request); asynchronous(request, handler); }
/** * Creates a root for this server. Can be overridden to create another root. * * @return the resource */ protected Resource createRoot() { return new RootResource(); }
/** * Marks this relation as canceled. * * @param canceled true if this relation has been canceled */ protected void setCanceled(boolean canceled) { this.canceled = canceled; if (this.canceled) { setReregistrationHandle(null); } }
@Override public ExecutorService getExecutor() { if (executor != null) return executor; else return super.getExecutor(); }
/** * Formats a {@link CoapResponse} into a readable String representation. * * @param r the CoapResponse * @return the pretty print */ public static String prettyPrint(CoapResponse r) { return prettyPrint(r.advanced()); }
/** * Creates a {@link CoapClient} that uses the same executor as this resource * and one of the endpoints that this resource belongs to. If no executor is * defined by this resource or any parent, the client will not have an * executor (it still works). If this resource is not yet added to a server * or the server has no endpoints, the client has no specific endpoint and * will use Californium's default endpoint. * * @param uri the URI string * @return the CoAP client */ public CoapClient createClient(String uri) { return createClient().setURI(uri); }
public CaliforniumHandler() { super(System.out, new CaliforniumFormatter()); this.setLevel(Level.ALL); }
/** * Marks the relation as canceled and invokes the the handler's failed() * method. */ @Override protected void failed() { relation.setCanceled(true); super.failed(); } }
@Override public void onResponse(final Response response) { succeeded(response != null ? new CoapResponse(response) : null); }
/** * Creates a root for this server. Can be overridden to create another root. * * @return the resource */ protected Resource createRoot() { return new RootResource(); }