Merge pull request #4770 from ShvaykaD/fix/coap-transport/obesrve-sessions
CoAP: Updated observe sessions closing logic
This commit is contained in:
commit
3d3cb1f16c
@ -65,6 +65,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CoapTransportResource extends AbstractCoapTransportResource {
|
public class CoapTransportResource extends AbstractCoapTransportResource {
|
||||||
@ -76,9 +77,8 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
private static final int REQUEST_ID_POSITION_CERTIFICATE_REQUEST = 4;
|
private static final int REQUEST_ID_POSITION_CERTIFICATE_REQUEST = 4;
|
||||||
private static final String DTLS_SESSION_ID_KEY = "DTLS_SESSION_ID";
|
private static final String DTLS_SESSION_ID_KEY = "DTLS_SESSION_ID";
|
||||||
|
|
||||||
private final ConcurrentMap<String, TransportProtos.SessionInfoProto> tokenToSessionInfoMap = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, CoapObserveSessionInfo> tokenToCoapSessionInfoMap = new ConcurrentHashMap<>();
|
||||||
private final ConcurrentMap<String, AtomicInteger> tokenToObserveNotificationSeqMap = new ConcurrentHashMap<>();
|
private final ConcurrentMap<CoapObserveSessionInfo, ObserveRelation> sessionInfoToObserveRelationMap = new ConcurrentHashMap<>();
|
||||||
private final ConcurrentMap<TransportProtos.SessionInfoProto, ObserveRelation> sessionInfoToObserveRelationMap = new ConcurrentHashMap<>();
|
|
||||||
private final Set<UUID> rpcSubscriptions = ConcurrentHashMap.newKeySet();
|
private final Set<UUID> rpcSubscriptions = ConcurrentHashMap.newKeySet();
|
||||||
private final Set<UUID> attributeSubscriptions = ConcurrentHashMap.newKeySet();
|
private final Set<UUID> attributeSubscriptions = ConcurrentHashMap.newKeySet();
|
||||||
|
|
||||||
@ -94,7 +94,11 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
this.timeout = coapServerService.getTimeout();
|
this.timeout = coapServerService.getTimeout();
|
||||||
this.sessionReportTimeout = ctx.getSessionReportTimeout();
|
this.sessionReportTimeout = ctx.getSessionReportTimeout();
|
||||||
ctx.getScheduler().scheduleAtFixedRate(() -> {
|
ctx.getScheduler().scheduleAtFixedRate(() -> {
|
||||||
Set<TransportProtos.SessionInfoProto> observeSessions = sessionInfoToObserveRelationMap.keySet();
|
Set<CoapObserveSessionInfo> coapObserveSessionInfos = sessionInfoToObserveRelationMap.keySet();
|
||||||
|
Set<TransportProtos.SessionInfoProto> observeSessions = coapObserveSessionInfos
|
||||||
|
.stream()
|
||||||
|
.map(CoapObserveSessionInfo::getSessionInfoProto)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
observeSessions.forEach(this::reportActivity);
|
observeSessions.forEach(this::reportActivity);
|
||||||
}, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS);
|
}, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
@ -112,17 +116,17 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
relation.setEstablished();
|
relation.setEstablished();
|
||||||
addObserveRelation(relation);
|
addObserveRelation(relation);
|
||||||
}
|
}
|
||||||
AtomicInteger notificationCounter = tokenToObserveNotificationSeqMap.computeIfAbsent(token, s -> new AtomicInteger(0));
|
AtomicInteger observeNotificationCounter = tokenToCoapSessionInfoMap.get(token).getObserveNotificationCounter();
|
||||||
response.getOptions().setObserve(notificationCounter.getAndIncrement());
|
response.getOptions().setObserve(observeNotificationCounter.getAndIncrement());
|
||||||
} // ObserveLayer takes care of the else case
|
} // ObserveLayer takes care of the else case
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearAndNotifyObserveRelation(ObserveRelation relation, CoAP.ResponseCode code) {
|
private void clearAndNotifyObserveRelation(ObserveRelation relation, CoAP.ResponseCode code) {
|
||||||
relation.cancel();
|
relation.cancel();
|
||||||
relation.getExchange().sendResponse(new Response(code));
|
relation.getExchange().sendResponse(new Response(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<TransportProtos.SessionInfoProto, ObserveRelation> getSessionInfoToObserveRelationMap() {
|
private Map<CoapObserveSessionInfo, ObserveRelation> getCoapSessionInfoToObserveRelationMap() {
|
||||||
return sessionInfoToObserveRelationMap;
|
return sessionInfoToObserveRelationMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,8 +282,8 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
new CoapOkCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
|
new CoapOkCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
|
||||||
break;
|
break;
|
||||||
case SUBSCRIBE_ATTRIBUTES_REQUEST:
|
case SUBSCRIBE_ATTRIBUTES_REQUEST:
|
||||||
TransportProtos.SessionInfoProto currentAttrSession = tokenToSessionInfoMap.get(getTokenFromRequest(request));
|
CoapObserveSessionInfo currentCoapObserveAttrSessionInfo = tokenToCoapSessionInfoMap.get(getTokenFromRequest(request));
|
||||||
if (currentAttrSession == null) {
|
if (currentCoapObserveAttrSessionInfo == null) {
|
||||||
attributeSubscriptions.add(sessionId);
|
attributeSubscriptions.add(sessionId);
|
||||||
registerAsyncCoapSession(exchange, sessionInfo, coapTransportAdaptor,
|
registerAsyncCoapSession(exchange, sessionInfo, coapTransportAdaptor,
|
||||||
transportConfigurationContainer.getRpcRequestDynamicMessageBuilder(), getTokenFromRequest(request));
|
transportConfigurationContainer.getRpcRequestDynamicMessageBuilder(), getTokenFromRequest(request));
|
||||||
@ -291,20 +295,20 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBSCRIBE_ATTRIBUTES_REQUEST:
|
case UNSUBSCRIBE_ATTRIBUTES_REQUEST:
|
||||||
TransportProtos.SessionInfoProto attrSession = lookupAsyncSessionInfo(getTokenFromRequest(request));
|
CoapObserveSessionInfo coapObserveAttrSessionInfo = lookupAsyncSessionInfo(getTokenFromRequest(request));
|
||||||
if (attrSession != null) {
|
if (coapObserveAttrSessionInfo != null) {
|
||||||
|
TransportProtos.SessionInfoProto attrSession = coapObserveAttrSessionInfo.getSessionInfoProto();
|
||||||
UUID attrSessionId = toSessionId(attrSession);
|
UUID attrSessionId = toSessionId(attrSession);
|
||||||
attributeSubscriptions.remove(attrSessionId);
|
attributeSubscriptions.remove(attrSessionId);
|
||||||
sessionInfoToObserveRelationMap.remove(attrSession);
|
|
||||||
transportService.process(attrSession,
|
transportService.process(attrSession,
|
||||||
TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().setUnsubscribe(true).build(),
|
TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().setUnsubscribe(true).build(),
|
||||||
new CoapOkCallback(exchange, CoAP.ResponseCode.DELETED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
|
new CoapNoOpCallback(exchange));
|
||||||
closeAndDeregister(sessionInfo);
|
|
||||||
}
|
}
|
||||||
|
closeAndDeregister(sessionInfo);
|
||||||
break;
|
break;
|
||||||
case SUBSCRIBE_RPC_COMMANDS_REQUEST:
|
case SUBSCRIBE_RPC_COMMANDS_REQUEST:
|
||||||
TransportProtos.SessionInfoProto currentRpcSession = tokenToSessionInfoMap.get(getTokenFromRequest(request));
|
CoapObserveSessionInfo currentCoapObserveRpcSessionInfo = tokenToCoapSessionInfoMap.get(getTokenFromRequest(request));
|
||||||
if (currentRpcSession == null) {
|
if (currentCoapObserveRpcSessionInfo == null) {
|
||||||
rpcSubscriptions.add(sessionId);
|
rpcSubscriptions.add(sessionId);
|
||||||
registerAsyncCoapSession(exchange, sessionInfo, coapTransportAdaptor,
|
registerAsyncCoapSession(exchange, sessionInfo, coapTransportAdaptor,
|
||||||
transportConfigurationContainer.getRpcRequestDynamicMessageBuilder(), getTokenFromRequest(request));
|
transportConfigurationContainer.getRpcRequestDynamicMessageBuilder(), getTokenFromRequest(request));
|
||||||
@ -315,16 +319,16 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBSCRIBE_RPC_COMMANDS_REQUEST:
|
case UNSUBSCRIBE_RPC_COMMANDS_REQUEST:
|
||||||
TransportProtos.SessionInfoProto rpcSession = lookupAsyncSessionInfo(getTokenFromRequest(request));
|
CoapObserveSessionInfo coapObserveRpcSessionInfo = lookupAsyncSessionInfo(getTokenFromRequest(request));
|
||||||
if (rpcSession != null) {
|
if (coapObserveRpcSessionInfo != null) {
|
||||||
|
TransportProtos.SessionInfoProto rpcSession = coapObserveRpcSessionInfo.getSessionInfoProto();
|
||||||
UUID rpcSessionId = toSessionId(rpcSession);
|
UUID rpcSessionId = toSessionId(rpcSession);
|
||||||
rpcSubscriptions.remove(rpcSessionId);
|
rpcSubscriptions.remove(rpcSessionId);
|
||||||
sessionInfoToObserveRelationMap.remove(rpcSession);
|
|
||||||
transportService.process(rpcSession,
|
transportService.process(rpcSession,
|
||||||
TransportProtos.SubscribeToRPCMsg.newBuilder().setUnsubscribe(true).build(),
|
TransportProtos.SubscribeToRPCMsg.newBuilder().setUnsubscribe(true).build(),
|
||||||
new CoapOkCallback(exchange, CoAP.ResponseCode.DELETED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
|
new CoapOkCallback(exchange, CoAP.ResponseCode.DELETED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
|
||||||
closeAndDeregister(sessionInfo);
|
|
||||||
}
|
}
|
||||||
|
closeAndDeregister(sessionInfo);
|
||||||
break;
|
break;
|
||||||
case TO_DEVICE_RPC_RESPONSE:
|
case TO_DEVICE_RPC_RESPONSE:
|
||||||
transportService.process(sessionInfo,
|
transportService.process(sessionInfo,
|
||||||
@ -356,13 +360,12 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
|
return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransportProtos.SessionInfoProto lookupAsyncSessionInfo(String token) {
|
private CoapObserveSessionInfo lookupAsyncSessionInfo(String token) {
|
||||||
tokenToObserveNotificationSeqMap.remove(token);
|
return tokenToCoapSessionInfoMap.remove(token);
|
||||||
return tokenToSessionInfoMap.remove(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAsyncCoapSession(CoapExchange exchange, TransportProtos.SessionInfoProto sessionInfo, CoapTransportAdaptor coapTransportAdaptor, DynamicMessage.Builder rpcRequestDynamicMessageBuilder, String token) {
|
private void registerAsyncCoapSession(CoapExchange exchange, TransportProtos.SessionInfoProto sessionInfo, CoapTransportAdaptor coapTransportAdaptor, DynamicMessage.Builder rpcRequestDynamicMessageBuilder, String token) {
|
||||||
tokenToSessionInfoMap.putIfAbsent(token, sessionInfo);
|
tokenToCoapSessionInfoMap.putIfAbsent(token, new CoapObserveSessionInfo(sessionInfo));
|
||||||
transportService.registerAsyncSession(sessionInfo, getCoapSessionListener(exchange, coapTransportAdaptor, rpcRequestDynamicMessageBuilder, sessionInfo));
|
transportService.registerAsyncSession(sessionInfo, getCoapSessionListener(exchange, coapTransportAdaptor, rpcRequestDynamicMessageBuilder, sessionInfo));
|
||||||
transportService.process(sessionInfo, getSessionEventMsg(TransportProtos.SessionEvent.OPEN), null);
|
transportService.process(sessionInfo, getSessionEventMsg(TransportProtos.SessionEvent.OPEN), null);
|
||||||
}
|
}
|
||||||
@ -477,45 +480,36 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttributeUpdate(TransportProtos.AttributeUpdateNotificationMsg msg) {
|
public void onAttributeUpdate(UUID sessionId, TransportProtos.AttributeUpdateNotificationMsg msg) {
|
||||||
|
log.trace("[{}] Received attributes update notification to device", sessionId);
|
||||||
try {
|
try {
|
||||||
exchange.respond(coapTransportAdaptor.convertToPublish(isConRequest(), msg));
|
exchange.respond(coapTransportAdaptor.convertToPublish(isConRequest(), msg));
|
||||||
} catch (AdaptorException e) {
|
} catch (AdaptorException e) {
|
||||||
log.trace("Failed to reply due to error", e);
|
log.trace("Failed to reply due to error", e);
|
||||||
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
|
closeObserveRelationAndNotify(sessionId, CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
|
||||||
|
closeAndDeregister();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoteSessionCloseCommand(UUID sessionId, TransportProtos.SessionCloseNotificationProto sessionCloseNotification) {
|
public void onRemoteSessionCloseCommand(UUID sessionId, TransportProtos.SessionCloseNotificationProto sessionCloseNotification) {
|
||||||
log.trace("[{}] Received the remote command to close the session: {}", sessionId, sessionCloseNotification.getMessage());
|
log.trace("[{}] Received the remote command to close the session: {}", sessionId, sessionCloseNotification.getMessage());
|
||||||
Map<TransportProtos.SessionInfoProto, ObserveRelation> sessionToObserveRelationMap = coapTransportResource.getSessionInfoToObserveRelationMap();
|
closeObserveRelationAndNotify(sessionId, CoAP.ResponseCode.SERVICE_UNAVAILABLE);
|
||||||
if (coapTransportResource.getObserverCount() > 0 && !CollectionUtils.isEmpty(sessionToObserveRelationMap)) {
|
closeAndDeregister();
|
||||||
Set<TransportProtos.SessionInfoProto> observeSessions = sessionToObserveRelationMap.keySet();
|
|
||||||
Optional<TransportProtos.SessionInfoProto> observeSessionToClose = observeSessions.stream().filter(sessionInfoProto -> {
|
|
||||||
UUID observeSessionId = new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
|
|
||||||
return observeSessionId.equals(sessionId);
|
|
||||||
}).findFirst();
|
|
||||||
if (observeSessionToClose.isPresent()) {
|
|
||||||
TransportProtos.SessionInfoProto sessionInfoProto = observeSessionToClose.get();
|
|
||||||
ObserveRelation observeRelation = sessionToObserveRelationMap.get(sessionInfoProto);
|
|
||||||
coapTransportResource.clearAndNotifyObserveRelation(observeRelation, CoAP.ResponseCode.SERVICE_UNAVAILABLE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg msg) {
|
public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg msg) {
|
||||||
boolean successful;
|
log.trace("[{}] Received RPC command to device", sessionId);
|
||||||
|
boolean successful = true;
|
||||||
try {
|
try {
|
||||||
exchange.respond(coapTransportAdaptor.convertToPublish(isConRequest(), msg, rpcRequestDynamicMessageBuilder));
|
exchange.respond(coapTransportAdaptor.convertToPublish(isConRequest(), msg, rpcRequestDynamicMessageBuilder));
|
||||||
successful = true;
|
|
||||||
} catch (AdaptorException e) {
|
} catch (AdaptorException e) {
|
||||||
log.trace("Failed to reply due to error", e);
|
log.trace("Failed to reply due to error", e);
|
||||||
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
|
closeObserveRelationAndNotify(sessionId, CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
|
||||||
successful = false;
|
successful = false;
|
||||||
}
|
} finally {
|
||||||
if (msg.getPersisted()) {
|
if (msg.getPersisted()) {
|
||||||
RpcStatus status;
|
RpcStatus status;
|
||||||
if (!successful) {
|
if (!successful) {
|
||||||
status = RpcStatus.FAILED;
|
status = RpcStatus.FAILED;
|
||||||
@ -531,6 +525,10 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
.setStatus(status.name())
|
.setStatus(status.name())
|
||||||
.build();
|
.build();
|
||||||
coapTransportResource.transportService.process(sessionInfo, responseMsg, TransportServiceCallback.EMPTY);
|
coapTransportResource.transportService.process(sessionInfo, responseMsg, TransportServiceCallback.EMPTY);
|
||||||
|
}
|
||||||
|
if (!successful) {
|
||||||
|
closeAndDeregister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,6 +545,30 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
private boolean isConRequest() {
|
private boolean isConRequest() {
|
||||||
return exchange.advanced().getRequest().isConfirmable();
|
return exchange.advanced().getRequest().isConfirmable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void closeObserveRelationAndNotify(UUID sessionId, CoAP.ResponseCode responseCode) {
|
||||||
|
Map<CoapObserveSessionInfo, ObserveRelation> sessionToObserveRelationMap = coapTransportResource.getCoapSessionInfoToObserveRelationMap();
|
||||||
|
if (coapTransportResource.getObserverCount() > 0 && !CollectionUtils.isEmpty(sessionToObserveRelationMap)) {
|
||||||
|
Optional<CoapObserveSessionInfo> observeSessionToClose = sessionToObserveRelationMap.keySet().stream().filter(coapObserveSessionInfo -> {
|
||||||
|
TransportProtos.SessionInfoProto sessionToDelete = coapObserveSessionInfo.getSessionInfoProto();
|
||||||
|
UUID observeSessionId = new UUID(sessionToDelete.getSessionIdMSB(), sessionToDelete.getSessionIdLSB());
|
||||||
|
return observeSessionId.equals(sessionId);
|
||||||
|
}).findFirst();
|
||||||
|
if (observeSessionToClose.isPresent()) {
|
||||||
|
CoapObserveSessionInfo coapObserveSessionInfo = observeSessionToClose.get();
|
||||||
|
ObserveRelation observeRelation = sessionToObserveRelationMap.get(coapObserveSessionInfo);
|
||||||
|
coapTransportResource.clearAndNotifyObserveRelation(observeRelation, responseCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeAndDeregister() {
|
||||||
|
Request request = exchange.advanced().getRequest();
|
||||||
|
String token = coapTransportResource.getTokenFromRequest(request);
|
||||||
|
CoapObserveSessionInfo deleted = coapTransportResource.lookupAsyncSessionInfo(token);
|
||||||
|
coapTransportResource.closeAndDeregister(deleted.getSessionInfoProto());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CoapResourceObserver implements ResourceObserver {
|
public class CoapResourceObserver implements ResourceObserver {
|
||||||
@ -571,7 +593,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
public void addedObserveRelation(ObserveRelation relation) {
|
public void addedObserveRelation(ObserveRelation relation) {
|
||||||
Request request = relation.getExchange().getRequest();
|
Request request = relation.getExchange().getRequest();
|
||||||
String token = getTokenFromRequest(request);
|
String token = getTokenFromRequest(request);
|
||||||
sessionInfoToObserveRelationMap.putIfAbsent(tokenToSessionInfoMap.get(token), relation);
|
sessionInfoToObserveRelationMap.putIfAbsent(tokenToCoapSessionInfoMap.get(token), relation);
|
||||||
log.trace("Added Observe relation for token: {}", token);
|
log.trace("Added Observe relation for token: {}", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,8 +601,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
public void removedObserveRelation(ObserveRelation relation) {
|
public void removedObserveRelation(ObserveRelation relation) {
|
||||||
Request request = relation.getExchange().getRequest();
|
Request request = relation.getExchange().getRequest();
|
||||||
String token = getTokenFromRequest(request);
|
String token = getTokenFromRequest(request);
|
||||||
TransportProtos.SessionInfoProto session = tokenToSessionInfoMap.get(token);
|
sessionInfoToObserveRelationMap.remove(tokenToCoapSessionInfoMap.get(token));
|
||||||
sessionInfoToObserveRelationMap.remove(session);
|
|
||||||
log.trace("Relation removed for token: {}", token);
|
log.trace("Relation removed for token: {}", token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,7 +612,6 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
transportService.deregisterSession(session);
|
transportService.deregisterSession(session);
|
||||||
rpcSubscriptions.remove(sessionId);
|
rpcSubscriptions.remove(sessionId);
|
||||||
attributeSubscriptions.remove(sessionId);
|
attributeSubscriptions.remove(sessionId);
|
||||||
sessionInfoToObserveRelationMap.remove(session);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TransportConfigurationContainer getTransportConfigurationContainer(DeviceProfile deviceProfile) throws AdaptorException {
|
private TransportConfigurationContainer getTransportConfigurationContainer(DeviceProfile deviceProfile) throws AdaptorException {
|
||||||
@ -657,4 +677,17 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
|
|||||||
this.jsonPayload = jsonPayload;
|
this.jsonPayload = jsonPayload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class CoapObserveSessionInfo {
|
||||||
|
|
||||||
|
private final TransportProtos.SessionInfoProto sessionInfoProto;
|
||||||
|
private final AtomicInteger observeNotificationCounter;
|
||||||
|
|
||||||
|
private CoapObserveSessionInfo(TransportProtos.SessionInfoProto sessionInfoProto) {
|
||||||
|
this.sessionInfoProto = sessionInfoProto;
|
||||||
|
this.observeNotificationCounter = new AtomicInteger(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -393,7 +393,8 @@ public class DeviceApiController implements TbTransportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttributeUpdate(AttributeUpdateNotificationMsg msg) {
|
public void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg msg) {
|
||||||
|
log.trace("[{}] Received attributes update notification to device", sessionId);
|
||||||
responseWriter.setResult(new ResponseEntity<>(JsonConverter.toJson(msg).toString(), HttpStatus.OK));
|
responseWriter.setResult(new ResponseEntity<>(JsonConverter.toJson(msg).toString(), HttpStatus.OK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +405,8 @@ public class DeviceApiController implements TbTransportService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg msg) {
|
public void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg msg) {
|
||||||
|
log.trace("[{}] Received RPC command to device", sessionId);
|
||||||
responseWriter.setResult(new ResponseEntity<>(JsonConverter.toJson(msg, true).toString(), HttpStatus.OK));
|
responseWriter.setResult(new ResponseEntity<>(JsonConverter.toJson(msg, true).toString(), HttpStatus.OK));
|
||||||
if (msg.getPersisted()) {
|
if (msg.getPersisted()) {
|
||||||
RpcStatus status;
|
RpcStatus status;
|
||||||
|
|||||||
@ -56,9 +56,10 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification) {
|
public void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg attributeUpdateNotification) {
|
||||||
|
log.trace("[{}] Received attributes update notification to device", sessionId);
|
||||||
this.attributesService.onAttributesUpdate(attributeUpdateNotification, this.sessionInfo);
|
this.attributesService.onAttributesUpdate(attributeUpdateNotification, this.sessionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoteSessionCloseCommand(UUID sessionId, SessionCloseNotificationProto sessionCloseNotification) {
|
public void onRemoteSessionCloseCommand(UUID sessionId, SessionCloseNotificationProto sessionCloseNotification) {
|
||||||
@ -81,7 +82,8 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest) {
|
public void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg toDeviceRequest) {
|
||||||
|
log.trace("[{}] Received RPC command to device", sessionId);
|
||||||
this.rpcHandler.onToDeviceRpcRequest(toDeviceRequest, this.sessionInfo);
|
this.rpcHandler.onToDeviceRpcRequest(toDeviceRequest, this.sessionInfo);
|
||||||
if (toDeviceRequest.getPersisted()) {
|
if (toDeviceRequest.getPersisted()) {
|
||||||
RpcStatus status;
|
RpcStatus status;
|
||||||
|
|||||||
@ -797,7 +797,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttributeUpdate(TransportProtos.AttributeUpdateNotificationMsg notification) {
|
public void onAttributeUpdate(UUID sessionId, TransportProtos.AttributeUpdateNotificationMsg notification) {
|
||||||
|
log.trace("[{}] Received attributes update notification to device", sessionId);
|
||||||
try {
|
try {
|
||||||
deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, notification).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush);
|
deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, notification).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -812,7 +813,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg rpcRequest) {
|
public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg rpcRequest) {
|
||||||
log.trace("[{}] Received RPC command to device", sessionId);
|
log.trace("[{}] Received RPC command to device", sessionId);
|
||||||
try {
|
try {
|
||||||
deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, rpcRequest)
|
deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, rpcRequest)
|
||||||
|
|||||||
@ -85,7 +85,8 @@ public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttributeUpdate(TransportProtos.AttributeUpdateNotificationMsg notification) {
|
public void onAttributeUpdate(UUID sessionId, TransportProtos.AttributeUpdateNotificationMsg notification) {
|
||||||
|
log.trace("[{}] Received attributes update notification to device", sessionId);
|
||||||
try {
|
try {
|
||||||
parent.getPayloadAdaptor().convertToGatewayPublish(this, getDeviceInfo().getDeviceName(), notification).ifPresent(parent::writeAndFlush);
|
parent.getPayloadAdaptor().convertToGatewayPublish(this, getDeviceInfo().getDeviceName(), notification).ifPresent(parent::writeAndFlush);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -94,7 +95,8 @@ public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg request) {
|
public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg request) {
|
||||||
|
log.trace("[{}] Received RPC command to device", sessionId);
|
||||||
try {
|
try {
|
||||||
parent.getPayloadAdaptor().convertToGatewayPublish(this, getDeviceInfo().getDeviceName(), request).ifPresent(
|
parent.getPayloadAdaptor().convertToGatewayPublish(this, getDeviceInfo().getDeviceName(), request).ifPresent(
|
||||||
payload -> {
|
payload -> {
|
||||||
|
|||||||
@ -129,7 +129,8 @@ public class DeviceSessionContext extends DeviceAwareSessionContext implements S
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification) {
|
public void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg attributeUpdateNotification) {
|
||||||
|
log.trace("[{}] Received attributes update notification to device", sessionId);
|
||||||
snmpTransportContext.getSnmpTransportService().onAttributeUpdate(this, attributeUpdateNotification);
|
snmpTransportContext.getSnmpTransportService().onAttributeUpdate(this, attributeUpdateNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +140,8 @@ public class DeviceSessionContext extends DeviceAwareSessionContext implements S
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest) {
|
public void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg toDeviceRequest) {
|
||||||
|
log.trace("[{}] Received RPC command to device", sessionId);
|
||||||
snmpTransportContext.getSnmpTransportService().onToDeviceRpcRequest(this, toDeviceRequest);
|
snmpTransportContext.getSnmpTransportService().onToDeviceRpcRequest(this, toDeviceRequest);
|
||||||
if (toDeviceRequest.getPersisted()) {
|
if (toDeviceRequest.getPersisted()) {
|
||||||
RpcStatus status;
|
RpcStatus status;
|
||||||
|
|||||||
@ -36,11 +36,11 @@ public interface SessionMsgListener {
|
|||||||
|
|
||||||
void onGetAttributesResponse(GetAttributeResponseMsg getAttributesResponse);
|
void onGetAttributesResponse(GetAttributeResponseMsg getAttributesResponse);
|
||||||
|
|
||||||
void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification);
|
void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg attributeUpdateNotification);
|
||||||
|
|
||||||
void onRemoteSessionCloseCommand(UUID sessionId, SessionCloseNotificationProto sessionCloseNotification);
|
void onRemoteSessionCloseCommand(UUID sessionId, SessionCloseNotificationProto sessionCloseNotification);
|
||||||
|
|
||||||
void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest);
|
void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg toDeviceRequest);
|
||||||
|
|
||||||
void onToServerRpcResponse(ToServerRpcResponseMsg toServerResponse);
|
void onToServerRpcResponse(ToServerRpcResponseMsg toServerResponse);
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,6 @@ import org.thingsboard.server.common.data.DeviceTransportType;
|
|||||||
import org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse;
|
import org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse;
|
||||||
import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
|
import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
|
||||||
import org.thingsboard.server.common.transport.service.SessionMetaData;
|
import org.thingsboard.server.common.transport.service.SessionMetaData;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg;
|
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceCredentialsRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceCredentialsRequestMsg;
|
||||||
@ -30,9 +28,9 @@ import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceRequestMsg;
|
|||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceResponseMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceResponseMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileResponseMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileResponseMsg;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageResponseMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageResponseMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg;
|
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetResourceRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetResourceRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetResourceResponseMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetResourceResponseMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.GetSnmpDevicesRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.GetSnmpDevicesRequestMsg;
|
||||||
@ -48,10 +46,11 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
|
|||||||
import org.thingsboard.server.gen.transport.TransportProtos.SubscribeToAttributeUpdatesMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.SubscribeToAttributeUpdatesMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.SubscribeToRPCMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.SubscribeToRPCMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.SubscriptionInfoProto;
|
import org.thingsboard.server.gen.transport.TransportProtos.SubscriptionInfoProto;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos.ToDevicePersistedRpcResponseMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ToDeviceRpcResponseMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ToDeviceRpcResponseMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ToServerRpcRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ToServerRpcRequestMsg;
|
||||||
|
import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCredRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCredRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg;
|
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
||||||
@ -110,7 +109,7 @@ public interface TransportService {
|
|||||||
|
|
||||||
void process(SessionInfoProto sessionInfo, ToServerRpcRequestMsg msg, TransportServiceCallback<Void> callback);
|
void process(SessionInfoProto sessionInfo, ToServerRpcRequestMsg msg, TransportServiceCallback<Void> callback);
|
||||||
|
|
||||||
void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.ToDevicePersistedRpcResponseMsg msg, TransportServiceCallback<Void> callback);
|
void process(SessionInfoProto sessionInfo, ToDevicePersistedRpcResponseMsg msg, TransportServiceCallback<Void> callback);
|
||||||
|
|
||||||
void process(SessionInfoProto sessionInfo, SubscriptionInfoProto msg, TransportServiceCallback<Void> callback);
|
void process(SessionInfoProto sessionInfo, SubscriptionInfoProto msg, TransportServiceCallback<Void> callback);
|
||||||
|
|
||||||
|
|||||||
@ -752,7 +752,7 @@ public class DefaultTransportService implements TransportService {
|
|||||||
listener.onGetAttributesResponse(toSessionMsg.getGetAttributesResponse());
|
listener.onGetAttributesResponse(toSessionMsg.getGetAttributesResponse());
|
||||||
}
|
}
|
||||||
if (toSessionMsg.hasAttributeUpdateNotification()) {
|
if (toSessionMsg.hasAttributeUpdateNotification()) {
|
||||||
listener.onAttributeUpdate(toSessionMsg.getAttributeUpdateNotification());
|
listener.onAttributeUpdate(sessionId, toSessionMsg.getAttributeUpdateNotification());
|
||||||
}
|
}
|
||||||
if (toSessionMsg.hasSessionCloseNotification()) {
|
if (toSessionMsg.hasSessionCloseNotification()) {
|
||||||
listener.onRemoteSessionCloseCommand(sessionId, toSessionMsg.getSessionCloseNotification());
|
listener.onRemoteSessionCloseCommand(sessionId, toSessionMsg.getSessionCloseNotification());
|
||||||
@ -761,7 +761,7 @@ public class DefaultTransportService implements TransportService {
|
|||||||
listener.onToTransportUpdateCredentials(toSessionMsg.getToTransportUpdateCredentialsNotification());
|
listener.onToTransportUpdateCredentials(toSessionMsg.getToTransportUpdateCredentialsNotification());
|
||||||
}
|
}
|
||||||
if (toSessionMsg.hasToDeviceRequest()) {
|
if (toSessionMsg.hasToDeviceRequest()) {
|
||||||
listener.onToDeviceRpcRequest(toSessionMsg.getToDeviceRequest());
|
listener.onToDeviceRpcRequest(sessionId, toSessionMsg.getToDeviceRequest());
|
||||||
}
|
}
|
||||||
if (toSessionMsg.hasToServerResponse()) {
|
if (toSessionMsg.hasToServerResponse()) {
|
||||||
String requestId = sessionId + "-" + toSessionMsg.getToServerResponse().getRequestId();
|
String requestId = sessionId + "-" + toSessionMsg.getToServerResponse().getRequestId();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user