Merge pull request #7041 from YevhenBondarenko/device-state-improvements
[3.4.1] fixed update or remove inactivityTimeout kv
This commit is contained in:
commit
1be7deee5f
@ -278,17 +278,16 @@ public class DefaultDeviceStateService extends AbstractPartitionBasedService<Dev
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeviceInactivityTimeoutUpdate(TenantId tenantId, DeviceId deviceId, long inactivityTimeout) {
|
public void onDeviceInactivityTimeoutUpdate(TenantId tenantId, DeviceId deviceId, long inactivityTimeout) {
|
||||||
if (inactivityTimeout <= 0L) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cleanDeviceStateIfBelongsExternalPartition(tenantId, deviceId)) {
|
if (cleanDeviceStateIfBelongsExternalPartition(tenantId, deviceId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (inactivityTimeout <= 0L) {
|
||||||
|
inactivityTimeout = defaultInactivityTimeoutInSec;
|
||||||
|
}
|
||||||
log.trace("on Device Activity Timeout Update device id {} inactivityTimeout {}", deviceId, inactivityTimeout);
|
log.trace("on Device Activity Timeout Update device id {} inactivityTimeout {}", deviceId, inactivityTimeout);
|
||||||
DeviceStateData stateData = getOrFetchDeviceStateData(deviceId);
|
DeviceStateData stateData = getOrFetchDeviceStateData(deviceId);
|
||||||
stateData.getState().setInactivityTimeout(inactivityTimeout);
|
stateData.getState().setInactivityTimeout(inactivityTimeout);
|
||||||
checkAndUpdateState(deviceId, stateData);
|
checkAndUpdateState(deviceId, stateData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -278,7 +278,15 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
private void updateDeviceInactivityTimeout(TenantId tenantId, EntityId entityId, List<? extends KvEntry> kvEntries) {
|
private void updateDeviceInactivityTimeout(TenantId tenantId, EntityId entityId, List<? extends KvEntry> kvEntries) {
|
||||||
for (KvEntry kvEntry : kvEntries) {
|
for (KvEntry kvEntry : kvEntries) {
|
||||||
if (kvEntry.getKey().equals(DefaultDeviceStateService.INACTIVITY_TIMEOUT)) {
|
if (kvEntry.getKey().equals(DefaultDeviceStateService.INACTIVITY_TIMEOUT)) {
|
||||||
deviceStateService.onDeviceInactivityTimeoutUpdate(tenantId, new DeviceId(entityId.getId()), kvEntry.getLongValue().orElse(0L));
|
deviceStateService.onDeviceInactivityTimeoutUpdate(tenantId, new DeviceId(entityId.getId()), getLongValue(kvEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteDeviceInactivityTimeout(TenantId tenantId, EntityId entityId, List<String> keys) {
|
||||||
|
for (String key : keys) {
|
||||||
|
if (key.equals(DefaultDeviceStateService.INACTIVITY_TIMEOUT)) {
|
||||||
|
deviceStateService.onDeviceInactivityTimeoutUpdate(tenantId, new DeviceId(entityId.getId()), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,6 +348,9 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
}
|
}
|
||||||
return subscriptionUpdate;
|
return subscriptionUpdate;
|
||||||
}, false);
|
}, false);
|
||||||
|
if (entityId.getEntityType() == EntityType.DEVICE) {
|
||||||
|
deleteDeviceInactivityTimeout(tenantId, entityId, keys);
|
||||||
|
}
|
||||||
callback.onSuccess();
|
callback.onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,6 +375,9 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
}
|
}
|
||||||
return subscriptionUpdate;
|
return subscriptionUpdate;
|
||||||
}, false);
|
}, false);
|
||||||
|
if (entityId.getEntityType() == EntityType.DEVICE) {
|
||||||
|
deleteDeviceInactivityTimeout(tenantId, entityId, keys);
|
||||||
|
}
|
||||||
callback.onSuccess();
|
callback.onSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,4 +571,27 @@ public class DefaultSubscriptionManagerService extends TbApplicationEventListene
|
|||||||
return new TbProtoQueueMsg<>(subscription.getEntityId().getId(), toCoreMsg);
|
return new TbProtoQueueMsg<>(subscription.getEntityId().getId(), toCoreMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long getLongValue(KvEntry kve) {
|
||||||
|
switch (kve.getDataType()) {
|
||||||
|
case LONG:
|
||||||
|
return kve.getLongValue().orElse(0L);
|
||||||
|
case DOUBLE:
|
||||||
|
return kve.getDoubleValue().orElse(0.0).longValue();
|
||||||
|
case STRING:
|
||||||
|
try {
|
||||||
|
return Long.parseLong(kve.getStrValue().orElse("0"));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
case JSON:
|
||||||
|
try {
|
||||||
|
return Long.parseLong(kve.getJsonValue().orElse("0"));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user