Commit 765ced2954d822b22cd68ebc75b1fe8d027bc3c4

Authored by Igor Kulikov
2 parents d13116db d5bf25e2

Merge branch 'master' of github.com:thingsboard/thingsboard

... ... @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
20 20 import io.netty.channel.EventLoopGroup;
21 21 import lombok.extern.slf4j.Slf4j;
22 22 import org.springframework.data.redis.core.RedisTemplate;
  23 +import org.springframework.util.StringUtils;
23 24 import org.thingsboard.common.util.ListeningExecutor;
24 25 import org.thingsboard.rule.engine.api.MailService;
25 26 import org.thingsboard.rule.engine.api.RuleEngineAlarmService;
... ... @@ -47,6 +48,7 @@ import org.thingsboard.server.common.data.rule.RuleNodeState;
47 48 import org.thingsboard.server.common.msg.TbActorMsg;
48 49 import org.thingsboard.server.common.msg.TbMsg;
49 50 import org.thingsboard.server.common.msg.TbMsgMetaData;
  51 +import org.thingsboard.server.common.msg.queue.ServiceQueue;
50 52 import org.thingsboard.server.common.msg.queue.ServiceType;
51 53 import org.thingsboard.server.common.msg.queue.TopicPartitionInfo;
52 54 import org.thingsboard.server.dao.asset.AssetService;
... ... @@ -183,6 +185,9 @@ class DefaultTbContext implements TbContext {
183 185 }
184 186
185 187 private TopicPartitionInfo resolvePartition(TbMsg tbMsg, String queueName) {
  188 + if (StringUtils.isEmpty(queueName)) {
  189 + queueName = ServiceQueue.MAIN;
  190 + }
186 191 return mainCtx.resolve(ServiceType.TB_RULE_ENGINE, queueName, getTenantId(), tbMsg.getOriginator());
187 192 }
188 193
... ...
... ... @@ -74,6 +74,8 @@ public class DefaultTbDeviceProfileCache implements TbDeviceProfileCache {
74 74 if (device != null) {
75 75 profileId = device.getDeviceProfileId();
76 76 devicesMap.put(deviceId, profileId);
  77 + } else {
  78 + return null;
77 79 }
78 80 }
79 81 return get(tenantId, profileId);
... ...
... ... @@ -392,7 +392,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
392 392 if (stateData != null) {
393 393 DeviceState state = stateData.getState();
394 394 state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout());
395   - if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime())) {
  395 + if (!state.isActive() && (state.getLastInactivityAlarmTime() == 0L || state.getLastInactivityAlarmTime() < state.getLastActivityTime()) && stateData.getDeviceCreationTime() + state.getInactivityTimeout() < ts) {
396 396 state.setLastInactivityAlarmTime(ts);
397 397 pushRuleEngineMessage(stateData, INACTIVITY_EVENT);
398 398 save(deviceId, INACTIVITY_ALARM_TIME, ts);
... ... @@ -479,6 +479,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
479 479 return DeviceStateData.builder()
480 480 .tenantId(device.getTenantId())
481 481 .deviceId(device.getId())
  482 + .deviceCreationTime(device.getCreatedTime())
482 483 .metaData(md)
483 484 .state(deviceState).build();
484 485 } catch (Exception e) {
... ...
... ... @@ -30,8 +30,8 @@ class DeviceStateData {
30 30
31 31 private final TenantId tenantId;
32 32 private final DeviceId deviceId;
33   -
  33 + private final long deviceCreationTime;
34 34 private TbMsgMetaData metaData;
35 35 private final DeviceState state;
36   -
  36 +
37 37 }
... ...