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