Commit 3d3cb1f16cde9a074675a03aad7f4d52afdca842

Authored by Andrew Shvayka
Committed by GitHub
2 parents 66d4c3fd f1355172

Merge pull request #4770 from ShvaykaD/fix/coap-transport/obesrve-sessions

CoAP: Updated observe sessions closing logic
... ... @@ -65,6 +65,7 @@ import java.util.concurrent.ConcurrentHashMap;
65 65 import java.util.concurrent.ConcurrentMap;
66 66 import java.util.concurrent.TimeUnit;
67 67 import java.util.concurrent.atomic.AtomicInteger;
  68 +import java.util.stream.Collectors;
68 69
69 70 @Slf4j
70 71 public class CoapTransportResource extends AbstractCoapTransportResource {
... ... @@ -76,9 +77,8 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
76 77 private static final int REQUEST_ID_POSITION_CERTIFICATE_REQUEST = 4;
77 78 private static final String DTLS_SESSION_ID_KEY = "DTLS_SESSION_ID";
78 79
79   - private final ConcurrentMap<String, TransportProtos.SessionInfoProto> tokenToSessionInfoMap = new ConcurrentHashMap<>();
80   - private final ConcurrentMap<String, AtomicInteger> tokenToObserveNotificationSeqMap = new ConcurrentHashMap<>();
81   - private final ConcurrentMap<TransportProtos.SessionInfoProto, ObserveRelation> sessionInfoToObserveRelationMap = new ConcurrentHashMap<>();
  80 + private final ConcurrentMap<String, CoapObserveSessionInfo> tokenToCoapSessionInfoMap = new ConcurrentHashMap<>();
  81 + private final ConcurrentMap<CoapObserveSessionInfo, ObserveRelation> sessionInfoToObserveRelationMap = new ConcurrentHashMap<>();
82 82 private final Set<UUID> rpcSubscriptions = ConcurrentHashMap.newKeySet();
83 83 private final Set<UUID> attributeSubscriptions = ConcurrentHashMap.newKeySet();
84 84
... ... @@ -94,7 +94,11 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
94 94 this.timeout = coapServerService.getTimeout();
95 95 this.sessionReportTimeout = ctx.getSessionReportTimeout();
96 96 ctx.getScheduler().scheduleAtFixedRate(() -> {
97   - Set<TransportProtos.SessionInfoProto> observeSessions = sessionInfoToObserveRelationMap.keySet();
  97 + Set<CoapObserveSessionInfo> coapObserveSessionInfos = sessionInfoToObserveRelationMap.keySet();
  98 + Set<TransportProtos.SessionInfoProto> observeSessions = coapObserveSessionInfos
  99 + .stream()
  100 + .map(CoapObserveSessionInfo::getSessionInfoProto)
  101 + .collect(Collectors.toSet());
98 102 observeSessions.forEach(this::reportActivity);
99 103 }, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS);
100 104 }
... ... @@ -112,17 +116,17 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
112 116 relation.setEstablished();
113 117 addObserveRelation(relation);
114 118 }
115   - AtomicInteger notificationCounter = tokenToObserveNotificationSeqMap.computeIfAbsent(token, s -> new AtomicInteger(0));
116   - response.getOptions().setObserve(notificationCounter.getAndIncrement());
  119 + AtomicInteger observeNotificationCounter = tokenToCoapSessionInfoMap.get(token).getObserveNotificationCounter();
  120 + response.getOptions().setObserve(observeNotificationCounter.getAndIncrement());
