/** * Method that checks if the lifetime allowed for the response if expired. * The result is calculated with the initial timestamp (when the response * has been received) and the max-age option compared against the current * timestamp. If the max-age option is not specified, it will be assumed the * default (60 seconds). * * @param response * the response * @param currentTime * @return true, if is expired */ private long getRemainingLifetime(Response response, long currentTime) { // get the timestamp long arriveTime = response.getTimestamp(); Long maxAgeOption = response.getOptions().getMaxAge(); long oldMaxAge = OptionNumberRegistry.Defaults.MAX_AGE; if (maxAgeOption != null) { oldMaxAge = maxAgeOption.longValue(); } // calculate the time that the response has spent in the cache double secondsInCache = TimeUnit.NANOSECONDS.toSeconds(currentTime - arriveTime); int cacheTime = Ints.checkedCast(Math.round(secondsInCache)); return oldMaxAge - cacheTime; }
/** * Method that checks if the lifetime allowed for the response if expired. * The result is calculated with the initial timestamp (when the response * has been received) and the max-age option compared against the current * timestamp. If the max-age option is not specified, it will be assumed the * default (60 seconds). * * @param response * the response * @param currentTime * @return true, if is expired */ private long getRemainingLifetime(Response response, long currentTime) { // get the timestamp long arriveTime = response.getTimestamp(); Long maxAgeOption = response.getOptions().getMaxAge(); long oldMaxAge = OptionNumberRegistry.Defaults.MAX_AGE; if (maxAgeOption != null) { oldMaxAge = maxAgeOption.longValue(); } // calculate the time that the response has spent in the cache double secondsInCache = TimeUnit.NANOSECONDS.toSeconds(currentTime - arriveTime); int cacheTime = Ints.checkedCast(Math.round(secondsInCache)); return oldMaxAge - cacheTime; }
private void prepareReregistration(CoapResponse response, long backoff) { if (!isCanceled()) { long timeout = response.getOptions().getMaxAge() * 1000 + backoff; ScheduledFuture<?> f = scheduler.schedule(new Runnable() { @Override public void run() { reregister(); } }, timeout, TimeUnit.MILLISECONDS); setReregistrationHandle(f); } } }
@Override public void onLoad(CoapResponse response) { OptionSet os = response.getOptions(); nextExpectedMessage = os.getMaxAge() * 2 + (System.currentTimeMillis() / 1000); postStreamElement(new Serializable[]{response.getPayload()}); }
private void prepareReregistration(CoapResponse response, long backoff) { if (!isCanceled()) { long timeout = response.getOptions().getMaxAge() * 1000 + backoff; ScheduledFuture<?> f = scheduler.schedule(new Runnable() { @Override public void run() { reregister(); } }, timeout, TimeUnit.MILLISECONDS); setReregistrationHandle(f); } } }
/** * Checks for Max-Age option. * * @param response * the response * @return true, if successful */ protected boolean hasMaxAge(Response response) { // boolean success = // response.hasOption(OptionNumberRegistry.MAX_AGE); boolean success = response.getOptions().hasMaxAge(); if (!success) { System.out.println("FAIL: Response without Max-Age"); } else { System.out.printf("PASS: Max-Age (%s)\n", response.getOptions() .getMaxAge()); } return success; }
success &= hasObserve(response); time = response.getOptions().getMaxAge() * 1000; System.out.println("+++++ Max-Age: "+time+" +++++"); if (time==0) time = 5000;
long timeout = relation4.getCurrent().getOptions().getMaxAge(); try { Thread.sleep(6*1000); } catch (InterruptedException e) { } System.out.println("---------------\nReboot Server");
time = response.getOptions().getMaxAge() * 1000; System.out.println("+++++ Max-Age: "+time+" +++++"); if (time==0) time = 5000;
success &= hasObserve(response); time = response.getOptions().getMaxAge() * 1000; System.out.println("+++++ Max-Age: "+time+" +++++"); if (time==0) time = 5000;
success &= hasObserve(response); time = response.getOptions().getMaxAge() * 1000; System.out.println("+++++ Max-Age: "+time+" +++++"); if (time==0) time = 5000;
long time = response.getOptions().getMaxAge() * 1000;
options.add(new Option(OptionNumberRegistry.CONTENT_FORMAT, getContentFormat())); if (hasMaxAge()) options.add(new Option(OptionNumberRegistry.MAX_AGE, getMaxAge())); if (uri_query_list != null) for (String str:uri_query_list) options.add(new Option(OptionNumberRegistry.URI_QUERY, str));
options.add(new Option(OptionNumberRegistry.CONTENT_FORMAT, getContentFormat())); if (hasMaxAge()) options.add(new Option(OptionNumberRegistry.MAX_AGE, getMaxAge())); if (uri_query_list != null) for (String str:uri_query_list) options.add(new Option(OptionNumberRegistry.URI_QUERY, str));