Browse Source

Merge pull request #5644 from YevhenBondarenko/fix/lwm2m

[3.3.3] fixed lwm2m device or profile update notifications
pull/5715/head
Andrew Shvayka 5 years ago
committed by GitHub
parent
commit
3038f23a93
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2MUplinkMsgHandler.java

21
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2MUplinkMsgHandler.java

@ -378,9 +378,13 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
List<LwM2mClient> clients = clientContext.getLwM2mClients()
.stream().filter(e -> e.getProfileId() != null)
.filter(e -> e.getProfileId().equals(deviceProfile.getUuidId())).collect(Collectors.toList());
clients.forEach(client -> client.onDeviceProfileUpdate(deviceProfile));
clients.forEach(client -> {
this.securityStore.remove(client.getEndpoint(), client.getRegistration().getId());
client.onDeviceProfileUpdate(deviceProfile);
});
if (clients.size() > 0) {
this.onDeviceProfileUpdate(clients, deviceProfile);
var oldProfile = clientContext.getProfile(deviceProfile.getUuidId());
this.onDeviceProfileUpdate(clients, oldProfile, deviceProfile);
}
} catch (Exception e) {
log.warn("[{}] failed to update profile: {}", deviceProfile.getId(), deviceProfile);
@ -388,11 +392,14 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
}
@Override
public void onDeviceUpdate(SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> deviceProfileOpt) {
public void onDeviceUpdate(SessionInfoProto sessionInfo, Device device, Optional<DeviceProfile> newDeviceProfileOpt) {
try {
LwM2mClient client = clientContext.getClientByDeviceId(device.getUuidId());
if (client != null) {
this.onDeviceUpdate(client, device, deviceProfileOpt);
if (newDeviceProfileOpt.isPresent()) {
this.securityStore.remove(client.getEndpoint(), client.getRegistration().getId());
}
this.onDeviceUpdate(client, device, newDeviceProfileOpt);
}
} catch (Exception e) {
log.warn("[{}] failed to update device: {}", device.getId(), device);
@ -645,7 +652,8 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
}
private void onDeviceUpdate(LwM2mClient lwM2MClient, Device device, Optional<DeviceProfile> deviceProfileOpt) {
deviceProfileOpt.ifPresent(deviceProfile -> this.onDeviceProfileUpdate(Collections.singletonList(lwM2MClient), deviceProfile));
var oldProfile = clientContext.getProfile(lwM2MClient.getProfileId());
deviceProfileOpt.ifPresent(deviceProfile -> this.onDeviceProfileUpdate(Collections.singletonList(lwM2MClient), oldProfile, deviceProfile));
lwM2MClient.onDeviceUpdate(device, deviceProfileOpt);
}
@ -754,8 +762,7 @@ public class DefaultLwM2MUplinkMsgHandler extends LwM2MExecutorAwareService impl
}
//TODO: review and optimize the logic to minimize number of the requests to device.
private void onDeviceProfileUpdate(List<LwM2mClient> clients, DeviceProfile deviceProfile) {
var oldProfile = clientContext.getProfile(deviceProfile.getUuidId());
private void onDeviceProfileUpdate(List<LwM2mClient> clients, Lwm2mDeviceProfileTransportConfiguration oldProfile, DeviceProfile deviceProfile) {
if (clientContext.profileUpdate(deviceProfile) != null) {
// #1
TelemetryMappingConfiguration oldTelemetryParams = oldProfile.getObserveAttr();

Loading…
Cancel
Save