117 121 } // ObserveLayer takes care of the else case
118 122 }
119 123
120   - public void clearAndNotifyObserveRelation(ObserveRelation relation, CoAP.ResponseCode code) {
  124 + private void clearAndNotifyObserveRelation(ObserveRelation relation, CoAP.ResponseCode code) {
121 125 relation.cancel();
122 126 relation.getExchange().sendResponse(new Response(code));
123 127 }
124 128
125   - public Map<TransportProtos.SessionInfoProto, ObserveRelation> getSessionInfoToObserveRelationMap() {
  129 + private Map<CoapObserveSessionInfo, ObserveRelation> getCoapSessionInfoToObserveRelationMap() {
126 130 return sessionInfoToObserveRelationMap;
127 131 }
128 132
... ... @@ -278,8 +282,8 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
278 282 new CoapOkCallback(exchange, CoAP.ResponseCode.CREATED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
279 283 break;
280 284 case SUBSCRIBE_ATTRIBUTES_REQUEST:
281   - TransportProtos.SessionInfoProto currentAttrSession = tokenToSessionInfoMap.get(getTokenFromRequest(request));
282   - if (currentAttrSession == null) {
  285 + CoapObserveSessionInfo currentCoapObserveAttrSessionInfo = tokenToCoapSessionInfoMap.get(getTokenFromRequest(request));
  286 + if (currentCoapObserveAttrSessionInfo == null) {
283 287 attributeSubscriptions.add(sessionId);
284 288 registerAsyncCoapSession(exchange, sessionInfo, coapTransportAdaptor,
285 289 transportConfigurationContainer.getRpcRequestDynamicMessageBuilder(), getTokenFromRequest(request));
... ... @@ -291,20 +295,20 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
291 295 }
292 296 break;
293 297 case UNSUBSCRIBE_ATTRIBUTES_REQUEST:
294   - TransportProtos.SessionInfoProto attrSession = lookupAsyncSessionInfo(getTokenFromRequest(request));
295   - if (attrSession != null) {
  298 + CoapObserveSessionInfo coapObserveAttrSessionInfo = lookupAsyncSessionInfo(getTokenFromRequest(request));
  299 + if (coapObserveAttrSessionInfo != null) {
  300 + TransportProtos.SessionInfoProto attrSession = coapObserveAttrSessionInfo.getSessionInfoProto();
296 301 UUID attrSessionId = toSessionId(attrSession);
297 302 attributeSubscriptions.remove(attrSessionId);
298   - sessionInfoToObserveRelationMap.remove(attrSession);
299 303 transportService.process(attrSession,
300 304 TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().setUnsubscribe(true).build(),
301   - new CoapOkCallback(exchange, CoAP.ResponseCode.DELETED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
302   - closeAndDeregister(sessionInfo);
  305 + new CoapNoOpCallback(exchange));
303 306 }
  307 + closeAndDeregister(sessionInfo);
304 308 break;
305 309 case SUBSCRIBE_RPC_COMMANDS_REQUEST:
306   - TransportProtos.SessionInfoProto currentRpcSession = tokenToSessionInfoMap.get(getTokenFromRequest(request));
307   - if (currentRpcSession == null) {
  310 + CoapObserveSessionInfo currentCoapObserveRpcSessionInfo = tokenToCoapSessionInfoMap.get(getTokenFromRequest(request));
  311 + if (currentCoapObserveRpcSessionInfo == null) {
308 312 rpcSubscriptions.add(sessionId);
309 313 registerAsyncCoapSession(exchange, sessionInfo, coapTransportAdaptor,
310 314 transportConfigurationContainer.getRpcRequestDynamicMessageBuilder(), getTokenFromRequest(request));
... ... @@ -315,16 +319,16 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
315 319 }
316 320 break;
317 321 case UNSUBSCRIBE_RPC_COMMANDS_REQUEST:
318   - TransportProtos.SessionInfoProto rpcSession = lookupAsyncSessionInfo(getTokenFromRequest(request));
319   - if (rpcSession != null) {
  322 + CoapObserveSessionInfo coapObserveRpcSessionInfo = lookupAsyncSessionInfo(getTokenFromRequest(request));
  323 + if (coapObserveRpcSessionInfo != null) {
  324 + TransportProtos.SessionInfoProto rpcSession = coapObserveRpcSessionInfo.getSessionInfoProto();
320 325 UUID rpcSessionId = toSessionId(rpcSession);
321 326 rpcSubscriptions.remove(rpcSessionId);
322   - sessionInfoToObserveRelationMap.remove(rpcSession);
323 327 transportService.process(rpcSession,
324 328 TransportProtos.SubscribeToRPCMsg.newBuilder().setUnsubscribe(true).build(),
325 329 new CoapOkCallback(exchange, CoAP.ResponseCode.DELETED, CoAP.ResponseCode.INTERNAL_SERVER_ERROR));
326   - closeAndDeregister(sessionInfo);
327 330 }
  331 + closeAndDeregister(sessionInfo);
328 332 break;
329 333 case TO_DEVICE_RPC_RESPONSE:
330 334 transportService.process(sessionInfo,
... ... @@ -356,13 +360,12 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
356 360 return new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
357 361 }
358 362
359   - private TransportProtos.SessionInfoProto lookupAsyncSessionInfo(String token) {
360   - tokenToObserveNotificationSeqMap.remove(token);
361   - return tokenToSessionInfoMap.remove(token);
  363 + private CoapObserveSessionInfo lookupAsyncSessionInfo(String token) {
  364 + return tokenToCoapSessionInfoMap.remove(token);
362 365 }
363 366
364 367 private void registerAsyncCoapSession(CoapExchange exchange, TransportProtos.SessionInfoProto sessionInfo, CoapTransportAdaptor coapTransportAdaptor, DynamicMessage.Builder rpcRequestDynamicMessageBuilder, String token) {
365   - tokenToSessionInfoMap.putIfAbsent(token, sessionInfo);
  368 + tokenToCoapSessionInfoMap.putIfAbsent(token, new CoapObserveSessionInfo(sessionInfo));
366 369 transportService.registerAsyncSession(sessionInfo, getCoapSessionListener(exchange, coapTransportAdaptor, rpcRequestDynamicMessageBuilder, sessionInfo));
367 370 transportService.process(sessionInfo, getSessionEventMsg(TransportProtos.SessionEvent.OPEN), null);
368 371 }
... ... @@ -477,45 +480,36 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
477 480 }
478 481
479 482 @Override
480   - public void onAttributeUpdate(TransportProtos.AttributeUpdateNotificationMsg msg) {
  483 + public void onAttributeUpdate(UUID sessionId, TransportProtos.AttributeUpdateNotificationMsg msg) {
  484 + log.trace("[{}] Received attributes update notification to device", sessionId);
481 485 try {
482 486 exchange.respond(coapTransportAdaptor.convertToPublish(isConRequest(), msg));
483 487 } catch (AdaptorException e) {
484 488 log.trace("Failed to reply due to error", e);
485   - exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
  489 + closeObserveRelationAndNotify(sessionId, CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
  490 + closeAndDeregister();
486 491 }
487 492 }
488 493
489 494 @Override
490 495 public void onRemoteSessionCloseCommand(UUID sessionId, TransportProtos.SessionCloseNotificationProto sessionCloseNotification) {
491 496 log.trace("[{}] Received the remote command to close the session: {}", sessionId, sessionCloseNotification.getMessage());
492   - Map<TransportProtos.SessionInfoProto, ObserveRelation> sessionToObserveRelationMap = coapTransportResource.getSessionInfoToObserveRelationMap();
493   - if (coapTransportResource.getObserverCount() > 0 && !CollectionUtils.isEmpty(sessionToObserveRelationMap)) {
494   - Set<TransportProtos.SessionInfoProto> observeSessions = sessionToObserveRelationMap.keySet();
495   - Optional<TransportProtos.SessionInfoProto> observeSessionToClose = observeSessions.stream().filter(sessionInfoProto -> {
496   - UUID observeSessionId = new UUID(sessionInfoProto.getSessionIdMSB(), sessionInfoProto.getSessionIdLSB());
497   - return observeSessionId.equals(sessionId);
498   - }).findFirst();
499   - if (observeSessionToClose.isPresent()) {
500   - TransportProtos.SessionInfoProto sessionInfoProto = observeSessionToClose.get();
501   - ObserveRelation observeRelation = sessionToObserveRelationMap.get(sessionInfoProto);
502   - coapTransportResource.clearAndNotifyObserveRelation(observeRelation, CoAP.ResponseCode.SERVICE_UNAVAILABLE);
503   - }
504   - }
  497 + closeObserveRelationAndNotify(sessionId, CoAP.ResponseCode.SERVICE_UNAVAILABLE);
  498 + closeAndDeregister();
505 499 }
506 500
507 501 @Override
508   - public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg msg) {
509   - boolean successful;
  502 + public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg msg) {
  503 + log.trace("[{}] Received RPC command to device", sessionId);
  504 + boolean successful = true;
510 505 try {
511 506 exchange.respond(coapTransportAdaptor.convertToPublish(isConRequest(), msg, rpcRequestDynamicMessageBuilder));
512   - successful = true;
513 507 } catch (AdaptorException e) {
514 508 log.trace("Failed to reply due to error", e);
515   - exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
  509 + closeObserveRelationAndNotify(sessionId, CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
516 510 successful = false;
517   - }
518   - if (msg.getPersisted()) {
  511 + } finally {
  512 + if (msg.getPersisted()) {
519 513 RpcStatus status;
520 514 if (!successful) {
521 515 status = RpcStatus.FAILED;
... ... @@ -531,6 +525,10 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
531 525 .setStatus(status.name())
532 526 .build();
533 527 coapTransportResource.transportService.process(sessionInfo, responseMsg, TransportServiceCallback.EMPTY);
  528 + }
  529 + if (!successful) {
  530 + closeAndDeregister();
  531 + }
534 532 }
535 533 }
536 534
... ... @@ -547,6 +545,30 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
547 545 private boolean isConRequest() {
548 546 return exchange.advanced().getRequest().isConfirmable();
549 547 }
  548 +
  549 + private void closeObserveRelationAndNotify(UUID sessionId, CoAP.ResponseCode responseCode) {
  550 + Map<CoapObserveSessionInfo, ObserveRelation> sessionToObserveRelationMap = coapTransportResource.getCoapSessionInfoToObserveRelationMap();
  551 + if (coapTransportResource.getObserverCount() > 0 && !CollectionUtils.isEmpty(sessionToObserveRelationMap)) {
  552 + Optional<CoapObserveSessionInfo> observeSessionToClose = sessionToObserveRelationMap.keySet().stream().filter(coapObserveSessionInfo -> {
  553 + TransportProtos.SessionInfoProto sessionToDelete = coapObserveSessionInfo.getSessionInfoProto();
  554 + UUID observeSessionId = new UUID(sessionToDelete.getSessionIdMSB(), sessionToDelete.getSessionIdLSB());
  555 + return observeSessionId.equals(sessionId);
  556 + }).findFirst();
  557 + if (observeSessionToClose.isPresent()) {
  558 + CoapObserveSessionInfo coapObserveSessionInfo = observeSessionToClose.get();
  559 + ObserveRelation observeRelation = sessionToObserveRelationMap.get(coapObserveSessionInfo);
  560 + coapTransportResource.clearAndNotifyObserveRelation(observeRelation, responseCode);
  561 + }
  562 + }
  563 + }
  564 +
  565 + private void closeAndDeregister() {
  566 + Request request = exchange.advanced().getRequest();
  567 + String token = coapTransportResource.getTokenFromRequest(request);
  568 + CoapObserveSessionInfo deleted = coapTransportResource.lookupAsyncSessionInfo(token);
  569 + coapTransportResource.closeAndDeregister(deleted.getSessionInfoProto());
  570 + }
  571 +
550 572 }
551 573
552 574 public class CoapResourceObserver implements ResourceObserver {
... ... @@ -571,7 +593,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
571 593 public void addedObserveRelation(ObserveRelation relation) {
572 594 Request request = relation.getExchange().getRequest();
573 595 String token = getTokenFromRequest(request);
574   - sessionInfoToObserveRelationMap.putIfAbsent(tokenToSessionInfoMap.get(token), relation);
  596 + sessionInfoToObserveRelationMap.putIfAbsent(tokenToCoapSessionInfoMap.get(token), relation);
575 597 log.trace("Added Observe relation for token: {}", token);
576 598 }
577 599
... ... @@ -579,8 +601,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
579 601 public void removedObserveRelation(ObserveRelation relation) {
580 602 Request request = relation.getExchange().getRequest();
581 603 String token = getTokenFromRequest(request);
582   - TransportProtos.SessionInfoProto session = tokenToSessionInfoMap.get(token);
583   - sessionInfoToObserveRelationMap.remove(session);
  604 + sessionInfoToObserveRelationMap.remove(tokenToCoapSessionInfoMap.get(token));
584 605 log.trace("Relation removed for token: {}", token);
585 606 }
586 607 }
... ... @@ -591,7 +612,6 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
591 612 transportService.deregisterSession(session);
592 613 rpcSubscriptions.remove(sessionId);
593 614 attributeSubscriptions.remove(sessionId);
594   - sessionInfoToObserveRelationMap.remove(session);
595 615 }
596 616
597 617 private TransportConfigurationContainer getTransportConfigurationContainer(DeviceProfile deviceProfile) throws AdaptorException {
... ... @@ -657,4 +677,17 @@ public class CoapTransportResource extends AbstractCoapTransportResource {
657 677 this.jsonPayload = jsonPayload;
658 678 }
659 679 }
  680 +
  681 + @Data
  682 + private static class CoapObserveSessionInfo {
  683 +
  684 + private final TransportProtos.SessionInfoProto sessionInfoProto;
  685 + private final AtomicInteger observeNotificationCounter;
  686 +
  687 + private CoapObserveSessionInfo(TransportProtos.SessionInfoProto sessionInfoProto) {
  688 + this.sessionInfoProto = sessionInfoProto;
  689 + this.observeNotificationCounter = new AtomicInteger(0);
  690 + }
  691 + }
  692 +
660 693 }
... ...
... ... @@ -393,7 +393,8 @@ public class DeviceApiController implements TbTransportService {
393 393 }
394 394
395 395 @Override
396   - public void onAttributeUpdate(AttributeUpdateNotificationMsg msg) {
  396 + public void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg msg) {
  397 + log.trace("[{}] Received attributes update notification to device", sessionId);
397 398 responseWriter.setResult(new ResponseEntity<>(JsonConverter.toJson(msg).toString(), HttpStatus.OK));
398 399 }
399 400
... ... @@ -404,7 +405,8 @@ public class DeviceApiController implements TbTransportService {
404 405 }
405 406
406 407 @Override
407   - public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg msg) {
  408 + public void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg msg) {
  409 + log.trace("[{}] Received RPC command to device", sessionId);
408 410 responseWriter.setResult(new ResponseEntity<>(JsonConverter.toJson(msg, true).toString(), HttpStatus.OK));
409 411 if (msg.getPersisted()) {
410 412 RpcStatus status;
... ...
... ... @@ -56,9 +56,10 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s
56 56 }
57 57
58 58 @Override
59   - public void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification) {
  59 + public void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg attributeUpdateNotification) {
  60 + log.trace("[{}] Received attributes update notification to device", sessionId);
60 61 this.attributesService.onAttributesUpdate(attributeUpdateNotification, this.sessionInfo);
61   - }
  62 + }
62 63
63 64 @Override
64 65 public void onRemoteSessionCloseCommand(UUID sessionId, SessionCloseNotificationProto sessionCloseNotification) {
... ... @@ -81,7 +82,8 @@ public class LwM2mSessionMsgListener implements GenericFutureListener<Future<? s
81 82 }
82 83
83 84 @Override
84   - public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest) {
  85 + public void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg toDeviceRequest) {
  86 + log.trace("[{}] Received RPC command to device", sessionId);
85 87 this.rpcHandler.onToDeviceRpcRequest(toDeviceRequest, this.sessionInfo);
86 88 if (toDeviceRequest.getPersisted()) {
87 89 RpcStatus status;
... ...
... ... @@ -797,7 +797,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
797 797 }
798 798
799 799 @Override
800   - public void onAttributeUpdate(TransportProtos.AttributeUpdateNotificationMsg notification) {
  800 + public void onAttributeUpdate(UUID sessionId, TransportProtos.AttributeUpdateNotificationMsg notification) {
  801 + log.trace("[{}] Received attributes update notification to device", sessionId);
801 802 try {
802 803 deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, notification).ifPresent(deviceSessionCtx.getChannel()::writeAndFlush);
803 804 } catch (Exception e) {
... ... @@ -812,7 +813,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
812 813 }
813 814
814 815 @Override
815   - public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg rpcRequest) {
  816 + public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg rpcRequest) {
816 817 log.trace("[{}] Received RPC command to device", sessionId);
817 818 try {
818 819 deviceSessionCtx.getPayloadAdaptor().convertToPublish(deviceSessionCtx, rpcRequest)
... ...
... ... @@ -85,7 +85,8 @@ public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext imple
85 85 }
86 86
87 87 @Override
88   - public void onAttributeUpdate(TransportProtos.AttributeUpdateNotificationMsg notification) {
  88 + public void onAttributeUpdate(UUID sessionId, TransportProtos.AttributeUpdateNotificationMsg notification) {
  89 + log.trace("[{}] Received attributes update notification to device", sessionId);
89 90 try {
90 91 parent.getPayloadAdaptor().convertToGatewayPublish(this, getDeviceInfo().getDeviceName(), notification).ifPresent(parent::writeAndFlush);
91 92 } catch (Exception e) {
... ... @@ -94,7 +95,8 @@ public class GatewayDeviceSessionCtx extends MqttDeviceAwareSessionContext imple
94 95 }
95 96
96 97 @Override
97   - public void onToDeviceRpcRequest(TransportProtos.ToDeviceRpcRequestMsg request) {
  98 + public void onToDeviceRpcRequest(UUID sessionId, TransportProtos.ToDeviceRpcRequestMsg request) {
  99 + log.trace("[{}] Received RPC command to device", sessionId);
98 100 try {
99 101 parent.getPayloadAdaptor().convertToGatewayPublish(this, getDeviceInfo().getDeviceName(), request).ifPresent(
100 102 payload -> {
... ...
... ... @@ -129,7 +129,8 @@ public class DeviceSessionContext extends DeviceAwareSessionContext implements S
129 129 }
130 130
131 131 @Override
132   - public void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification) {
  132 + public void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg attributeUpdateNotification) {
  133 + log.trace("[{}] Received attributes update notification to device", sessionId);
133 134 snmpTransportContext.getSnmpTransportService().onAttributeUpdate(this, attributeUpdateNotification);
134 135 }
135 136
... ... @@ -139,7 +140,8 @@ public class DeviceSessionContext extends DeviceAwareSessionContext implements S
139 140 }
140 141
141 142 @Override
142   - public void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest) {
  143 + public void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg toDeviceRequest) {
  144 + log.trace("[{}] Received RPC command to device", sessionId);
143 145 snmpTransportContext.getSnmpTransportService().onToDeviceRpcRequest(this, toDeviceRequest);
144 146 if (toDeviceRequest.getPersisted()) {
145 147 RpcStatus status;
... ...
... ... @@ -36,11 +36,11 @@ public interface SessionMsgListener {
36 36
37 37 void onGetAttributesResponse(GetAttributeResponseMsg getAttributesResponse);
38 38
39   - void onAttributeUpdate(AttributeUpdateNotificationMsg attributeUpdateNotification);
  39 + void onAttributeUpdate(UUID sessionId, AttributeUpdateNotificationMsg attributeUpdateNotification);
40 40
41 41 void onRemoteSessionCloseCommand(UUID sessionId, SessionCloseNotificationProto sessionCloseNotification);
42 42
43   - void onToDeviceRpcRequest(ToDeviceRpcRequestMsg toDeviceRequest);
  43 + void onToDeviceRpcRequest(UUID sessionId, ToDeviceRpcRequestMsg toDeviceRequest);
44 44
45 45 void onToServerRpcResponse(ToServerRpcResponseMsg toServerResponse);
46 46
... ...
... ... @@ -20,8 +20,6 @@ import org.thingsboard.server.common.data.DeviceTransportType;
20 20 import org.thingsboard.server.common.transport.auth.GetOrCreateDeviceFromGatewayResponse;
21 21 import org.thingsboard.server.common.transport.auth.ValidateDeviceCredentialsResponse;
22 22 import org.thingsboard.server.common.transport.service.SessionMetaData;
23   -import org.thingsboard.server.gen.transport.TransportProtos;
24   -import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg;
25 23 import org.thingsboard.server.gen.transport.TransportProtos.ClaimDeviceMsg;
26 24 import org.thingsboard.server.gen.transport.TransportProtos.GetAttributeRequestMsg;
27 25 import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceCredentialsRequestMsg;
... ... @@ -30,9 +28,9 @@ import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceRequestMsg;
30 28 import org.thingsboard.server.gen.transport.TransportProtos.GetDeviceResponseMsg;
31 29 import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileRequestMsg;
32 30 import org.thingsboard.server.gen.transport.TransportProtos.GetEntityProfileResponseMsg;
  31 +import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg;
33 32 import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageRequestMsg;
34 33 import org.thingsboard.server.gen.transport.TransportProtos.GetOtaPackageResponseMsg;
35   -import org.thingsboard.server.gen.transport.TransportProtos.GetOrCreateDeviceFromGatewayRequestMsg;
36 34 import org.thingsboard.server.gen.transport.TransportProtos.GetResourceRequestMsg;
37 35 import org.thingsboard.server.gen.transport.TransportProtos.GetResourceResponseMsg;
38 36 import org.thingsboard.server.gen.transport.TransportProtos.GetSnmpDevicesRequestMsg;
... ... @@ -48,10 +46,11 @@ import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
48 46 import org.thingsboard.server.gen.transport.TransportProtos.SubscribeToAttributeUpdatesMsg;
49 47 import org.thingsboard.server.gen.transport.TransportProtos.SubscribeToRPCMsg;
50 48 import org.thingsboard.server.gen.transport.TransportProtos.SubscriptionInfoProto;
  49 +import org.thingsboard.server.gen.transport.TransportProtos.ToDevicePersistedRpcResponseMsg;
51 50 import org.thingsboard.server.gen.transport.TransportProtos.ToDeviceRpcResponseMsg;
52 51 import org.thingsboard.server.gen.transport.TransportProtos.ToServerRpcRequestMsg;
  52 +import org.thingsboard.server.gen.transport.TransportProtos.TransportToDeviceActorMsg;
53 53 import org.thingsboard.server.gen.transport.TransportProtos.ValidateBasicMqttCredRequestMsg;
54   -import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg;
55 54 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg;
56 55 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
57 56 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
... ... @@ -110,7 +109,7 @@ public interface TransportService {
110 109
111 110 void process(SessionInfoProto sessionInfo, ToServerRpcRequestMsg msg, TransportServiceCallback<Void> callback);
112 111
113   - void process(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.ToDevicePersistedRpcResponseMsg msg, TransportServiceCallback<Void> callback);
  112 + void process(SessionInfoProto sessionInfo, ToDevicePersistedRpcResponseMsg msg, TransportServiceCallback<Void> callback);
114 113
115 114 void process(SessionInfoProto sessionInfo, SubscriptionInfoProto msg, TransportServiceCallback<Void> callback);
116 115
... ...
... ... @@ -752,7 +752,7 @@ public class DefaultTransportService implements TransportService {
752 752 listener.onGetAttributesResponse(toSessionMsg.getGetAttributesResponse());
753 753 }
754 754 if (toSessionMsg.hasAttributeUpdateNotification()) {
755   - listener.onAttributeUpdate(toSessionMsg.getAttributeUpdateNotification());
  755 + listener.onAttributeUpdate(sessionId, toSessionMsg.getAttributeUpdateNotification());
756 756 }
757 757 if (toSessionMsg.hasSessionCloseNotification()) {
758 758 listener.onRemoteSessionCloseCommand(sessionId, toSessionMsg.getSessionCloseNotification());
... ... @@ -761,7 +761,7 @@ public class DefaultTransportService implements TransportService {
761 761 listener.onToTransportUpdateCredentials(toSessionMsg.getToTransportUpdateCredentialsNotification());
762 762 }
763 763 if (toSessionMsg.hasToDeviceRequest()) {
764   - listener.onToDeviceRpcRequest(toSessionMsg.getToDeviceRequest());
  764 + listener.onToDeviceRpcRequest(sessionId, toSessionMsg.getToDeviceRequest());
765 765 }
766 766 if (toSessionMsg.hasToServerResponse()) {
767 767 String requestId = sessionId + "-" + toSessionMsg.getToServerResponse().getRequestId();
... ...