public ObserveRelation getObserveRelation(byte[] token) { for (ObserveRelation relation:relations) { if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) { return relation; } } return null; } }
public ObserveRelation getObserveRelation(byte[] token) { for (ObserveRelation relation:relations) { if (Arrays.equals(relation.getExchange().getRequest().getToken(), token)) { return relation; } } return null; } }
@Override public boolean accept(ObserveRelation relation) { String relationURI = relation.getExchange().getRequest().getOptions().getUriPathString(); boolean result = relationURI.equals(notifyURI); if (LOG.isTraceEnabled()) { LOG.trace("observe " + relationURI + " / " + notifyURI + ": " + result); } return result; }
private void removeNotificationsOf(final ObserveRelation relation) { LOGGER.log(Level.FINE, "Removing all remaining NON-notifications of observe relation with {0}", relation.getSource()); for (Iterator<Response> iterator = relation.getNotificationIterator(); iterator.hasNext(); ) { Response previous = iterator.next(); // notifications are local MID namespace if (previous.hasMID()) { KeyMID idByMID = KeyMID.fromOutboundMessage(previous); exchangeStore.remove(idByMID, relation.getExchange()); } else { previous.cancel(); } iterator.remove(); } }
@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 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(); }
/** * Remove all observe relations to CoAP clients and notify them that the * observe relation has been canceled. * * @param code * the error code why the relation was terminated * (e.g., 4.04 after deletion) */ public void clearAndNotifyObserveRelations(ResponseCode code) { /* * draft-ietf-core-observe-08, chapter 3.2 Notification states: * In the event that the resource changes in a way that would cause * a normal GET request at that time to return a non-2.xx response * (for example, when the resource is deleted), the server sends a * notification with a matching response code and removes the client * from the list of observers. * This method is called, when the resource is deleted. */ for (ObserveRelation relation:observeRelations) { relation.cancel(); relation.getExchange().sendResponse(new Response(code)); } }
/** * Remove all observe relations to CoAP clients and notify them that the * observe relation has been canceled. * * @param code * the error code why the relation was terminated * (e.g., 4.04 after deletion) */ public void clearAndNotifyObserveRelations(ResponseCode code) { /* * draft-ietf-core-observe-08, chapter 3.2 Notification states: * In the event that the resource changes in a way that would cause * a normal GET request at that time to return a non-2.xx response * (for example, when the resource is deleted), the server sends a * notification with a matching response code and removes the client * from the list of observers. * This method is called, when the resource is deleted. */ for (ObserveRelation relation:observeRelations) { relation.cancel(); relation.getExchange().sendResponse(new Response(code)); } }