use of org.eclipse.californium.core.observe.ObserveRelation in project thingsboard by thingsboard.
the class CoapTransportResource method checkObserveRelation.
/*
* Overwritten method from CoapResource to be able to manage our own observe notification counters.
*/
@Override
public void checkObserveRelation(Exchange exchange, Response response) {
String token = getTokenFromRequest(exchange.getRequest());
final ObserveRelation relation = exchange.getRelation();
if (relation == null || relation.isCanceled()) {
// because request did not try to establish a relation
return;
}
if (response.getCode().isSuccess()) {
if (!relation.isEstablished()) {
relation.setEstablished();
addObserveRelation(relation);
}
AtomicInteger state = clients.getNotificationCounterByToken(token);
if (state != null) {
response.getOptions().setObserve(state.getAndIncrement());
} else {
response.getOptions().removeObserve();
}
}
// ObserveLayer takes care of the else case
}
use of org.eclipse.californium.core.observe.ObserveRelation in project thingsboard by thingsboard.
the class LwM2mTransportCoapResource method checkObserveRelation.
@Override
public void checkObserveRelation(Exchange exchange, Response response) {
String token = getTokenFromRequest(exchange.getRequest());
final ObserveRelation relation = exchange.getRelation();
if (relation == null || relation.isCanceled()) {
// because request did not try to establish a relation
return;
}
if (response.getCode().isSuccess()) {
if (!relation.isEstablished()) {
relation.setEstablished();
addObserveRelation(relation);
}
AtomicInteger notificationCounter = tokenToObserveNotificationSeqMap.computeIfAbsent(token, s -> new AtomicInteger(0));
response.getOptions().setObserve(notificationCounter.getAndIncrement());
}
// ObserveLayer takes care of the else case
}
Aggregations