|
@@ -121,6 +121,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -121,6 +121,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
121
|
this.context.getScheduler().scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) context.getCtxServer().getSessionReportTimeout()), context.getCtxServer().getSessionReportTimeout(), TimeUnit.MILLISECONDS);
|
121
|
this.context.getScheduler().scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) context.getCtxServer().getSessionReportTimeout()), context.getCtxServer().getSessionReportTimeout(), TimeUnit.MILLISECONDS);
|
122
|
this.executorRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getRegisteredPoolSize(),
|
122
|
this.executorRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getRegisteredPoolSize(),
|
123
|
new NamedThreadFactory(String.format("LwM2M %s channel registered", SERVICE_CHANNEL)));
|
123
|
new NamedThreadFactory(String.format("LwM2M %s channel registered", SERVICE_CHANNEL)));
|
|
|
124
|
+// this.executorRegistered = Executors.newWorkStealingPool(this.context.getCtxServer().getRegisteredPoolSize());
|
124
|
this.executorUpdateRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getUpdateRegisteredPoolSize(),
|
125
|
this.executorUpdateRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getUpdateRegisteredPoolSize(),
|
125
|
new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL)));
|
126
|
new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL)));
|
126
|
this.executorUnRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getUnRegisteredPoolSize(),
|
127
|
this.executorUnRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getUnRegisteredPoolSize(),
|
|
@@ -147,14 +148,10 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -147,14 +148,10 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
147
|
executorRegistered.submit(() -> {
|
148
|
executorRegistered.submit(() -> {
|
148
|
try {
|
149
|
try {
|
149
|
log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId());
|
150
|
log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId());
|
150
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.updateInSessionsLwM2MClient(lwServer, registration);
|
151
|
+ LwM2MClient lwM2MClient = this.lwM2mInMemorySecurityStore.updateInSessionsLwM2MClient(lwServer, registration);
|
151
|
if (lwM2MClient != null) {
|
152
|
if (lwM2MClient != null) {
|
152
|
lwM2MClient.setLwM2MTransportServiceImpl(this);
|
153
|
lwM2MClient.setLwM2MTransportServiceImpl(this);
|
153
|
- lwM2MClient.setSessionUuid(UUID.randomUUID());
|
|
|
154
|
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration);
|
154
|
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration);
|
155
|
- LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
|
|
156
|
- this.putDelayedUpdateResourcesThingsboard(lwM2MClient);
|
|
|
157
|
- this.setLwM2mFromClientValue(lwServer, registration, lwM2MClient, lwM2MClientProfile);
|
|
|
158
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
155
|
SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration);
|
159
|
if (sessionInfo != null) {
|
156
|
if (sessionInfo != null) {
|
160
|
lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
157
|
lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB()));
|
|
@@ -165,9 +162,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -165,9 +162,8 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
165
|
transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
|
162
|
transportService.process(sessionInfo, DefaultTransportService.getSessionEventMsg(SessionEvent.OPEN), null);
|
166
|
transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
|
163
|
transportService.process(sessionInfo, TransportProtos.SubscribeToAttributeUpdatesMsg.newBuilder().build(), null);
|
167
|
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
|
164
|
this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration);
|
168
|
-// if (LwM2MTransportHandler.getClientUpdateValueAfterConnect(lwM2MClientProfile)) {
|
|
|
169
|
-// this.putDelayedUpdateResourcesThingsboard(lwM2MClient);
|
|
|
170
|
-// }
|
165
|
+ this.initLwM2mFromClientValue(lwServer, registration, lwM2MClient);
|
|
|
166
|
+
|
171
|
} else {
|
167
|
} else {
|
172
|
log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
168
|
log.error("Client: [{}] onRegistered [{}] name [{}] sessionInfo ", registration.getId(), registration.getEndpoint(), null);
|
173
|
}
|
169
|
}
|
|
@@ -301,8 +297,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -301,8 +297,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
301
|
if (!path.isEmpty() && (this.validatePathInAttrProfile(profile, path) || this.validatePathInTelemetryProfile(profile, path))) {
|
297
|
if (!path.isEmpty() && (this.validatePathInAttrProfile(profile, path) || this.validatePathInTelemetryProfile(profile, path))) {
|
302
|
if (resourceModel != null && resourceModel.operations.isWritable()) {
|
298
|
if (resourceModel != null && resourceModel.operations.isWritable()) {
|
303
|
lwM2MTransportRequest.sendAllRequest(lwM2MClient.getLwServer(), lwM2MClient.getRegistration(), path, POST_TYPE_OPER_WRITE_REPLACE,
|
299
|
lwM2MTransportRequest.sendAllRequest(lwM2MClient.getLwServer(), lwM2MClient.getRegistration(), path, POST_TYPE_OPER_WRITE_REPLACE,
|
304
|
- ContentFormat.TLV.getName(), lwM2MClient, null, value, this.context.getCtxServer().getTimeout(),
|
|
|
305
|
- false);
|
300
|
+ ContentFormat.TLV.getName(), null, value, this.context.getCtxServer().getTimeout());
|
306
|
} else {
|
301
|
} else {
|
307
|
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", path, value);
|
302
|
log.error("Resource path - [{}] value - [{}] is not Writable and cannot be updated", path, value);
|
308
|
String logMsg = String.format(LOG_LW2M_ERROR + ": attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", path, value);
|
303
|
String logMsg = String.format(LOG_LW2M_ERROR + ": attributeUpdate: Resource path - %s value - %s is not Writable and cannot be updated", path, value);
|
|
@@ -356,8 +351,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -356,8 +351,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
356
|
@Override
|
351
|
@Override
|
357
|
public void doTrigger(LeshanServer lwServer, Registration registration, String path) {
|
352
|
public void doTrigger(LeshanServer lwServer, Registration registration, String path) {
|
358
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, POST_TYPE_OPER_EXECUTE,
|
353
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, POST_TYPE_OPER_EXECUTE,
|
359
|
- ContentFormat.TLV.getName(), null, null, null, this.context.getCtxServer().getTimeout(),
|
|
|
360
|
- false);
|
354
|
+ ContentFormat.TLV.getName(), null, null, this.context.getCtxServer().getTimeout());
|
361
|
}
|
355
|
}
|
362
|
|
356
|
|
363
|
/**
|
357
|
/**
|
|
@@ -461,23 +455,26 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -461,23 +455,26 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
461
|
* @param registration - Registration LwM2M Client
|
455
|
* @param registration - Registration LwM2M Client
|
462
|
* @param lwM2MClient - object with All parameters off client
|
456
|
* @param lwM2MClient - object with All parameters off client
|
463
|
*/
|
457
|
*/
|
464
|
- private void setLwM2mFromClientValue(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, LwM2MClientProfile lwM2MClientProfile) {
|
458
|
+ private void initLwM2mFromClientValue(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient) {
|
|
|
459
|
+ LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
465
|
Set<String> clientObjects = this.getAllOjectsInClient(registration);
|
460
|
Set<String> clientObjects = this.getAllOjectsInClient(registration);
|
466
|
- if (clientObjects != null) {
|
461
|
+ if (clientObjects != null && !LwM2MTransportHandler.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) {
|
467
|
// #2
|
462
|
// #2
|
468
|
- if (!LwM2MTransportHandler.getClientOnlyObserveAfterConnect(lwM2MClientProfile) && !LwM2MTransportHandler.getClientUpdateValueAfterConnect(lwM2MClientProfile)) {
|
|
|
469
|
- this.onSentReadAttrTelemetryToClient(lwServer, registration);
|
463
|
+ if (!LwM2MTransportHandler.getClientUpdateValueAfterConnect(lwM2MClientProfile)) {
|
|
|
464
|
+ this.initReadAttrTelemetryObserveToClient(lwServer, registration, lwM2MClient, GET_TYPE_OPER_READ);
|
|
|
465
|
+
|
470
|
}
|
466
|
}
|
471
|
// #3
|
467
|
// #3
|
472
|
else {
|
468
|
else {
|
|
|
469
|
+ lwM2MClient.getPendingRequests().addAll(clientObjects);
|
473
|
clientObjects.forEach(path -> {
|
470
|
clientObjects.forEach(path -> {
|
474
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, GET_TYPE_OPER_READ, ContentFormat.TLV.getName(),
|
471
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, path, GET_TYPE_OPER_READ, ContentFormat.TLV.getName(),
|
475
|
- lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false);
|
472
|
+ null, null, this.context.getCtxServer().getTimeout());
|
476
|
});
|
473
|
});
|
477
|
}
|
474
|
}
|
478
|
}
|
475
|
}
|
479
|
// #1
|
476
|
// #1
|
480
|
- this.onSentObserveToClient(lwServer, registration);
|
477
|
+ this.initReadAttrTelemetryObserveToClient(lwServer, registration, lwM2MClient, GET_TYPE_OPER_OBSERVE);
|
481
|
}
|
478
|
}
|
482
|
|
479
|
|
483
|
/**
|
480
|
/**
|
|
@@ -519,7 +516,6 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -519,7 +516,6 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
519
|
private void updateResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) {
|
516
|
private void updateResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) {
|
520
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
517
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null);
|
521
|
lwM2MClient.updateResourceValue(path, lwM2mResource);
|
518
|
lwM2MClient.updateResourceValue(path, lwM2mResource);
|
522
|
- log.warn("upDateResize: [{}] [{}]", lwM2MClient.getEndPoint(), path);
|
|
|
523
|
Set<String> paths = new HashSet<>();
|
519
|
Set<String> paths = new HashSet<>();
|
524
|
paths.add(path);
|
520
|
paths.add(path);
|
525
|
this.updateAttrTelemetry(registration, false, paths);
|
521
|
this.updateAttrTelemetry(registration, false, paths);
|
|
@@ -582,30 +578,45 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -582,30 +578,45 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
582
|
}
|
578
|
}
|
583
|
|
579
|
|
584
|
/**
|
580
|
/**
|
585
|
- * Start observe
|
581
|
+ * Start observe/read: Attr/Telemetry
|
586
|
* #1 - Analyze:
|
582
|
* #1 - Analyze:
|
587
|
- * #1.1 path in observe profile == client resource
|
|
|
588
|
- *
|
|
|
589
|
- * @param lwServer - LeshanServer
|
|
|
590
|
- * @param registration - Registration LwM2M Client
|
583
|
+ * #1.1 path in resource profile == client resource
|
|
|
584
|
+ * @param lwServer -
|
|
|
585
|
+ * @param registration -
|
591
|
*/
|
586
|
*/
|
592
|
- private void onSentObserveToClient(LeshanServer lwServer, Registration registration) {
|
|
|
593
|
- if (lwServer.getObservationService().getObservations(registration).size() > 0) {
|
|
|
594
|
- this.setCancelObservations(lwServer, registration);
|
|
|
595
|
- }
|
|
|
596
|
- LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
|
|
597
|
- Set<String> clientInstances = this.getAllInstancesInClient(registration);
|
|
|
598
|
- lwM2MClientProfile.getPostObserveProfile().forEach(p -> {
|
|
|
599
|
- // #1.1
|
|
|
600
|
- String target = p.getAsString().toString();
|
|
|
601
|
- String[] resPath = target.split("/");
|
|
|
602
|
- String instance = "/" + resPath[1] + "/" + resPath[2];
|
|
|
603
|
- if (clientInstances.contains(instance)) {
|
|
|
604
|
- lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, GET_TYPE_OPER_OBSERVE,
|
|
|
605
|
- null, null, null, null, this.context.getCtxServer().getTimeout(),
|
|
|
606
|
- false);
|
587
|
+ private void initReadAttrTelemetryObserveToClient(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient, String typeOper) {
|
|
|
588
|
+ try {
|
|
|
589
|
+ LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
|
|
590
|
+ Set<String> clientInstances = this.getAllInstancesInClient(registration);
|
|
|
591
|
+ Set<String> result;
|
|
|
592
|
+ if (GET_TYPE_OPER_READ.equals(typeOper)) {
|
|
|
593
|
+ result = new ObjectMapper().readValue(lwM2MClientProfile.getPostAttributeProfile().getAsJsonArray().toString().getBytes(), Set.class);
|
|
|
594
|
+ result.addAll(new ObjectMapper().readValue(lwM2MClientProfile.getPostTelemetryProfile().getAsJsonArray().toString().getBytes(), Set.class));
|
607
|
}
|
595
|
}
|
608
|
- });
|
596
|
+ else {
|
|
|
597
|
+ result = new ObjectMapper().readValue(lwM2MClientProfile.getPostObserveProfile().getAsJsonArray().toString().getBytes(), Set.class);
|
|
|
598
|
+ }
|
|
|
599
|
+ Set<String> pathSent = ConcurrentHashMap.newKeySet();
|
|
|
600
|
+ result.forEach(p -> {
|
|
|
601
|
+ // #1.1
|
|
|
602
|
+ String target = p;
|
|
|
603
|
+ String[] resPath = target.split("/");
|
|
|
604
|
+ String instance = "/" + resPath[1] + "/" + resPath[2];
|
|
|
605
|
+ if (clientInstances.contains(instance)) {
|
|
|
606
|
+ pathSent.add(target);
|
|
|
607
|
+ }
|
|
|
608
|
+ });
|
|
|
609
|
+ lwM2MClient.getPendingRequests().addAll(pathSent);
|
|
|
610
|
+ pathSent.forEach(target -> {
|
|
|
611
|
+ lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper, ContentFormat.TLV.getName(),
|
|
|
612
|
+ null, null, this.context.getCtxServer().getTimeout());
|
|
|
613
|
+ });
|
|
|
614
|
+ if (GET_TYPE_OPER_OBSERVE.equals(typeOper)) {
|
|
|
615
|
+ lwM2MClient.initValue(this, null);
|
|
|
616
|
+ }
|
|
|
617
|
+ } catch (IOException e) {
|
|
|
618
|
+ e.printStackTrace();
|
|
|
619
|
+ }
|
609
|
}
|
620
|
}
|
610
|
|
621
|
|
611
|
/**
|
622
|
/**
|
|
@@ -657,28 +668,6 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -657,28 +668,6 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
657
|
return (clientInstances.size() > 0) ? clientInstances : null;
|
668
|
return (clientInstances.size() > 0) ? clientInstances : null;
|
658
|
}
|
669
|
}
|
659
|
|
670
|
|
660
|
- private void onSentReadAttrTelemetryToClient(LeshanServer lwServer, Registration registration) {
|
|
|
661
|
- LwM2MClientProfile lwM2MClientProfile = lwM2mInMemorySecurityStore.getProfile(registration.getId());
|
|
|
662
|
- Set<String> clientInstances = this.getAllInstancesInClient(registration);
|
|
|
663
|
- Set<String> attr = ConcurrentHashMap.newKeySet();
|
|
|
664
|
- try {
|
|
|
665
|
- attr = new ObjectMapper().readValue(lwM2MClientProfile.getPostAttributeProfile().getAsJsonArray().toString().getBytes(), Set.class);
|
|
|
666
|
- attr.addAll(new ObjectMapper().readValue(lwM2MClientProfile.getPostTelemetryProfile().getAsJsonArray().toString().getBytes(), Set.class));
|
|
|
667
|
- } catch (IOException e) {
|
|
|
668
|
- e.printStackTrace();
|
|
|
669
|
- }
|
|
|
670
|
- attr.forEach(p -> {
|
|
|
671
|
- // #1.1
|
|
|
672
|
- String target = p;
|
|
|
673
|
- String[] resPath = target.split("/");
|
|
|
674
|
- String instance = "/" + resPath[1] + "/" + resPath[2];
|
|
|
675
|
- if (clientInstances.contains(instance)) {
|
|
|
676
|
- lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, GET_TYPE_OPER_READ, ContentFormat.TLV.getName(),
|
|
|
677
|
- null, null, null, this.context.getCtxServer().getTimeout(), false);
|
|
|
678
|
- }
|
|
|
679
|
- });
|
|
|
680
|
- }
|
|
|
681
|
-
|
|
|
682
|
/**
|
671
|
/**
|
683
|
* get AttrName/TelemetryName with value from Client
|
672
|
* get AttrName/TelemetryName with value from Client
|
684
|
*
|
673
|
*
|
|
@@ -767,7 +756,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -767,7 +756,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
767
|
* @param path -
|
756
|
* @param path -
|
768
|
* @param request -
|
757
|
* @param request -
|
769
|
*/
|
758
|
*/
|
770
|
- public void onWriteResponseOk(Registration registration, String path, WriteRequest request, boolean isDelayedUpdate) {
|
759
|
+ public void onWriteResponseOk(Registration registration, String path, WriteRequest request) {
|
771
|
this.updateResourcesValue(registration, ((LwM2mResource) request.getNode()), path);
|
760
|
this.updateResourcesValue(registration, ((LwM2mResource) request.getNode()), path);
|
772
|
}
|
761
|
}
|
773
|
|
762
|
|
|
@@ -841,8 +830,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -841,8 +830,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
841
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(null, registrationId);
|
830
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(null, registrationId);
|
842
|
LeshanServer lwServer = lwM2MClient.getLwServer();
|
831
|
LeshanServer lwServer = lwM2MClient.getLwServer();
|
843
|
Registration registration = lwM2mInMemorySecurityStore.getByRegistration(registrationId);
|
832
|
Registration registration = lwM2mInMemorySecurityStore.getByRegistration(registrationId);
|
844
|
- log.warn("[{}] # 4.1", registration.getEndpoint());
|
|
|
845
|
- this.updateResourceValueObserve(lwServer, registration, sentAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
833
|
+ this.readResourceValueObserve(lwServer, registration, sentAttrToThingsboard.getPathPostParametersAdd(), GET_TYPE_OPER_READ);
|
846
|
// sent attr/telemetry to tingsboard for new path
|
834
|
// sent attr/telemetry to tingsboard for new path
|
847
|
this.updateAttrTelemetry(registration, false, sentAttrToThingsboard.getPathPostParametersAdd());
|
835
|
this.updateAttrTelemetry(registration, false, sentAttrToThingsboard.getPathPostParametersAdd());
|
848
|
});
|
836
|
});
|
|
@@ -870,8 +858,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -870,8 +858,7 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
870
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(null, registrationId);
|
858
|
LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(null, registrationId);
|
871
|
LeshanServer lwServer = lwM2MClient.getLwServer();
|
859
|
LeshanServer lwServer = lwM2MClient.getLwServer();
|
872
|
Registration registration = lwM2mInMemorySecurityStore.getByRegistration(registrationId);
|
860
|
Registration registration = lwM2mInMemorySecurityStore.getByRegistration(registrationId);
|
873
|
- log.warn("[{}] # 5.1", registration.getEndpoint());
|
|
|
874
|
- this.updateResourceValueObserve(lwServer, registration, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
|
861
|
+ this.readResourceValueObserve(lwServer, registration, postObserveAnalyzer.getPathPostParametersAdd(), GET_TYPE_OPER_OBSERVE);
|
875
|
// 5.3 del
|
862
|
// 5.3 del
|
876
|
// sent Request cancel observe to Client
|
863
|
// sent Request cancel observe to Client
|
877
|
this.cancelObserveIsValue(lwServer, registration, postObserveAnalyzer.getPathPostParametersDel());
|
864
|
this.cancelObserveIsValue(lwServer, registration, postObserveAnalyzer.getPathPostParametersDel());
|
|
@@ -914,18 +901,16 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -914,18 +901,16 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
914
|
* @param registration - Registration LwM2M Client
|
901
|
* @param registration - Registration LwM2M Client
|
915
|
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
|
902
|
* @param targets - path Resources == [ "/2/0/0", "/2/0/1"]
|
916
|
*/
|
903
|
*/
|
917
|
- private void updateResourceValueObserve(LeshanServer lwServer, Registration registration, Set<String> targets, String typeOper) {
|
904
|
+ private void readResourceValueObserve(LeshanServer lwServer, Registration registration, Set<String> targets, String typeOper) {
|
918
|
targets.forEach(target -> {
|
905
|
targets.forEach(target -> {
|
919
|
LwM2mPath pathIds = new LwM2mPath(target);
|
906
|
LwM2mPath pathIds = new LwM2mPath(target);
|
920
|
if (pathIds.isResource()) {
|
907
|
if (pathIds.isResource()) {
|
921
|
if (GET_TYPE_OPER_READ.equals(typeOper)) {
|
908
|
if (GET_TYPE_OPER_READ.equals(typeOper)) {
|
922
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,
|
909
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,
|
923
|
- ContentFormat.TLV.getName(), null, null, null, this.context.getCtxServer().getTimeout(),
|
|
|
924
|
- false);
|
910
|
+ ContentFormat.TLV.getName(), null, null, this.context.getCtxServer().getTimeout());
|
925
|
} else if (GET_TYPE_OPER_OBSERVE.equals(typeOper)) {
|
911
|
} else if (GET_TYPE_OPER_OBSERVE.equals(typeOper)) {
|
926
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,
|
912
|
lwM2MTransportRequest.sendAllRequest(lwServer, registration, target, typeOper,
|
927
|
- null, null, null, null, this.context.getCtxServer().getTimeout(),
|
|
|
928
|
- false);
|
913
|
+ null, null, null, this.context.getCtxServer().getTimeout());
|
929
|
}
|
914
|
}
|
930
|
}
|
915
|
}
|
931
|
});
|
916
|
});
|
|
@@ -952,10 +937,11 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -952,10 +937,11 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
952
|
}
|
937
|
}
|
953
|
|
938
|
|
954
|
private void putDelayedUpdateResourcesClient(LwM2MClient lwM2MClient, Object valueOld, Object valueNew, String path) {
|
939
|
private void putDelayedUpdateResourcesClient(LwM2MClient lwM2MClient, Object valueOld, Object valueNew, String path) {
|
955
|
- if (valueNew != null && !valueNew.toString().equals(valueOld.toString())) {
|
940
|
+ if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) {
|
956
|
lwM2MTransportRequest.sendAllRequest(lwM2MClient.getLwServer(), lwM2MClient.getRegistration(), path, POST_TYPE_OPER_WRITE_REPLACE,
|
941
|
lwM2MTransportRequest.sendAllRequest(lwM2MClient.getLwServer(), lwM2MClient.getRegistration(), path, POST_TYPE_OPER_WRITE_REPLACE,
|
957
|
- ContentFormat.TLV.getName(), lwM2MClient, null, valueNew, this.context.getCtxServer().getTimeout(),
|
|
|
958
|
- true);
|
942
|
+ ContentFormat.TLV.getName(), null, valueNew, this.context.getCtxServer().getTimeout());
|
|
|
943
|
+ } else {
|
|
|
944
|
+ log.error("05 delayError");
|
959
|
}
|
945
|
}
|
960
|
}
|
946
|
}
|
961
|
|
947
|
|
|
@@ -1007,22 +993,26 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
|
@@ -1007,22 +993,26 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
1007
|
* @param sessionInfo -
|
993
|
* @param sessionInfo -
|
1008
|
*/
|
994
|
*/
|
1009
|
public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg attributesResponse, TransportProtos.SessionInfoProto sessionInfo) {
|
995
|
public void onGetAttributesResponse(TransportProtos.GetAttributeResponseMsg attributesResponse, TransportProtos.SessionInfoProto sessionInfo) {
|
1010
|
- LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(sessionInfo);
|
|
|
1011
|
- attributesResponse.getSharedAttributeListList().forEach(attr -> {
|
|
|
1012
|
- String path = this.getPathAttributeUpdate(sessionInfo, attr.getKv().getKey());
|
|
|
1013
|
- // #1.1
|
|
|
1014
|
- if (lwM2MClient.getDelayedRequests().containsKey(path) && attr.getTs() > lwM2MClient.getDelayedRequests().get(path).getTs()) {
|
|
|
1015
|
- lwM2MClient.getDelayedRequests().put(path, attr);
|
|
|
1016
|
- } else {
|
|
|
1017
|
- lwM2MClient.getDelayedRequests().put(path, attr);
|
|
|
1018
|
- }
|
|
|
1019
|
- });
|
|
|
1020
|
- // #2.1
|
|
|
1021
|
- lwM2MClient.getDelayedRequests().forEach((k, v) -> {
|
|
|
1022
|
- ArrayList<TransportProtos.KeyValueProto> listV = new ArrayList<>();
|
|
|
1023
|
- listV.add(v.getKv());
|
|
|
1024
|
- this.putDelayedUpdateResourcesClient(lwM2MClient, this.getResourceValueToString(lwM2MClient, k), getJsonObject(listV).get(v.getKv().getKey()), k);
|
|
|
1025
|
- });
|
996
|
+ try {
|
|
|
997
|
+ LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClient(sessionInfo);
|
|
|
998
|
+ attributesResponse.getSharedAttributeListList().forEach(attr -> {
|
|
|
999
|
+ String path = this.getPathAttributeUpdate(sessionInfo, attr.getKv().getKey());
|
|
|
1000
|
+ // #1.1
|
|
|
1001
|
+ if (lwM2MClient.getDelayedRequests().containsKey(path) && attr.getTs() > lwM2MClient.getDelayedRequests().get(path).getTs()) {
|
|
|
1002
|
+ lwM2MClient.getDelayedRequests().put(path, attr);
|
|
|
1003
|
+ } else {
|
|
|
1004
|
+ lwM2MClient.getDelayedRequests().put(path, attr);
|
|
|
1005
|
+ }
|
|
|
1006
|
+ });
|
|
|
1007
|
+ // #2.1
|
|
|
1008
|
+ lwM2MClient.getDelayedRequests().forEach((k, v) -> {
|
|
|
1009
|
+ ArrayList<TransportProtos.KeyValueProto> listV = new ArrayList<>();
|
|
|
1010
|
+ listV.add(v.getKv());
|
|
|
1011
|
+ this.putDelayedUpdateResourcesClient(lwM2MClient, this.getResourceValueToString(lwM2MClient, k), getJsonObject(listV).get(v.getKv().getKey()), k);
|
|
|
1012
|
+ });
|
|
|
1013
|
+ } catch (Exception e) {
|
|
|
1014
|
+ log.error(String.valueOf(e));
|
|
|
1015
|
+ }
|
1026
|
}
|
1016
|
}
|
1027
|
|
1017
|
|
1028
|
/**
|
1018
|
/**
|