Commit a9b09da1e60731b100b3781830867ee51d36b05f
1 parent
de38a776
Implemented Transport support for the new rule engine
Showing
113 changed files
with
804 additions
and
646 deletions
@@ -61,6 +61,7 @@ import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; | @@ -61,6 +61,7 @@ import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; | ||
61 | import org.thingsboard.server.service.component.ComponentDiscoveryService; | 61 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
62 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; | 62 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
63 | import org.thingsboard.server.service.mail.MailExecutorService; | 63 | import org.thingsboard.server.service.mail.MailExecutorService; |
64 | +import org.thingsboard.server.service.rpc.DeviceRpcService; | ||
64 | import org.thingsboard.server.service.script.JsExecutorService; | 65 | import org.thingsboard.server.service.script.JsExecutorService; |
65 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; | 66 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
66 | 67 | ||
@@ -163,6 +164,10 @@ public class ActorSystemContext { | @@ -163,6 +164,10 @@ public class ActorSystemContext { | ||
163 | 164 | ||
164 | @Autowired | 165 | @Autowired |
165 | @Getter | 166 | @Getter |
167 | + private DeviceRpcService deviceRpcService; | ||
168 | + | ||
169 | + @Autowired | ||
170 | + @Getter | ||
166 | @Setter | 171 | @Setter |
167 | private PluginWebSocketMsgEndpoint wsMsgEndpoint; | 172 | private PluginWebSocketMsgEndpoint wsMsgEndpoint; |
168 | 173 | ||
@@ -186,17 +191,13 @@ public class ActorSystemContext { | @@ -186,17 +191,13 @@ public class ActorSystemContext { | ||
186 | @Getter | 191 | @Getter |
187 | private long syncSessionTimeout; | 192 | private long syncSessionTimeout; |
188 | 193 | ||
189 | - @Value("${actors.plugin.termination.delay}") | ||
190 | - @Getter | ||
191 | - private long pluginActorTerminationDelay; | ||
192 | - | ||
193 | - @Value("${actors.plugin.processing.timeout}") | 194 | + @Value("${actors.queue.enabled}") |
194 | @Getter | 195 | @Getter |
195 | - private long pluginProcessingTimeout; | 196 | + private boolean queuePersistenceEnabled; |
196 | 197 | ||
197 | - @Value("${actors.plugin.error_persist_frequency}") | 198 | + @Value("${actors.queue.timeout}") |
198 | @Getter | 199 | @Getter |
199 | - private long pluginErrorPersistFrequency; | 200 | + private long queuePersistenceTimeout; |
200 | 201 | ||
201 | @Value("${actors.rule.chain.error_persist_frequency}") | 202 | @Value("${actors.rule.chain.error_persist_frequency}") |
202 | @Getter | 203 | @Getter |
@@ -206,14 +207,6 @@ public class ActorSystemContext { | @@ -206,14 +207,6 @@ public class ActorSystemContext { | ||
206 | @Getter | 207 | @Getter |
207 | private long ruleNodeErrorPersistFrequency; | 208 | private long ruleNodeErrorPersistFrequency; |
208 | 209 | ||
209 | - @Value("${actors.rule.termination.delay}") | ||
210 | - @Getter | ||
211 | - private long ruleActorTerminationDelay; | ||
212 | - | ||
213 | - @Value("${actors.rule.error_persist_frequency}") | ||
214 | - @Getter | ||
215 | - private long ruleErrorPersistFrequency; | ||
216 | - | ||
217 | @Value("${actors.statistics.enabled}") | 210 | @Value("${actors.statistics.enabled}") |
218 | @Getter | 211 | @Getter |
219 | private boolean statisticsEnabled; | 212 | private boolean statisticsEnabled; |
@@ -29,13 +29,12 @@ import org.thingsboard.server.actors.shared.plugin.SystemPluginManager; | @@ -29,13 +29,12 @@ import org.thingsboard.server.actors.shared.plugin.SystemPluginManager; | ||
29 | import org.thingsboard.server.actors.shared.rulechain.SystemRuleChainManager; | 29 | import org.thingsboard.server.actors.shared.rulechain.SystemRuleChainManager; |
30 | import org.thingsboard.server.actors.tenant.TenantActor; | 30 | import org.thingsboard.server.actors.tenant.TenantActor; |
31 | import org.thingsboard.server.common.data.Tenant; | 31 | import org.thingsboard.server.common.data.Tenant; |
32 | -import org.thingsboard.server.common.data.id.PluginId; | ||
33 | -import org.thingsboard.server.common.data.id.RuleChainId; | ||
34 | import org.thingsboard.server.common.data.id.TenantId; | 32 | import org.thingsboard.server.common.data.id.TenantId; |
35 | import org.thingsboard.server.common.data.page.PageDataIterable; | 33 | import org.thingsboard.server.common.data.page.PageDataIterable; |
36 | import org.thingsboard.server.common.msg.TbActorMsg; | 34 | import org.thingsboard.server.common.msg.TbActorMsg; |
37 | -import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | ||
38 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 35 | +import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
36 | +import org.thingsboard.server.common.msg.aware.TenantAwareMsg; | ||
37 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | ||
39 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | 38 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
40 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | 39 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
41 | import org.thingsboard.server.dao.model.ModelConstants; | 40 | import org.thingsboard.server.dao.model.ModelConstants; |
@@ -90,12 +89,22 @@ public class AppActor extends RuleChainManagerActor { | @@ -90,12 +89,22 @@ public class AppActor extends RuleChainManagerActor { | ||
90 | @Override | 89 | @Override |
91 | protected boolean process(TbActorMsg msg) { | 90 | protected boolean process(TbActorMsg msg) { |
92 | switch (msg.getMsgType()) { | 91 | switch (msg.getMsgType()) { |
92 | + case CLUSTER_EVENT_MSG: | ||
93 | + broadcast(msg); | ||
94 | + break; | ||
93 | case COMPONENT_LIFE_CYCLE_MSG: | 95 | case COMPONENT_LIFE_CYCLE_MSG: |
94 | onComponentLifecycleMsg((ComponentLifecycleMsg) msg); | 96 | onComponentLifecycleMsg((ComponentLifecycleMsg) msg); |
95 | break; | 97 | break; |
96 | case SERVICE_TO_RULE_ENGINE_MSG: | 98 | case SERVICE_TO_RULE_ENGINE_MSG: |
97 | onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); | 99 | onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); |
98 | break; | 100 | break; |
101 | + case DEVICE_SESSION_TO_DEVICE_ACTOR_MSG: | ||
102 | + case DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
103 | + case DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
104 | + case DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
105 | + case DEVICE_RPC_REQUEST_TO_DEVICE_ACTOR_MSG: | ||
106 | + onToDeviceActorMsg((DeviceToDeviceActorMsg) msg); | ||
107 | + break; | ||
99 | default: | 108 | default: |
100 | return false; | 109 | return false; |
101 | } | 110 | } |
@@ -110,48 +119,12 @@ public class AppActor extends RuleChainManagerActor { | @@ -110,48 +119,12 @@ public class AppActor extends RuleChainManagerActor { | ||
110 | } | 119 | } |
111 | } | 120 | } |
112 | 121 | ||
113 | - | ||
114 | -// @Override | ||
115 | -// public void onReceive(Object msg) throws Exception { | ||
116 | -// logger.debug("Received message: {}", msg); | ||
117 | -// if (msg instanceof ToDeviceActorMsg) { | ||
118 | -// processDeviceMsg((ToDeviceActorMsg) msg); | ||
119 | -// } else if (msg instanceof ToPluginActorMsg) { | ||
120 | -// onToPluginMsg((ToPluginActorMsg) msg); | ||
121 | -// } else if (msg instanceof ToDeviceActorNotificationMsg) { | ||
122 | -// onToDeviceActorMsg((ToDeviceActorNotificationMsg) msg); | ||
123 | -// } else if (msg instanceof Terminated) { | ||
124 | -// processTermination((Terminated) msg); | ||
125 | -// } else if (msg instanceof ClusterEventMsg) { | ||
126 | -// broadcast(msg); | ||
127 | -// } else if (msg instanceof ComponentLifecycleMsg) { | ||
128 | -// onComponentLifecycleMsg((ComponentLifecycleMsg) msg); | ||
129 | -// } else if (msg instanceof PluginTerminationMsg) { | ||
130 | -// onPluginTerminated((PluginTerminationMsg) msg); | ||
131 | -// } else { | ||
132 | -// logger.warning("Unknown message: {}!", msg); | ||
133 | -// } | ||
134 | -// } | ||
135 | - | ||
136 | - private void onPluginTerminated(PluginTerminationMsg msg) { | ||
137 | - pluginManager.remove(msg.getId()); | ||
138 | - } | ||
139 | - | ||
140 | - private void broadcast(Object msg) { | ||
141 | - pluginManager.broadcast(msg); | 122 | + @Override |
123 | + protected void broadcast(Object msg) { | ||
124 | + super.broadcast(msg); | ||
142 | tenantActors.values().forEach(actorRef -> actorRef.tell(msg, ActorRef.noSender())); | 125 | tenantActors.values().forEach(actorRef -> actorRef.tell(msg, ActorRef.noSender())); |
143 | } | 126 | } |
144 | 127 | ||
145 | - private void onToPluginMsg(ToPluginActorMsg msg) { | ||
146 | - ActorRef target; | ||
147 | - if (SYSTEM_TENANT.equals(msg.getPluginTenantId())) { | ||
148 | - target = pluginManager.getOrCreateActor(this.context(), msg.getPluginId()); | ||
149 | - } else { | ||
150 | - target = getOrCreateTenantActor(msg.getPluginTenantId()); | ||
151 | - } | ||
152 | - target.tell(msg, ActorRef.noSender()); | ||
153 | - } | ||
154 | - | ||
155 | private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) { | 128 | private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) { |
156 | ActorRef target; | 129 | ActorRef target; |
157 | if (SYSTEM_TENANT.equals(msg.getTenantId())) { | 130 | if (SYSTEM_TENANT.equals(msg.getTenantId())) { |
@@ -166,17 +139,17 @@ public class AppActor extends RuleChainManagerActor { | @@ -166,17 +139,17 @@ public class AppActor extends RuleChainManagerActor { | ||
166 | } | 139 | } |
167 | } | 140 | } |
168 | 141 | ||
169 | - private void onToDeviceActorMsg(ToDeviceActorNotificationMsg msg) { | 142 | + private void onToDeviceActorMsg(TenantAwareMsg msg) { |
170 | getOrCreateTenantActor(msg.getTenantId()).tell(msg, ActorRef.noSender()); | 143 | getOrCreateTenantActor(msg.getTenantId()).tell(msg, ActorRef.noSender()); |
171 | } | 144 | } |
172 | 145 | ||
173 | - private void processDeviceMsg(ToDeviceActorMsg toDeviceActorMsg) { | ||
174 | - TenantId tenantId = toDeviceActorMsg.getTenantId(); | 146 | + private void processDeviceMsg(DeviceToDeviceActorMsg deviceToDeviceActorMsg) { |
147 | + TenantId tenantId = deviceToDeviceActorMsg.getTenantId(); | ||
175 | ActorRef tenantActor = getOrCreateTenantActor(tenantId); | 148 | ActorRef tenantActor = getOrCreateTenantActor(tenantId); |
176 | - if (toDeviceActorMsg.getPayload().getMsgType().requiresRulesProcessing()) { | ||
177 | -// tenantActor.tell(new RuleChainDeviceMsg(toDeviceActorMsg, ruleManager.getRuleChain(this.context())), context().self()); | 149 | + if (deviceToDeviceActorMsg.getPayload().getMsgType().requiresRulesProcessing()) { |
150 | +// tenantActor.tell(new RuleChainDeviceMsg(deviceToDeviceActorMsg, ruleManager.getRuleChain(this.context())), context().self()); | ||
178 | } else { | 151 | } else { |
179 | - tenantActor.tell(toDeviceActorMsg, context().self()); | 152 | + tenantActor.tell(deviceToDeviceActorMsg, context().self()); |
180 | } | 153 | } |
181 | } | 154 | } |
182 | 155 |
@@ -24,59 +24,59 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -24,59 +24,59 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
24 | import org.thingsboard.server.common.data.id.TenantId; | 24 | import org.thingsboard.server.common.data.id.TenantId; |
25 | import org.thingsboard.server.common.msg.TbActorMsg; | 25 | import org.thingsboard.server.common.msg.TbActorMsg; |
26 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 26 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
27 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 27 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
28 | +import org.thingsboard.server.common.msg.timeout.DeviceActorQueueTimeoutMsg; | ||
29 | +import org.thingsboard.server.common.msg.timeout.DeviceActorRpcTimeoutMsg; | ||
28 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | 30 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
29 | -import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; | ||
30 | import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; | 31 | import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; |
31 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
32 | -import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; | ||
33 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | 32 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; |
33 | +import org.thingsboard.server.service.rpc.ToDeviceRpcRequestMsg; | ||
34 | 34 | ||
35 | public class DeviceActor extends ContextAwareActor { | 35 | public class DeviceActor extends ContextAwareActor { |
36 | 36 | ||
37 | private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); | 37 | private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); |
38 | 38 | ||
39 | - private final TenantId tenantId; | ||
40 | - private final DeviceId deviceId; | ||
41 | private final DeviceActorMessageProcessor processor; | 39 | private final DeviceActorMessageProcessor processor; |
42 | 40 | ||
43 | private DeviceActor(ActorSystemContext systemContext, TenantId tenantId, DeviceId deviceId) { | 41 | private DeviceActor(ActorSystemContext systemContext, TenantId tenantId, DeviceId deviceId) { |
44 | super(systemContext); | 42 | super(systemContext); |
45 | - this.tenantId = tenantId; | ||
46 | - this.deviceId = deviceId; | ||
47 | - this.processor = new DeviceActorMessageProcessor(systemContext, logger, deviceId); | 43 | + this.processor = new DeviceActorMessageProcessor(systemContext, logger, tenantId, deviceId); |
48 | } | 44 | } |
49 | 45 | ||
50 | @Override | 46 | @Override |
51 | protected boolean process(TbActorMsg msg) { | 47 | protected boolean process(TbActorMsg msg) { |
52 | - return false; | ||
53 | - } | ||
54 | - | ||
55 | - @Override | ||
56 | - public void onReceive(Object msg) throws Exception { | ||
57 | -// if (msg instanceof RuleChainDeviceMsg) { | ||
58 | -// processor.process(context(), (RuleChainDeviceMsg) msg); | ||
59 | -// } else if (msg instanceof RulesProcessedMsg) { | ||
60 | -// processor.onRulesProcessedMsg(context(), (RulesProcessedMsg) msg); | ||
61 | - if (msg instanceof ToDeviceActorMsg) { | ||
62 | - processor.process(context(), (ToDeviceActorMsg) msg); | ||
63 | - } else if (msg instanceof ToDeviceActorNotificationMsg) { | ||
64 | - if (msg instanceof DeviceAttributesEventNotificationMsg) { | 48 | + switch (msg.getMsgType()) { |
49 | + case CLUSTER_EVENT_MSG: | ||
50 | + processor.processClusterEventMsg((ClusterEventMsg) msg); | ||
51 | + break; | ||
52 | + case DEVICE_SESSION_TO_DEVICE_ACTOR_MSG: | ||
53 | + processor.process(context(), (DeviceToDeviceActorMsg) msg); | ||
54 | + break; | ||
55 | + case DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
65 | processor.processAttributesUpdate(context(), (DeviceAttributesEventNotificationMsg) msg); | 56 | processor.processAttributesUpdate(context(), (DeviceAttributesEventNotificationMsg) msg); |
66 | - } else if (msg instanceof ToDeviceRpcRequestPluginMsg) { | ||
67 | - processor.processRpcRequest(context(), (ToDeviceRpcRequestPluginMsg) msg); | ||
68 | - } else if (msg instanceof DeviceCredentialsUpdateNotificationMsg){ | 57 | + break; |
58 | + case DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
69 | processor.processCredentialsUpdate(); | 59 | processor.processCredentialsUpdate(); |
70 | - } else if (msg instanceof DeviceNameOrTypeUpdateMsg){ | 60 | + break; |
61 | + case DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
71 | processor.processNameOrTypeUpdate((DeviceNameOrTypeUpdateMsg) msg); | 62 | processor.processNameOrTypeUpdate((DeviceNameOrTypeUpdateMsg) msg); |
72 | - } | ||
73 | - } else if (msg instanceof TimeoutMsg) { | ||
74 | - processor.processTimeout(context(), (TimeoutMsg) msg); | ||
75 | - } else if (msg instanceof ClusterEventMsg) { | ||
76 | - processor.processClusterEventMsg((ClusterEventMsg) msg); | ||
77 | - } else { | ||
78 | - logger.debug("[{}][{}] Unknown msg type.", tenantId, deviceId, msg.getClass().getName()); | 63 | + break; |
64 | + case DEVICE_RPC_REQUEST_TO_DEVICE_ACTOR_MSG: | ||
65 | + processor.processRpcRequest(context(), (ToDeviceRpcRequestMsg) msg); | ||
66 | + break; | ||
67 | + case DEVICE_ACTOR_RPC_TIMEOUT_MSG: | ||
68 | + processor.processRpcTimeout(context(), (DeviceActorRpcTimeoutMsg) msg); | ||
69 | + break; | ||
70 | + case DEVICE_ACTOR_QUEUE_TIMEOUT_MSG: | ||
71 | + processor.processQueueTimeout(context(), (DeviceActorQueueTimeoutMsg) msg); | ||
72 | + break; | ||
73 | + case RULE_ENGINE_QUEUE_PUT_ACK_MSG: | ||
74 | + processor.processQueueAck(context(), (RuleEngineQueuePutAckMsg) msg); | ||
75 | + break; | ||
76 | + default: | ||
77 | + return false; | ||
79 | } | 78 | } |
79 | + return true; | ||
80 | } | 80 | } |
81 | 81 | ||
82 | public static class ActorCreator extends ContextBasedCreator<DeviceActor> { | 82 | public static class ActorCreator extends ContextBasedCreator<DeviceActor> { |
@@ -18,31 +18,63 @@ package org.thingsboard.server.actors.device; | @@ -18,31 +18,63 @@ package org.thingsboard.server.actors.device; | ||
18 | import akka.actor.ActorContext; | 18 | import akka.actor.ActorContext; |
19 | import akka.actor.ActorRef; | 19 | import akka.actor.ActorRef; |
20 | import akka.event.LoggingAdapter; | 20 | import akka.event.LoggingAdapter; |
21 | +import com.datastax.driver.core.utils.UUIDs; | ||
22 | +import com.google.gson.Gson; | ||
23 | +import com.google.gson.JsonArray; | ||
24 | +import com.google.gson.JsonObject; | ||
21 | import org.thingsboard.server.actors.ActorSystemContext; | 25 | import org.thingsboard.server.actors.ActorSystemContext; |
22 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; | 26 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; |
23 | import org.thingsboard.server.common.data.DataConstants; | 27 | import org.thingsboard.server.common.data.DataConstants; |
24 | import org.thingsboard.server.common.data.Device; | 28 | import org.thingsboard.server.common.data.Device; |
25 | import org.thingsboard.server.common.data.id.DeviceId; | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
26 | import org.thingsboard.server.common.data.id.SessionId; | 30 | import org.thingsboard.server.common.data.id.SessionId; |
31 | +import org.thingsboard.server.common.data.id.TenantId; | ||
27 | import org.thingsboard.server.common.data.kv.AttributeKey; | 32 | import org.thingsboard.server.common.data.kv.AttributeKey; |
28 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 33 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
34 | +import org.thingsboard.server.common.data.kv.KvEntry; | ||
29 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | 35 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
36 | +import org.thingsboard.server.common.msg.TbMsg; | ||
37 | +import org.thingsboard.server.common.msg.TbMsgDataType; | ||
38 | +import org.thingsboard.server.common.msg.TbMsgMetaData; | ||
30 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 39 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
31 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 40 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
32 | -import org.thingsboard.server.common.msg.core.*; | ||
33 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 41 | +import org.thingsboard.server.common.msg.core.AttributesUpdateNotification; |
42 | +import org.thingsboard.server.common.msg.core.BasicCommandAckResponse; | ||
43 | +import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; | ||
44 | +import org.thingsboard.server.common.msg.core.BasicToDeviceSessionActorMsg; | ||
45 | +import org.thingsboard.server.common.msg.core.RuleEngineError; | ||
46 | +import org.thingsboard.server.common.msg.core.RuleEngineErrorMsg; | ||
47 | +import org.thingsboard.server.common.msg.core.SessionCloseMsg; | ||
48 | +import org.thingsboard.server.common.msg.core.SessionCloseNotification; | ||
49 | +import org.thingsboard.server.common.msg.core.SessionOpenMsg; | ||
50 | +import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | ||
51 | +import org.thingsboard.server.common.msg.core.ToDeviceRpcRequestMsg; | ||
52 | +import org.thingsboard.server.common.msg.core.ToDeviceRpcResponseMsg; | ||
53 | +import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; | ||
54 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | ||
34 | import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg; | 55 | import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg; |
35 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 56 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
36 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 57 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
37 | -import org.thingsboard.server.common.msg.session.MsgType; | 58 | +import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
59 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
60 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
38 | import org.thingsboard.server.common.msg.session.SessionType; | 61 | import org.thingsboard.server.common.msg.session.SessionType; |
39 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 62 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
40 | -import org.thingsboard.server.extensions.api.device.DeviceAttributes; | 63 | +import org.thingsboard.server.common.msg.timeout.DeviceActorQueueTimeoutMsg; |
64 | +import org.thingsboard.server.common.msg.timeout.DeviceActorRpcTimeoutMsg; | ||
41 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | 65 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
42 | import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; | 66 | import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; |
43 | -import org.thingsboard.server.extensions.api.plugins.msg.*; | ||
44 | - | ||
45 | -import java.util.*; | 67 | +import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
68 | +import org.thingsboard.server.extensions.api.plugins.msg.RpcError; | ||
69 | + | ||
70 | +import java.util.ArrayList; | ||
71 | +import java.util.HashMap; | ||
72 | +import java.util.HashSet; | ||
73 | +import java.util.List; | ||
74 | +import java.util.Map; | ||
75 | +import java.util.Optional; | ||
76 | +import java.util.Set; | ||
77 | +import java.util.UUID; | ||
46 | import java.util.concurrent.ExecutionException; | 78 | import java.util.concurrent.ExecutionException; |
47 | import java.util.concurrent.TimeoutException; | 79 | import java.util.concurrent.TimeoutException; |
48 | import java.util.function.Consumer; | 80 | import java.util.function.Consumer; |
@@ -54,25 +86,30 @@ import java.util.stream.Collectors; | @@ -54,25 +86,30 @@ import java.util.stream.Collectors; | ||
54 | */ | 86 | */ |
55 | public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { | 87 | public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
56 | 88 | ||
89 | + private final TenantId tenantId; | ||
57 | private final DeviceId deviceId; | 90 | private final DeviceId deviceId; |
58 | private final Map<SessionId, SessionInfo> sessions; | 91 | private final Map<SessionId, SessionInfo> sessions; |
59 | private final Map<SessionId, SessionInfo> attributeSubscriptions; | 92 | private final Map<SessionId, SessionInfo> attributeSubscriptions; |
60 | private final Map<SessionId, SessionInfo> rpcSubscriptions; | 93 | private final Map<SessionId, SessionInfo> rpcSubscriptions; |
61 | - | ||
62 | private final Map<Integer, ToDeviceRpcRequestMetadata> rpcPendingMap; | 94 | private final Map<Integer, ToDeviceRpcRequestMetadata> rpcPendingMap; |
95 | + private final Map<UUID, PendingSessionMsgData> pendingMsgs; | ||
96 | + | ||
97 | + private final Gson gson = new Gson(); | ||
63 | 98 | ||
64 | private int rpcSeq = 0; | 99 | private int rpcSeq = 0; |
65 | private String deviceName; | 100 | private String deviceName; |
66 | private String deviceType; | 101 | private String deviceType; |
67 | - private DeviceAttributes deviceAttributes; | 102 | + private TbMsgMetaData defaultMetaData; |
68 | 103 | ||
69 | - public DeviceActorMessageProcessor(ActorSystemContext systemContext, LoggingAdapter logger, DeviceId deviceId) { | 104 | + public DeviceActorMessageProcessor(ActorSystemContext systemContext, LoggingAdapter logger, TenantId tenantId, DeviceId deviceId) { |
70 | super(systemContext, logger); | 105 | super(systemContext, logger); |
106 | + this.tenantId = tenantId; | ||
71 | this.deviceId = deviceId; | 107 | this.deviceId = deviceId; |
72 | this.sessions = new HashMap<>(); | 108 | this.sessions = new HashMap<>(); |
73 | this.attributeSubscriptions = new HashMap<>(); | 109 | this.attributeSubscriptions = new HashMap<>(); |
74 | this.rpcSubscriptions = new HashMap<>(); | 110 | this.rpcSubscriptions = new HashMap<>(); |
75 | this.rpcPendingMap = new HashMap<>(); | 111 | this.rpcPendingMap = new HashMap<>(); |
112 | + this.pendingMsgs = new HashMap<>(); | ||
76 | initAttributes(); | 113 | initAttributes(); |
77 | } | 114 | } |
78 | 115 | ||
@@ -81,19 +118,12 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -81,19 +118,12 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
81 | Device device = systemContext.getDeviceService().findDeviceById(deviceId); | 118 | Device device = systemContext.getDeviceService().findDeviceById(deviceId); |
82 | this.deviceName = device.getName(); | 119 | this.deviceName = device.getName(); |
83 | this.deviceType = device.getType(); | 120 | this.deviceType = device.getType(); |
84 | - this.deviceAttributes = new DeviceAttributes(fetchAttributes(DataConstants.CLIENT_SCOPE), | ||
85 | - fetchAttributes(DataConstants.SERVER_SCOPE), fetchAttributes(DataConstants.SHARED_SCOPE)); | 121 | + this.defaultMetaData = new TbMsgMetaData(); |
122 | + this.defaultMetaData.putValue("deviceName", deviceName); | ||
123 | + this.defaultMetaData.putValue("deviceType", deviceType); | ||
86 | } | 124 | } |
87 | 125 | ||
88 | - private void refreshAttributes(DeviceAttributesEventNotificationMsg msg) { | ||
89 | - if (msg.isDeleted()) { | ||
90 | - msg.getDeletedKeys().forEach(key -> deviceAttributes.remove(key)); | ||
91 | - } else { | ||
92 | - deviceAttributes.update(msg.getScope(), msg.getValues()); | ||
93 | - } | ||
94 | - } | ||
95 | - | ||
96 | - void processRpcRequest(ActorContext context, ToDeviceRpcRequestPluginMsg msg) { | 126 | + void processRpcRequest(ActorContext context, org.thingsboard.server.service.rpc.ToDeviceRpcRequestMsg msg) { |
97 | ToDeviceRpcRequest request = msg.getMsg(); | 127 | ToDeviceRpcRequest request = msg.getMsg(); |
98 | ToDeviceRpcRequestBody body = request.getBody(); | 128 | ToDeviceRpcRequestBody body = request.getBody(); |
99 | ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg( | 129 | ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg( |
@@ -120,9 +150,8 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -120,9 +150,8 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
120 | syncSessionSet.forEach(rpcSubscriptions::remove); | 150 | syncSessionSet.forEach(rpcSubscriptions::remove); |
121 | 151 | ||
122 | if (request.isOneway() && sent) { | 152 | if (request.isOneway() && sent) { |
123 | - ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(msg, (String) null); | ||
124 | - context.parent().tell(responsePluginMsg, ActorRef.noSender()); | ||
125 | logger.debug("[{}] Rpc command response sent [{}]!", deviceId, request.getId()); | 153 | logger.debug("[{}] Rpc command response sent [{}]!", deviceId, request.getId()); |
154 | + systemContext.getDeviceRpcService().process(new FromDeviceRpcResponse(msg.getMsg().getId(), null, null)); | ||
126 | } else { | 155 | } else { |
127 | registerPendingRpcRequest(context, msg, sent, rpcRequest, timeout); | 156 | registerPendingRpcRequest(context, msg, sent, rpcRequest, timeout); |
128 | } | 157 | } |
@@ -134,18 +163,36 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -134,18 +163,36 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
134 | 163 | ||
135 | } | 164 | } |
136 | 165 | ||
137 | - private void registerPendingRpcRequest(ActorContext context, ToDeviceRpcRequestPluginMsg msg, boolean sent, ToDeviceRpcRequestMsg rpcRequest, long timeout) { | 166 | + private void registerPendingRpcRequest(ActorContext context, org.thingsboard.server.service.rpc.ToDeviceRpcRequestMsg msg, boolean sent, ToDeviceRpcRequestMsg rpcRequest, long timeout) { |
138 | rpcPendingMap.put(rpcRequest.getRequestId(), new ToDeviceRpcRequestMetadata(msg, sent)); | 167 | rpcPendingMap.put(rpcRequest.getRequestId(), new ToDeviceRpcRequestMetadata(msg, sent)); |
139 | - TimeoutIntMsg timeoutMsg = new TimeoutIntMsg(rpcRequest.getRequestId(), timeout); | 168 | + DeviceActorRpcTimeoutMsg timeoutMsg = new DeviceActorRpcTimeoutMsg(rpcRequest.getRequestId(), timeout); |
140 | scheduleMsgWithDelay(context, timeoutMsg, timeoutMsg.getTimeout()); | 169 | scheduleMsgWithDelay(context, timeoutMsg, timeoutMsg.getTimeout()); |
141 | } | 170 | } |
142 | 171 | ||
143 | - public void processTimeout(ActorContext context, TimeoutMsg msg) { | 172 | + void processRpcTimeout(ActorContext context, DeviceActorRpcTimeoutMsg msg) { |
144 | ToDeviceRpcRequestMetadata requestMd = rpcPendingMap.remove(msg.getId()); | 173 | ToDeviceRpcRequestMetadata requestMd = rpcPendingMap.remove(msg.getId()); |
145 | if (requestMd != null) { | 174 | if (requestMd != null) { |
146 | logger.debug("[{}] RPC request [{}] timeout detected!", deviceId, msg.getId()); | 175 | logger.debug("[{}] RPC request [{}] timeout detected!", deviceId, msg.getId()); |
147 | - ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(requestMd.getMsg(), requestMd.isSent() ? RpcError.TIMEOUT : RpcError.NO_ACTIVE_CONNECTION); | ||
148 | - context.parent().tell(responsePluginMsg, ActorRef.noSender()); | 176 | + systemContext.getDeviceRpcService().process(new FromDeviceRpcResponse(requestMd.getMsg().getMsg().getId(), |
177 | + null, requestMd.isSent() ? RpcError.TIMEOUT : RpcError.NO_ACTIVE_CONNECTION)); | ||
178 | + } | ||
179 | + } | ||
180 | + | ||
181 | + void processQueueTimeout(ActorContext context, DeviceActorQueueTimeoutMsg msg) { | ||
182 | + PendingSessionMsgData data = pendingMsgs.remove(msg.getId()); | ||
183 | + if (data != null) { | ||
184 | + logger.debug("[{}] Queue put [{}] timeout detected!", deviceId, msg.getId()); | ||
185 | + ToDeviceMsg toDeviceMsg = new RuleEngineErrorMsg(data.getSessionMsgType(), RuleEngineError.QUEUE_PUT_TIMEOUT); | ||
186 | + sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServerAddress()); | ||
187 | + } | ||
188 | + } | ||
189 | + | ||
190 | + void processQueueAck(ActorContext context, RuleEngineQueuePutAckMsg msg) { | ||
191 | + PendingSessionMsgData data = pendingMsgs.remove(msg.getId()); | ||
192 | + if (data != null) { | ||
193 | + logger.debug("[{}] Queue put [{}] ack detected!", deviceId, msg.getId()); | ||
194 | + ToDeviceMsg toDeviceMsg = BasicStatusCodeResponse.onSuccess(data.getSessionMsgType(), data.getRequestId()); | ||
195 | + sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(toDeviceMsg, data.getSessionId()), data.getServerAddress()); | ||
149 | } | 196 | } |
150 | } | 197 | } |
151 | 198 | ||
@@ -175,8 +222,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -175,8 +222,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
175 | ToDeviceRpcRequestBody body = request.getBody(); | 222 | ToDeviceRpcRequestBody body = request.getBody(); |
176 | if (request.isOneway()) { | 223 | if (request.isOneway()) { |
177 | sentOneWayIds.add(entry.getKey()); | 224 | sentOneWayIds.add(entry.getKey()); |
178 | - ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(entry.getValue().getMsg(), (String) null); | ||
179 | - context.parent().tell(responsePluginMsg, ActorRef.noSender()); | 225 | + systemContext.getDeviceRpcService().process(new FromDeviceRpcResponse(request.getId(), null, null)); |
180 | } | 226 | } |
181 | ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg( | 227 | ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg( |
182 | entry.getKey(), | 228 | entry.getKey(), |
@@ -188,14 +234,70 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -188,14 +234,70 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
188 | }; | 234 | }; |
189 | } | 235 | } |
190 | 236 | ||
191 | - void process(ActorContext context, ToDeviceActorMsg msg) { | 237 | + void process(ActorContext context, DeviceToDeviceActorMsg msg) { |
192 | processSubscriptionCommands(context, msg); | 238 | processSubscriptionCommands(context, msg); |
193 | processRpcResponses(context, msg); | 239 | processRpcResponses(context, msg); |
194 | processSessionStateMsgs(msg); | 240 | processSessionStateMsgs(msg); |
241 | + SessionMsgType sessionMsgType = msg.getPayload().getMsgType(); | ||
242 | + if (sessionMsgType.requiresRulesProcessing()) { | ||
243 | + switch (sessionMsgType) { | ||
244 | + case GET_ATTRIBUTES_REQUEST: | ||
245 | + handleGetAttributesRequest(msg); | ||
246 | + break; | ||
247 | + case POST_ATTRIBUTES_REQUEST: | ||
248 | + break; | ||
249 | + case POST_TELEMETRY_REQUEST: | ||
250 | + handlePostTelemetryRequest(context, msg); | ||
251 | + break; | ||
252 | + case TO_SERVER_RPC_REQUEST: | ||
253 | + break; | ||
254 | + //TODO: push to queue and start processing! | ||
255 | + } | ||
256 | + } | ||
257 | + } | ||
258 | + | ||
259 | + private void handleGetAttributesRequest(DeviceToDeviceActorMsg msg) { | ||
260 | + | ||
261 | + } | ||
262 | + | ||
263 | + private void handlePostTelemetryRequest(ActorContext context, DeviceToDeviceActorMsg src) { | ||
264 | + TelemetryUploadRequest telemetry = (TelemetryUploadRequest) src.getPayload(); | ||
265 | + | ||
266 | + Map<Long, List<KvEntry>> tsData = telemetry.getData(); | ||
267 | + | ||
268 | + JsonArray json = new JsonArray(); | ||
269 | + for (Map.Entry<Long, List<KvEntry>> entry : tsData.entrySet()) { | ||
270 | + JsonObject ts = new JsonObject(); | ||
271 | + ts.addProperty("ts", entry.getKey()); | ||
272 | + JsonObject values = new JsonObject(); | ||
273 | + for (KvEntry kv : entry.getValue()) { | ||
274 | + kv.getBooleanValue().ifPresent(v -> values.addProperty(kv.getKey(), v)); | ||
275 | + kv.getLongValue().ifPresent(v -> values.addProperty(kv.getKey(), v)); | ||
276 | + kv.getDoubleValue().ifPresent(v -> values.addProperty(kv.getKey(), v)); | ||
277 | + kv.getStrValue().ifPresent(v -> values.addProperty(kv.getKey(), v)); | ||
278 | + } | ||
279 | + ts.add("values", values); | ||
280 | + json.add(ts); | ||
281 | + } | ||
282 | + | ||
283 | + TbMsg tbMsg = new TbMsg(UUIDs.timeBased(), SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, defaultMetaData, TbMsgDataType.JSON, gson.toJson(json)); | ||
284 | + pushToRuleEngineWithTimeout(context, tbMsg, src, telemetry); | ||
285 | + } | ||
286 | + | ||
287 | + private void pushToRuleEngineWithTimeout(ActorContext context, TbMsg tbMsg, DeviceToDeviceActorMsg src, FromDeviceRequestMsg fromDeviceRequestMsg) { | ||
288 | + SessionMsgType sessionMsgType = fromDeviceRequestMsg.getMsgType(); | ||
289 | + int requestId = fromDeviceRequestMsg.getRequestId(); | ||
290 | + if (systemContext.isQueuePersistenceEnabled()) { | ||
291 | + pendingMsgs.put(tbMsg.getId(), new PendingSessionMsgData(src.getSessionId(), src.getServerAddress(), sessionMsgType, requestId)); | ||
292 | + scheduleMsgWithDelay(context, new DeviceActorQueueTimeoutMsg(tbMsg.getId(), systemContext.getQueuePersistenceTimeout()), systemContext.getQueuePersistenceTimeout()); | ||
293 | + } else { | ||
294 | + ToDeviceSessionActorMsg response = new BasicToDeviceSessionActorMsg(BasicStatusCodeResponse.onSuccess(sessionMsgType, requestId), src.getSessionId()); | ||
295 | + sendMsgToSessionActor(response, src.getServerAddress()); | ||
296 | + } | ||
297 | + context.parent().tell(new DeviceActorToRuleEngineMsg(context.self(), tbMsg), context.self()); | ||
195 | } | 298 | } |
196 | 299 | ||
197 | void processAttributesUpdate(ActorContext context, DeviceAttributesEventNotificationMsg msg) { | 300 | void processAttributesUpdate(ActorContext context, DeviceAttributesEventNotificationMsg msg) { |
198 | - refreshAttributes(msg); | ||
199 | if (attributeSubscriptions.size() > 0) { | 301 | if (attributeSubscriptions.size() > 0) { |
200 | ToDeviceMsg notification = null; | 302 | ToDeviceMsg notification = null; |
201 | if (msg.isDeleted()) { | 303 | if (msg.isDeleted()) { |
@@ -225,50 +327,29 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -225,50 +327,29 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
225 | } | 327 | } |
226 | } | 328 | } |
227 | 329 | ||
228 | -// void process(ActorContext context, RuleChainDeviceMsg srcMsg) { | ||
229 | -// ChainProcessingMetaData md = new ChainProcessingMetaData(srcMsg.getRuleChain(), | ||
230 | -// srcMsg.getToDeviceActorMsg(), new DeviceMetaData(deviceId, deviceName, deviceType, deviceAttributes), context.self()); | ||
231 | -// ChainProcessingContext ctx = new ChainProcessingContext(md); | ||
232 | -// if (ctx.getChainLength() > 0) { | ||
233 | -// RuleProcessingMsg msg = new RuleProcessingMsg(ctx); | ||
234 | -// ActorRef ruleActorRef = ctx.getCurrentActor(); | ||
235 | -// ruleActorRef.tell(msg, ActorRef.noSender()); | ||
236 | -// } else { | ||
237 | -// context.self().tell(new RulesProcessedMsg(ctx), context.self()); | ||
238 | -// } | ||
239 | -// } | ||
240 | - | ||
241 | - void processRpcResponses(ActorContext context, ToDeviceActorMsg msg) { | 330 | + private void processRpcResponses(ActorContext context, DeviceToDeviceActorMsg msg) { |
242 | SessionId sessionId = msg.getSessionId(); | 331 | SessionId sessionId = msg.getSessionId(); |
243 | FromDeviceMsg inMsg = msg.getPayload(); | 332 | FromDeviceMsg inMsg = msg.getPayload(); |
244 | - if (inMsg.getMsgType() == MsgType.TO_DEVICE_RPC_RESPONSE) { | 333 | + if (inMsg.getMsgType() == SessionMsgType.TO_DEVICE_RPC_RESPONSE) { |
245 | logger.debug("[{}] Processing rpc command response [{}]", deviceId, sessionId); | 334 | logger.debug("[{}] Processing rpc command response [{}]", deviceId, sessionId); |
246 | ToDeviceRpcResponseMsg responseMsg = (ToDeviceRpcResponseMsg) inMsg; | 335 | ToDeviceRpcResponseMsg responseMsg = (ToDeviceRpcResponseMsg) inMsg; |
247 | ToDeviceRpcRequestMetadata requestMd = rpcPendingMap.remove(responseMsg.getRequestId()); | 336 | ToDeviceRpcRequestMetadata requestMd = rpcPendingMap.remove(responseMsg.getRequestId()); |
248 | boolean success = requestMd != null; | 337 | boolean success = requestMd != null; |
249 | if (success) { | 338 | if (success) { |
250 | - ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(requestMd.getMsg(), responseMsg.getData()); | ||
251 | - Optional<ServerAddress> pluginServerAddress = requestMd.getMsg().getServerAddress(); | ||
252 | - if (pluginServerAddress.isPresent()) { | ||
253 | - systemContext.getRpcService().tell(pluginServerAddress.get(), responsePluginMsg); | ||
254 | - logger.debug("[{}] Rpc command response sent to remote plugin actor [{}]!", deviceId, requestMd.getMsg().getMsg().getId()); | ||
255 | - } else { | ||
256 | - context.parent().tell(responsePluginMsg, ActorRef.noSender()); | ||
257 | - logger.debug("[{}] Rpc command response sent to local plugin actor [{}]!", deviceId, requestMd.getMsg().getMsg().getId()); | ||
258 | - } | 339 | + systemContext.getDeviceRpcService().process(new FromDeviceRpcResponse(requestMd.getMsg().getMsg().getId(), responseMsg.getData(), null)); |
259 | } else { | 340 | } else { |
260 | logger.debug("[{}] Rpc command response [{}] is stale!", deviceId, responseMsg.getRequestId()); | 341 | logger.debug("[{}] Rpc command response [{}] is stale!", deviceId, responseMsg.getRequestId()); |
261 | } | 342 | } |
262 | if (msg.getSessionType() == SessionType.SYNC) { | 343 | if (msg.getSessionType() == SessionType.SYNC) { |
263 | BasicCommandAckResponse response = success | 344 | BasicCommandAckResponse response = success |
264 | - ? BasicCommandAckResponse.onSuccess(MsgType.TO_DEVICE_RPC_REQUEST, responseMsg.getRequestId()) | ||
265 | - : BasicCommandAckResponse.onError(MsgType.TO_DEVICE_RPC_REQUEST, responseMsg.getRequestId(), new TimeoutException()); | 345 | + ? BasicCommandAckResponse.onSuccess(SessionMsgType.TO_DEVICE_RPC_REQUEST, responseMsg.getRequestId()) |
346 | + : BasicCommandAckResponse.onError(SessionMsgType.TO_DEVICE_RPC_REQUEST, responseMsg.getRequestId(), new TimeoutException()); | ||
266 | sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(response, msg.getSessionId()), msg.getServerAddress()); | 347 | sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(response, msg.getSessionId()), msg.getServerAddress()); |
267 | } | 348 | } |
268 | } | 349 | } |
269 | } | 350 | } |
270 | 351 | ||
271 | - public void processClusterEventMsg(ClusterEventMsg msg) { | 352 | + void processClusterEventMsg(ClusterEventMsg msg) { |
272 | if (!msg.isAdded()) { | 353 | if (!msg.isAdded()) { |
273 | logger.debug("[{}] Clearing attributes/rpc subscription for server [{}]", deviceId, msg.getServerAddress()); | 354 | logger.debug("[{}] Clearing attributes/rpc subscription for server [{}]", deviceId, msg.getServerAddress()); |
274 | Predicate<Map.Entry<SessionId, SessionInfo>> filter = e -> e.getValue().getServer() | 355 | Predicate<Map.Entry<SessionId, SessionInfo>> filter = e -> e.getValue().getServer() |
@@ -278,59 +359,27 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -278,59 +359,27 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
278 | } | 359 | } |
279 | } | 360 | } |
280 | 361 | ||
281 | - private ToPluginRpcResponseDeviceMsg toPluginRpcResponseMsg(ToDeviceRpcRequestPluginMsg requestMsg, String data) { | ||
282 | - return toPluginRpcResponseMsg(requestMsg, data, null); | ||
283 | - } | ||
284 | - | ||
285 | - private ToPluginRpcResponseDeviceMsg toPluginRpcResponseMsg(ToDeviceRpcRequestPluginMsg requestMsg, RpcError error) { | ||
286 | - return toPluginRpcResponseMsg(requestMsg, null, error); | ||
287 | - } | ||
288 | - | ||
289 | - private ToPluginRpcResponseDeviceMsg toPluginRpcResponseMsg(ToDeviceRpcRequestPluginMsg requestMsg, String data, RpcError error) { | ||
290 | - return new ToPluginRpcResponseDeviceMsg( | ||
291 | - requestMsg.getPluginId(), | ||
292 | - requestMsg.getPluginTenantId(), | ||
293 | - new FromDeviceRpcResponse(requestMsg.getMsg().getId(), | ||
294 | - data, | ||
295 | - error | ||
296 | - ) | ||
297 | - ); | ||
298 | - } | ||
299 | - | ||
300 | -// void onRulesProcessedMsg(ActorContext context, RulesProcessedMsg msg) { | ||
301 | -// ChainProcessingContext ctx = msg.getCtx(); | ||
302 | -// ToDeviceActorMsg inMsg = ctx.getInMsg(); | ||
303 | -// SessionId sid = inMsg.getSessionId(); | ||
304 | -// ToDeviceSessionActorMsg response; | ||
305 | -// if (ctx.getResponse() != null) { | ||
306 | -// response = new BasicToDeviceSessionActorMsg(ctx.getResponse(), sid); | ||
307 | -// } else { | ||
308 | -// response = new BasicToDeviceSessionActorMsg(ctx.getError(), sid); | ||
309 | -// } | ||
310 | -// sendMsgToSessionActor(response, inMsg.getServerAddress()); | ||
311 | -// } | ||
312 | - | ||
313 | - private void processSubscriptionCommands(ActorContext context, ToDeviceActorMsg msg) { | 362 | + private void processSubscriptionCommands(ActorContext context, DeviceToDeviceActorMsg msg) { |
314 | SessionId sessionId = msg.getSessionId(); | 363 | SessionId sessionId = msg.getSessionId(); |
315 | SessionType sessionType = msg.getSessionType(); | 364 | SessionType sessionType = msg.getSessionType(); |
316 | FromDeviceMsg inMsg = msg.getPayload(); | 365 | FromDeviceMsg inMsg = msg.getPayload(); |
317 | - if (inMsg.getMsgType() == MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST) { | 366 | + if (inMsg.getMsgType() == SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST) { |
318 | logger.debug("[{}] Registering attributes subscription for session [{}]", deviceId, sessionId); | 367 | logger.debug("[{}] Registering attributes subscription for session [{}]", deviceId, sessionId); |
319 | attributeSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress())); | 368 | attributeSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress())); |
320 | - } else if (inMsg.getMsgType() == MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST) { | 369 | + } else if (inMsg.getMsgType() == SessionMsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST) { |
321 | logger.debug("[{}] Canceling attributes subscription for session [{}]", deviceId, sessionId); | 370 | logger.debug("[{}] Canceling attributes subscription for session [{}]", deviceId, sessionId); |
322 | attributeSubscriptions.remove(sessionId); | 371 | attributeSubscriptions.remove(sessionId); |
323 | - } else if (inMsg.getMsgType() == MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST) { | 372 | + } else if (inMsg.getMsgType() == SessionMsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST) { |
324 | logger.debug("[{}] Registering rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType); | 373 | logger.debug("[{}] Registering rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType); |
325 | rpcSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress())); | 374 | rpcSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress())); |
326 | sendPendingRequests(context, sessionId, sessionType, msg.getServerAddress()); | 375 | sendPendingRequests(context, sessionId, sessionType, msg.getServerAddress()); |
327 | - } else if (inMsg.getMsgType() == MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST) { | 376 | + } else if (inMsg.getMsgType() == SessionMsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST) { |
328 | logger.debug("[{}] Canceling rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType); | 377 | logger.debug("[{}] Canceling rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType); |
329 | rpcSubscriptions.remove(sessionId); | 378 | rpcSubscriptions.remove(sessionId); |
330 | } | 379 | } |
331 | } | 380 | } |
332 | 381 | ||
333 | - private void processSessionStateMsgs(ToDeviceActorMsg msg) { | 382 | + private void processSessionStateMsgs(DeviceToDeviceActorMsg msg) { |
334 | SessionId sessionId = msg.getSessionId(); | 383 | SessionId sessionId = msg.getSessionId(); |
335 | FromDeviceMsg inMsg = msg.getPayload(); | 384 | FromDeviceMsg inMsg = msg.getPayload(); |
336 | if (inMsg instanceof SessionOpenMsg) { | 385 | if (inMsg instanceof SessionOpenMsg) { |
@@ -364,7 +413,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -364,7 +413,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
364 | } | 413 | } |
365 | } | 414 | } |
366 | 415 | ||
367 | - public void processCredentialsUpdate() { | 416 | + void processCredentialsUpdate() { |
368 | sessions.forEach((k, v) -> { | 417 | sessions.forEach((k, v) -> { |
369 | sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(new SessionCloseNotification(), k), v.getServer()); | 418 | sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(new SessionCloseNotification(), k), v.getServer()); |
370 | }); | 419 | }); |
@@ -372,8 +421,12 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | @@ -372,8 +421,12 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso | ||
372 | rpcSubscriptions.clear(); | 421 | rpcSubscriptions.clear(); |
373 | } | 422 | } |
374 | 423 | ||
375 | - public void processNameOrTypeUpdate(DeviceNameOrTypeUpdateMsg msg) { | 424 | + void processNameOrTypeUpdate(DeviceNameOrTypeUpdateMsg msg) { |
376 | this.deviceName = msg.getDeviceName(); | 425 | this.deviceName = msg.getDeviceName(); |
377 | this.deviceType = msg.getDeviceType(); | 426 | this.deviceType = msg.getDeviceType(); |
427 | + this.defaultMetaData = new TbMsgMetaData(); | ||
428 | + this.defaultMetaData.putValue("deviceName", deviceName); | ||
429 | + this.defaultMetaData.putValue("deviceType", deviceType); | ||
378 | } | 430 | } |
431 | + | ||
379 | } | 432 | } |
application/src/main/java/org/thingsboard/server/actors/device/DeviceActorToRuleEngineMsg.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2018 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.actors.device; | ||
17 | + | ||
18 | +import akka.actor.ActorRef; | ||
19 | +import lombok.Data; | ||
20 | +import org.thingsboard.server.common.data.id.TenantId; | ||
21 | +import org.thingsboard.server.common.msg.MsgType; | ||
22 | +import org.thingsboard.server.common.msg.TbActorMsg; | ||
23 | +import org.thingsboard.server.common.msg.TbMsg; | ||
24 | + | ||
25 | +/** | ||
26 | + * Created by ashvayka on 15.03.18. | ||
27 | + */ | ||
28 | +@Data | ||
29 | +public final class DeviceActorToRuleEngineMsg implements TbActorMsg { | ||
30 | + | ||
31 | + private final ActorRef callbackRef; | ||
32 | + private final TbMsg tbMsg; | ||
33 | + | ||
34 | + @Override | ||
35 | + public MsgType getMsgType() { | ||
36 | + return MsgType.DEVICE_ACTOR_TO_RULE_ENGINE_MSG; | ||
37 | + } | ||
38 | +} |
application/src/main/java/org/thingsboard/server/actors/device/PendingSessionMsgData.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2018 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.actors.device; | ||
17 | + | ||
18 | +import lombok.Data; | ||
19 | +import org.thingsboard.server.common.data.id.SessionId; | ||
20 | +import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
22 | + | ||
23 | +import java.util.Optional; | ||
24 | + | ||
25 | +/** | ||
26 | + * Created by ashvayka on 17.04.18. | ||
27 | + */ | ||
28 | +@Data | ||
29 | +public final class PendingSessionMsgData { | ||
30 | + | ||
31 | + private final SessionId sessionId; | ||
32 | + private final Optional<ServerAddress> serverAddress; | ||
33 | + private final SessionMsgType sessionMsgType; | ||
34 | + private final int requestId; | ||
35 | + | ||
36 | +} |
application/src/main/java/org/thingsboard/server/actors/device/RuleEngineQueuePutAckMsg.java
0 → 100644
1 | +/** | ||
2 | + * Copyright © 2016-2018 The Thingsboard Authors | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.thingsboard.server.actors.device; | ||
17 | + | ||
18 | +import lombok.Data; | ||
19 | +import org.thingsboard.server.common.msg.MsgType; | ||
20 | +import org.thingsboard.server.common.msg.TbActorMsg; | ||
21 | + | ||
22 | +import java.util.UUID; | ||
23 | + | ||
24 | +/** | ||
25 | + * Created by ashvayka on 15.03.18. | ||
26 | + */ | ||
27 | +@Data | ||
28 | +public final class RuleEngineQueuePutAckMsg implements TbActorMsg { | ||
29 | + | ||
30 | + private final UUID id; | ||
31 | + | ||
32 | + @Override | ||
33 | + public MsgType getMsgType() { | ||
34 | + return MsgType.RULE_ENGINE_QUEUE_PUT_ACK_MSG; | ||
35 | + } | ||
36 | +} |
@@ -16,13 +16,13 @@ | @@ -16,13 +16,13 @@ | ||
16 | package org.thingsboard.server.actors.device; | 16 | package org.thingsboard.server.actors.device; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | 19 | +import org.thingsboard.server.service.rpc.ToDeviceRpcRequestMsg; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Andrew Shvayka | 22 | * @author Andrew Shvayka |
23 | */ | 23 | */ |
24 | @Data | 24 | @Data |
25 | public class ToDeviceRpcRequestMetadata { | 25 | public class ToDeviceRpcRequestMetadata { |
26 | - private final ToDeviceRpcRequestPluginMsg msg; | 26 | + private final ToDeviceRpcRequestMsg msg; |
27 | private final boolean sent; | 27 | private final boolean sent; |
28 | } | 28 | } |
@@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.TenantId; | @@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.TenantId; | ||
26 | import org.thingsboard.server.common.msg.TbActorMsg; | 26 | import org.thingsboard.server.common.msg.TbActorMsg; |
27 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 27 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
28 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | 28 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
29 | -import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; | 29 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; |
30 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; | 30 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; |
31 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | 31 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
32 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | 32 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
@@ -153,6 +153,7 @@ public class PluginActor extends ComponentActor<PluginId, PluginActorMessageProc | @@ -153,6 +153,7 @@ public class PluginActor extends ComponentActor<PluginId, PluginActorMessageProc | ||
153 | 153 | ||
154 | @Override | 154 | @Override |
155 | protected long getErrorPersistFrequency() { | 155 | protected long getErrorPersistFrequency() { |
156 | - return systemContext.getPluginErrorPersistFrequency(); | 156 | + return 0; |
157 | +// return systemContext.getPluginErrorPersistFrequency(); | ||
157 | } | 158 | } |
158 | } | 159 | } |
@@ -30,13 +30,14 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | @@ -30,13 +30,14 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | ||
30 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 30 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
31 | import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; | 31 | import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; |
32 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 32 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
33 | -import org.thingsboard.server.common.msg.session.MsgType; | 33 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
34 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
34 | import org.thingsboard.server.extensions.api.plugins.Plugin; | 35 | import org.thingsboard.server.extensions.api.plugins.Plugin; |
35 | import org.thingsboard.server.extensions.api.plugins.PluginInitializationException; | 36 | import org.thingsboard.server.extensions.api.plugins.PluginInitializationException; |
36 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | 37 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
37 | import org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg; | 38 | import org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg; |
38 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 39 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
39 | -import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; | 40 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; |
40 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | 41 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
41 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | 42 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
42 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | 43 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; |
@@ -108,7 +109,7 @@ public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> | @@ -108,7 +109,7 @@ public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> | ||
108 | } catch (Exception ex) { | 109 | } catch (Exception ex) { |
109 | logger.debug("[{}] Failed to process RuleToPlugin msg: [{}] [{}]", tenantId, msg.getMsg(), ex); | 110 | logger.debug("[{}] Failed to process RuleToPlugin msg: [{}] [{}]", tenantId, msg.getMsg(), ex); |
110 | RuleToPluginMsg ruleMsg = msg.getMsg(); | 111 | RuleToPluginMsg ruleMsg = msg.getMsg(); |
111 | - MsgType responceMsgType = MsgType.RULE_ENGINE_ERROR; | 112 | + SessionMsgType responceMsgType = SessionMsgType.RULE_ENGINE_ERROR; |
112 | Integer requestId = 0; | 113 | Integer requestId = 0; |
113 | if (ruleMsg.getPayload() instanceof FromDeviceRequestMsg) { | 114 | if (ruleMsg.getPayload() instanceof FromDeviceRequestMsg) { |
114 | requestId = ((FromDeviceRequestMsg) ruleMsg.getPayload()).getRequestId(); | 115 | requestId = ((FromDeviceRequestMsg) ruleMsg.getPayload()).getRequestId(); |
@@ -216,7 +217,7 @@ public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> | @@ -216,7 +217,7 @@ public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> | ||
216 | @Override | 217 | @Override |
217 | public void onStop(ActorContext context) { | 218 | public void onStop(ActorContext context) { |
218 | onStop(); | 219 | onStop(); |
219 | - scheduleMsgWithDelay(context, new PluginTerminationMsg(entityId), systemContext.getPluginActorTerminationDelay()); | 220 | +// scheduleMsgWithDelay(context, new PluginTerminationMsg(entityId), systemContext.getPluginActorTerminationDelay()); |
220 | } | 221 | } |
221 | 222 | ||
222 | private void onStop() { | 223 | private void onStop() { |
@@ -41,6 +41,7 @@ import org.thingsboard.server.common.data.rule.RuleChain; | @@ -41,6 +41,7 @@ import org.thingsboard.server.common.data.rule.RuleChain; | ||
41 | import org.thingsboard.server.common.data.rule.RuleMetaData; | 41 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
42 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 42 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
43 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 43 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
44 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
44 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | 45 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
45 | import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext; | 46 | import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext; |
46 | import org.thingsboard.server.extensions.api.plugins.PluginCallback; | 47 | import org.thingsboard.server.extensions.api.plugins.PluginCallback; |
@@ -19,10 +19,12 @@ import akka.actor.ActorRef; | @@ -19,10 +19,12 @@ import akka.actor.ActorRef; | ||
19 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
20 | import org.thingsboard.server.actors.ActorSystemContext; | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
21 | import org.thingsboard.server.common.data.id.DeviceId; | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | +import org.thingsboard.server.common.data.id.PluginId; | ||
22 | import org.thingsboard.server.common.data.id.TenantId; | 23 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
25 | +import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | ||
26 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
24 | import org.thingsboard.server.controller.plugin.PluginWebSocketMsgEndpoint; | 27 | import org.thingsboard.server.controller.plugin.PluginWebSocketMsgEndpoint; |
25 | -import org.thingsboard.server.common.data.id.PluginId; | ||
26 | import org.thingsboard.server.dao.asset.AssetService; | 28 | import org.thingsboard.server.dao.asset.AssetService; |
27 | import org.thingsboard.server.dao.attributes.AttributesService; | 29 | import org.thingsboard.server.dao.attributes.AttributesService; |
28 | import org.thingsboard.server.dao.audit.AuditLogService; | 30 | import org.thingsboard.server.dao.audit.AuditLogService; |
@@ -35,9 +37,6 @@ import org.thingsboard.server.dao.rule.RuleService; | @@ -35,9 +37,6 @@ import org.thingsboard.server.dao.rule.RuleService; | ||
35 | import org.thingsboard.server.dao.tenant.TenantService; | 37 | import org.thingsboard.server.dao.tenant.TenantService; |
36 | import org.thingsboard.server.dao.timeseries.TimeseriesService; | 38 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
37 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; | 39 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
38 | -import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; | ||
39 | -import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | ||
40 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | ||
41 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; | 40 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; |
42 | import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; | 41 | import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; |
43 | import scala.concurrent.duration.Duration; | 42 | import scala.concurrent.duration.Duration; |
@@ -106,8 +105,8 @@ public final class SharedPluginProcessingContext { | @@ -106,8 +105,8 @@ public final class SharedPluginProcessingContext { | ||
106 | 105 | ||
107 | public void sendRpcRequest(ToDeviceRpcRequest msg) { | 106 | public void sendRpcRequest(ToDeviceRpcRequest msg) { |
108 | log.trace("[{}] Forwarding msg {} to device actor!", pluginId, msg); | 107 | log.trace("[{}] Forwarding msg {} to device actor!", pluginId, msg); |
109 | - ToDeviceRpcRequestPluginMsg rpcMsg = new ToDeviceRpcRequestPluginMsg(pluginId, tenantId, msg); | ||
110 | - forward(msg.getDeviceId(), rpcMsg, rpcService::tell); | 108 | +// ToDeviceRpcRequestPluginMsg rpcMsg = new ToDeviceRpcRequestPluginMsg(pluginId, tenantId, msg); |
109 | +// forward(msg.getDeviceId(), rpcMsg, rpcService::tell); | ||
111 | } | 110 | } |
112 | 111 | ||
113 | private <T> void forward(DeviceId deviceId, T msg, BiConsumer<ServerAddress, T> rpcFunction) { | 112 | private <T> void forward(DeviceId deviceId, T msg, BiConsumer<ServerAddress, T> rpcFunction) { |
@@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | @@ -28,7 +28,7 @@ import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | ||
28 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 28 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
29 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | 29 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
30 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; | 30 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
31 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 31 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
32 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 32 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
33 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 33 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
34 | import org.thingsboard.server.extensions.api.plugins.msg.*; | 34 | import org.thingsboard.server.extensions.api.plugins.msg.*; |
@@ -86,7 +86,7 @@ public class BasicRpcSessionListener implements GrpcSessionListener { | @@ -86,7 +86,7 @@ public class BasicRpcSessionListener implements GrpcSessionListener { | ||
86 | @Override | 86 | @Override |
87 | public void onToDeviceActorRpcMsg(GrpcSession session, ClusterAPIProtos.ToDeviceActorRpcMessage msg) { | 87 | public void onToDeviceActorRpcMsg(GrpcSession session, ClusterAPIProtos.ToDeviceActorRpcMessage msg) { |
88 | log.trace("{} session [{}] received device actor msg {}", getType(session), session.getRemoteServer(), msg); | 88 | log.trace("{} session [{}] received device actor msg {}", getType(session), session.getRemoteServer(), msg); |
89 | - service.onMsg((ToDeviceActorMsg) deserialize(msg.getData().toByteArray())); | 89 | + service.onMsg((DeviceToDeviceActorMsg) deserialize(msg.getData().toByteArray())); |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
1 | /** | 1 | /** |
2 | * Copyright © 2016-2018 The Thingsboard Authors | 2 | * Copyright © 2016-2018 The Thingsboard Authors |
3 | - * | 3 | + * <p> |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at | 6 | * You may obtain a copy of the License at |
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | 7 | + * <p> |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * <p> | ||
10 | * Unless required by applicable law or agreed to in writing, software | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
@@ -18,6 +18,7 @@ package org.thingsboard.server.actors.ruleChain; | @@ -18,6 +18,7 @@ package org.thingsboard.server.actors.ruleChain; | ||
18 | import akka.actor.OneForOneStrategy; | 18 | import akka.actor.OneForOneStrategy; |
19 | import akka.actor.SupervisorStrategy; | 19 | import akka.actor.SupervisorStrategy; |
20 | import org.thingsboard.server.actors.ActorSystemContext; | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
21 | +import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | ||
21 | import org.thingsboard.server.actors.service.ComponentActor; | 22 | import org.thingsboard.server.actors.service.ComponentActor; |
22 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 23 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
23 | import org.thingsboard.server.common.data.id.RuleChainId; | 24 | import org.thingsboard.server.common.data.id.RuleChainId; |
@@ -44,6 +45,9 @@ public class RuleChainActor extends ComponentActor<RuleChainId, RuleChainActorMe | @@ -44,6 +45,9 @@ public class RuleChainActor extends ComponentActor<RuleChainId, RuleChainActorMe | ||
44 | case SERVICE_TO_RULE_ENGINE_MSG: | 45 | case SERVICE_TO_RULE_ENGINE_MSG: |
45 | processor.onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); | 46 | processor.onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); |
46 | break; | 47 | break; |
48 | + case DEVICE_ACTOR_TO_RULE_ENGINE_MSG: | ||
49 | + processor.onDeviceActorToRuleEngineMsg((DeviceActorToRuleEngineMsg) msg); | ||
50 | + break; | ||
47 | case RULE_TO_RULE_CHAIN_TELL_NEXT_MSG: | 51 | case RULE_TO_RULE_CHAIN_TELL_NEXT_MSG: |
48 | processor.onTellNext((RuleNodeToRuleChainTellNextMsg) msg); | 52 | processor.onTellNext((RuleNodeToRuleChainTellNextMsg) msg); |
49 | break; | 53 | break; |
1 | /** | 1 | /** |
2 | * Copyright © 2016-2018 The Thingsboard Authors | 2 | * Copyright © 2016-2018 The Thingsboard Authors |
3 | - * | 3 | + * <p> |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at | 6 | * You may obtain a copy of the License at |
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | 7 | + * <p> |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * <p> | ||
10 | * Unless required by applicable law or agreed to in writing, software | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
@@ -20,6 +20,8 @@ import akka.actor.ActorRef; | @@ -20,6 +20,8 @@ import akka.actor.ActorRef; | ||
20 | import akka.actor.Props; | 20 | import akka.actor.Props; |
21 | import akka.event.LoggingAdapter; | 21 | import akka.event.LoggingAdapter; |
22 | import org.thingsboard.server.actors.ActorSystemContext; | 22 | import org.thingsboard.server.actors.ActorSystemContext; |
23 | +import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | ||
24 | +import org.thingsboard.server.actors.device.RuleEngineQueuePutAckMsg; | ||
23 | import org.thingsboard.server.actors.service.DefaultActorService; | 25 | import org.thingsboard.server.actors.service.DefaultActorService; |
24 | import org.thingsboard.server.actors.shared.ComponentMsgProcessor; | 26 | import org.thingsboard.server.actors.shared.ComponentMsgProcessor; |
25 | import org.thingsboard.server.common.data.EntityType; | 27 | import org.thingsboard.server.common.data.EntityType; |
@@ -157,6 +159,14 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh | @@ -157,6 +159,14 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh | ||
157 | pushMsgToNode(firstNode, tbMsg); | 159 | pushMsgToNode(firstNode, tbMsg); |
158 | } | 160 | } |
159 | 161 | ||
162 | + public void onDeviceActorToRuleEngineMsg(DeviceActorToRuleEngineMsg envelope) { | ||
163 | + checkActive(); | ||
164 | + TbMsg tbMsg = envelope.getTbMsg(); | ||
165 | + //TODO: push to queue and act on ack in async way | ||
166 | + pushMsgToNode(firstNode, tbMsg); | ||
167 | + envelope.getCallbackRef().tell(new RuleEngineQueuePutAckMsg(tbMsg.getId()), self); | ||
168 | + } | ||
169 | + | ||
160 | void onTellNext(RuleNodeToRuleChainTellNextMsg envelope) { | 170 | void onTellNext(RuleNodeToRuleChainTellNextMsg envelope) { |
161 | checkActive(); | 171 | checkActive(); |
162 | RuleNodeId originator = envelope.getOriginator(); | 172 | RuleNodeId originator = envelope.getOriginator(); |
@@ -191,5 +201,4 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh | @@ -191,5 +201,4 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh | ||
191 | nodeCtx.getSelfActor().tell(new RuleChainToRuleNodeMsg(new DefaultTbContext(systemContext, nodeCtx), msg), self); | 201 | nodeCtx.getSelfActor().tell(new RuleChainToRuleNodeMsg(new DefaultTbContext(systemContext, nodeCtx), msg), self); |
192 | } | 202 | } |
193 | } | 203 | } |
194 | - | ||
195 | } | 204 | } |
@@ -31,31 +31,29 @@ import org.thingsboard.server.dao.rule.RuleChainService; | @@ -31,31 +31,29 @@ import org.thingsboard.server.dao.rule.RuleChainService; | ||
31 | public abstract class RuleChainManagerActor extends ContextAwareActor { | 31 | public abstract class RuleChainManagerActor extends ContextAwareActor { |
32 | 32 | ||
33 | protected final RuleChainManager ruleChainManager; | 33 | protected final RuleChainManager ruleChainManager; |
34 | - protected final PluginManager pluginManager; | ||
35 | protected final RuleChainService ruleChainService; | 34 | protected final RuleChainService ruleChainService; |
36 | 35 | ||
37 | public RuleChainManagerActor(ActorSystemContext systemContext, RuleChainManager ruleChainManager, PluginManager pluginManager) { | 36 | public RuleChainManagerActor(ActorSystemContext systemContext, RuleChainManager ruleChainManager, PluginManager pluginManager) { |
38 | super(systemContext); | 37 | super(systemContext); |
39 | this.ruleChainManager = ruleChainManager; | 38 | this.ruleChainManager = ruleChainManager; |
40 | - this.pluginManager = pluginManager; | ||
41 | this.ruleChainService = systemContext.getRuleChainService(); | 39 | this.ruleChainService = systemContext.getRuleChainService(); |
42 | } | 40 | } |
43 | 41 | ||
44 | protected void initRuleChains() { | 42 | protected void initRuleChains() { |
45 | - pluginManager.init(this.context()); | ||
46 | ruleChainManager.init(this.context()); | 43 | ruleChainManager.init(this.context()); |
47 | } | 44 | } |
48 | 45 | ||
49 | protected ActorRef getEntityActorRef(EntityId entityId) { | 46 | protected ActorRef getEntityActorRef(EntityId entityId) { |
50 | ActorRef target = null; | 47 | ActorRef target = null; |
51 | switch (entityId.getEntityType()) { | 48 | switch (entityId.getEntityType()) { |
52 | - case PLUGIN: | ||
53 | - target = pluginManager.getOrCreateActor(this.context(), (PluginId) entityId); | ||
54 | - break; | ||
55 | case RULE_CHAIN: | 49 | case RULE_CHAIN: |
56 | target = ruleChainManager.getOrCreateActor(this.context(), (RuleChainId) entityId); | 50 | target = ruleChainManager.getOrCreateActor(this.context(), (RuleChainId) entityId); |
57 | break; | 51 | break; |
58 | } | 52 | } |
59 | return target; | 53 | return target; |
60 | } | 54 | } |
55 | + | ||
56 | + protected void broadcast(Object msg) { | ||
57 | + ruleChainManager.broadcast(msg); | ||
58 | + } | ||
61 | } | 59 | } |
@@ -39,7 +39,7 @@ import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | @@ -39,7 +39,7 @@ import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | ||
39 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; | 39 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
40 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | 40 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
41 | import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; | 41 | import org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg; |
42 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 42 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
43 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | 43 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
44 | import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; | 44 | import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; |
45 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 45 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
@@ -156,7 +156,7 @@ public class DefaultActorService implements ActorService { | @@ -156,7 +156,7 @@ public class DefaultActorService implements ActorService { | ||
156 | } | 156 | } |
157 | 157 | ||
158 | @Override | 158 | @Override |
159 | - public void onMsg(ToDeviceActorMsg msg) { | 159 | + public void onMsg(DeviceToDeviceActorMsg msg) { |
160 | log.trace("Processing device rpc msg: {}", msg); | 160 | log.trace("Processing device rpc msg: {}", msg); |
161 | appActor.tell(msg, ActorRef.noSender()); | 161 | appActor.tell(msg, ActorRef.noSender()); |
162 | } | 162 | } |
@@ -22,12 +22,11 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | @@ -22,12 +22,11 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | ||
22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
23 | import org.thingsboard.server.common.msg.core.*; | 23 | import org.thingsboard.server.common.msg.core.*; |
24 | import org.thingsboard.server.common.msg.core.SessionCloseMsg; | 24 | import org.thingsboard.server.common.msg.core.SessionCloseMsg; |
25 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 25 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
26 | import org.thingsboard.server.common.msg.session.*; | 26 | import org.thingsboard.server.common.msg.session.*; |
27 | 27 | ||
28 | import akka.actor.ActorContext; | 28 | import akka.actor.ActorContext; |
29 | import akka.event.LoggingAdapter; | 29 | import akka.event.LoggingAdapter; |
30 | -import org.thingsboard.server.common.msg.session.ctrl.*; | ||
31 | import org.thingsboard.server.common.msg.session.ex.SessionException; | 30 | import org.thingsboard.server.common.msg.session.ex.SessionException; |
32 | 31 | ||
33 | import java.util.HashMap; | 32 | import java.util.HashMap; |
@@ -37,7 +36,7 @@ import java.util.Optional; | @@ -37,7 +36,7 @@ import java.util.Optional; | ||
37 | class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { | 36 | class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
38 | 37 | ||
39 | private boolean firstMsg = true; | 38 | private boolean firstMsg = true; |
40 | - private Map<Integer, ToDeviceActorMsg> pendingMap = new HashMap<>(); | 39 | + private Map<Integer, DeviceToDeviceActorMsg> pendingMap = new HashMap<>(); |
41 | private Optional<ServerAddress> currentTargetServer; | 40 | private Optional<ServerAddress> currentTargetServer; |
42 | private boolean subscribedToAttributeUpdates; | 41 | private boolean subscribedToAttributeUpdates; |
43 | private boolean subscribedToRpcCommands; | 42 | private boolean subscribedToRpcCommands; |
@@ -53,7 +52,7 @@ class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { | @@ -53,7 +52,7 @@ class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { | ||
53 | toDeviceMsg(new SessionOpenMsg()).ifPresent(m -> forwardToAppActor(ctx, m)); | 52 | toDeviceMsg(new SessionOpenMsg()).ifPresent(m -> forwardToAppActor(ctx, m)); |
54 | firstMsg = false; | 53 | firstMsg = false; |
55 | } | 54 | } |
56 | - ToDeviceActorMsg pendingMsg = toDeviceMsg(msg); | 55 | + DeviceToDeviceActorMsg pendingMsg = toDeviceMsg(msg); |
57 | FromDeviceMsg fromDeviceMsg = pendingMsg.getPayload(); | 56 | FromDeviceMsg fromDeviceMsg = pendingMsg.getPayload(); |
58 | switch (fromDeviceMsg.getMsgType()) { | 57 | switch (fromDeviceMsg.getMsgType()) { |
59 | case POST_TELEMETRY_REQUEST: | 58 | case POST_TELEMETRY_REQUEST: |
@@ -86,8 +85,8 @@ class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { | @@ -86,8 +85,8 @@ class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { | ||
86 | @Override | 85 | @Override |
87 | public void processToDeviceMsg(ActorContext context, ToDeviceMsg msg) { | 86 | public void processToDeviceMsg(ActorContext context, ToDeviceMsg msg) { |
88 | try { | 87 | try { |
89 | - if (msg.getMsgType() != MsgType.SESSION_CLOSE) { | ||
90 | - switch (msg.getMsgType()) { | 88 | + if (msg.getSessionMsgType() != SessionMsgType.SESSION_CLOSE) { |
89 | + switch (msg.getSessionMsgType()) { | ||
91 | case STATUS_CODE_RESPONSE: | 90 | case STATUS_CODE_RESPONSE: |
92 | case GET_ATTRIBUTES_RESPONSE: | 91 | case GET_ATTRIBUTES_RESPONSE: |
93 | ResponseMsg responseMsg = (ResponseMsg) msg; | 92 | ResponseMsg responseMsg = (ResponseMsg) msg; |
@@ -22,8 +22,8 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -22,8 +22,8 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
22 | import org.thingsboard.server.common.data.id.SessionId; | 22 | import org.thingsboard.server.common.data.id.SessionId; |
23 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 23 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
25 | -import org.thingsboard.server.common.msg.device.BasicToDeviceActorMsg; | ||
26 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 25 | +import org.thingsboard.server.common.msg.device.BasicDeviceToDeviceActorMsg; |
26 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | ||
27 | import org.thingsboard.server.common.msg.session.*; | 27 | import org.thingsboard.server.common.msg.session.*; |
28 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; | 28 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
29 | 29 | ||
@@ -37,7 +37,7 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | @@ -37,7 +37,7 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | ||
37 | 37 | ||
38 | protected final SessionId sessionId; | 38 | protected final SessionId sessionId; |
39 | protected SessionContext sessionCtx; | 39 | protected SessionContext sessionCtx; |
40 | - protected ToDeviceActorMsg toDeviceActorMsgPrototype; | 40 | + protected DeviceToDeviceActorMsg deviceToDeviceActorMsgPrototype; |
41 | 41 | ||
42 | protected AbstractSessionActorMsgProcessor(ActorSystemContext ctx, LoggingAdapter logger, SessionId sessionId) { | 42 | protected AbstractSessionActorMsgProcessor(ActorSystemContext ctx, LoggingAdapter logger, SessionId sessionId) { |
43 | super(ctx, logger); | 43 | super(ctx, logger); |
@@ -64,29 +64,29 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | @@ -64,29 +64,29 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | ||
64 | 64 | ||
65 | protected void updateSessionCtx(ToDeviceActorSessionMsg msg, SessionType type) { | 65 | protected void updateSessionCtx(ToDeviceActorSessionMsg msg, SessionType type) { |
66 | sessionCtx = msg.getSessionMsg().getSessionContext(); | 66 | sessionCtx = msg.getSessionMsg().getSessionContext(); |
67 | - toDeviceActorMsgPrototype = new BasicToDeviceActorMsg(msg, type); | 67 | + deviceToDeviceActorMsgPrototype = new BasicDeviceToDeviceActorMsg(msg, type); |
68 | } | 68 | } |
69 | 69 | ||
70 | - protected ToDeviceActorMsg toDeviceMsg(ToDeviceActorSessionMsg msg) { | 70 | + protected DeviceToDeviceActorMsg toDeviceMsg(ToDeviceActorSessionMsg msg) { |
71 | AdaptorToSessionActorMsg adaptorMsg = msg.getSessionMsg(); | 71 | AdaptorToSessionActorMsg adaptorMsg = msg.getSessionMsg(); |
72 | - return new BasicToDeviceActorMsg(toDeviceActorMsgPrototype, adaptorMsg.getMsg()); | 72 | + return new BasicDeviceToDeviceActorMsg(deviceToDeviceActorMsgPrototype, adaptorMsg.getMsg()); |
73 | } | 73 | } |
74 | 74 | ||
75 | - protected Optional<ToDeviceActorMsg> toDeviceMsg(FromDeviceMsg msg) { | ||
76 | - if (toDeviceActorMsgPrototype != null) { | ||
77 | - return Optional.of(new BasicToDeviceActorMsg(toDeviceActorMsgPrototype, msg)); | 75 | + protected Optional<DeviceToDeviceActorMsg> toDeviceMsg(FromDeviceMsg msg) { |
76 | + if (deviceToDeviceActorMsgPrototype != null) { | ||
77 | + return Optional.of(new BasicDeviceToDeviceActorMsg(deviceToDeviceActorMsgPrototype, msg)); | ||
78 | } else { | 78 | } else { |
79 | return Optional.empty(); | 79 | return Optional.empty(); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
83 | - protected Optional<ServerAddress> forwardToAppActor(ActorContext ctx, ToDeviceActorMsg toForward) { | 83 | + protected Optional<ServerAddress> forwardToAppActor(ActorContext ctx, DeviceToDeviceActorMsg toForward) { |
84 | Optional<ServerAddress> address = systemContext.getRoutingService().resolveById(toForward.getDeviceId()); | 84 | Optional<ServerAddress> address = systemContext.getRoutingService().resolveById(toForward.getDeviceId()); |
85 | forwardToAppActor(ctx, toForward, address); | 85 | forwardToAppActor(ctx, toForward, address); |
86 | return address; | 86 | return address; |
87 | } | 87 | } |
88 | 88 | ||
89 | - protected Optional<ServerAddress> forwardToAppActorIfAdressChanged(ActorContext ctx, ToDeviceActorMsg toForward, Optional<ServerAddress> oldAddress) { | 89 | + protected Optional<ServerAddress> forwardToAppActorIfAdressChanged(ActorContext ctx, DeviceToDeviceActorMsg toForward, Optional<ServerAddress> oldAddress) { |
90 | Optional<ServerAddress> newAddress = systemContext.getRoutingService().resolveById(toForward.getDeviceId()); | 90 | Optional<ServerAddress> newAddress = systemContext.getRoutingService().resolveById(toForward.getDeviceId()); |
91 | if (!newAddress.equals(oldAddress)) { | 91 | if (!newAddress.equals(oldAddress)) { |
92 | if (newAddress.isPresent()) { | 92 | if (newAddress.isPresent()) { |
@@ -99,7 +99,7 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | @@ -99,7 +99,7 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | ||
99 | return newAddress; | 99 | return newAddress; |
100 | } | 100 | } |
101 | 101 | ||
102 | - protected void forwardToAppActor(ActorContext ctx, ToDeviceActorMsg toForward, Optional<ServerAddress> address) { | 102 | + protected void forwardToAppActor(ActorContext ctx, DeviceToDeviceActorMsg toForward, Optional<ServerAddress> address) { |
103 | if (address.isPresent()) { | 103 | if (address.isPresent()) { |
104 | systemContext.getRpcService().tell(address.get(), | 104 | systemContext.getRpcService().tell(address.get(), |
105 | toForward.toOtherAddress(systemContext.getRoutingService().getCurrentServer())); | 105 | toForward.toOtherAddress(systemContext.getRoutingService().getCurrentServer())); |
@@ -114,6 +114,6 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | @@ -114,6 +114,6 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP | ||
114 | } | 114 | } |
115 | 115 | ||
116 | public DeviceId getDeviceId() { | 116 | public DeviceId getDeviceId() { |
117 | - return toDeviceActorMsgPrototype.getDeviceId(); | 117 | + return deviceToDeviceActorMsgPrototype.getDeviceId(); |
118 | } | 118 | } |
119 | } | 119 | } |
@@ -20,7 +20,7 @@ import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | @@ -20,7 +20,7 @@ import org.thingsboard.server.actors.shared.SessionTimeoutMsg; | ||
20 | import org.thingsboard.server.common.data.id.SessionId; | 20 | import org.thingsboard.server.common.data.id.SessionId; |
21 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; | 21 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
23 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 23 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
24 | import org.thingsboard.server.common.msg.session.*; | 24 | import org.thingsboard.server.common.msg.session.*; |
25 | import org.thingsboard.server.common.msg.session.ToDeviceActorSessionMsg; | 25 | import org.thingsboard.server.common.msg.session.ToDeviceActorSessionMsg; |
26 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; | 26 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
@@ -32,7 +32,7 @@ import akka.event.LoggingAdapter; | @@ -32,7 +32,7 @@ import akka.event.LoggingAdapter; | ||
32 | import java.util.Optional; | 32 | import java.util.Optional; |
33 | 33 | ||
34 | class SyncMsgProcessor extends AbstractSessionActorMsgProcessor { | 34 | class SyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
35 | - private ToDeviceActorMsg pendingMsg; | 35 | + private DeviceToDeviceActorMsg pendingMsg; |
36 | private Optional<ServerAddress> currentTargetServer; | 36 | private Optional<ServerAddress> currentTargetServer; |
37 | private boolean pendingResponse; | 37 | private boolean pendingResponse; |
38 | 38 |
@@ -17,10 +17,9 @@ package org.thingsboard.server.actors.tenant; | @@ -17,10 +17,9 @@ package org.thingsboard.server.actors.tenant; | ||
17 | 17 | ||
18 | import akka.actor.ActorRef; | 18 | import akka.actor.ActorRef; |
19 | import akka.actor.Props; | 19 | import akka.actor.Props; |
20 | -import akka.event.Logging; | ||
21 | -import akka.event.LoggingAdapter; | ||
22 | import org.thingsboard.server.actors.ActorSystemContext; | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
23 | import org.thingsboard.server.actors.device.DeviceActor; | 21 | import org.thingsboard.server.actors.device.DeviceActor; |
22 | +import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | ||
24 | import org.thingsboard.server.actors.plugin.PluginTerminationMsg; | 23 | import org.thingsboard.server.actors.plugin.PluginTerminationMsg; |
25 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; | 24 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; |
26 | import org.thingsboard.server.actors.service.ContextBasedCreator; | 25 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
@@ -30,7 +29,8 @@ import org.thingsboard.server.actors.shared.rulechain.TenantRuleChainManager; | @@ -30,7 +29,8 @@ import org.thingsboard.server.actors.shared.rulechain.TenantRuleChainManager; | ||
30 | import org.thingsboard.server.common.data.id.DeviceId; | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
31 | import org.thingsboard.server.common.data.id.TenantId; | 30 | import org.thingsboard.server.common.data.id.TenantId; |
32 | import org.thingsboard.server.common.msg.TbActorMsg; | 31 | import org.thingsboard.server.common.msg.TbActorMsg; |
33 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 32 | +import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
33 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; | ||
34 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; | 34 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
35 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; | 35 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
36 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 36 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
@@ -64,63 +64,47 @@ public class TenantActor extends RuleChainManagerActor { | @@ -64,63 +64,47 @@ public class TenantActor extends RuleChainManagerActor { | ||
64 | @Override | 64 | @Override |
65 | protected boolean process(TbActorMsg msg) { | 65 | protected boolean process(TbActorMsg msg) { |
66 | switch (msg.getMsgType()) { | 66 | switch (msg.getMsgType()) { |
67 | + case CLUSTER_EVENT_MSG: | ||
68 | + broadcast(msg); | ||
69 | + break; | ||
67 | case COMPONENT_LIFE_CYCLE_MSG: | 70 | case COMPONENT_LIFE_CYCLE_MSG: |
68 | onComponentLifecycleMsg((ComponentLifecycleMsg) msg); | 71 | onComponentLifecycleMsg((ComponentLifecycleMsg) msg); |
69 | break; | 72 | break; |
70 | case SERVICE_TO_RULE_ENGINE_MSG: | 73 | case SERVICE_TO_RULE_ENGINE_MSG: |
71 | onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); | 74 | onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); |
72 | break; | 75 | break; |
76 | + case DEVICE_ACTOR_TO_RULE_ENGINE_MSG: | ||
77 | + onDeviceActorToRuleEngineMsg((DeviceActorToRuleEngineMsg) msg); | ||
78 | + break; | ||
79 | + case DEVICE_SESSION_TO_DEVICE_ACTOR_MSG: | ||
80 | + case DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
81 | + case DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
82 | + case DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG: | ||
83 | + case DEVICE_RPC_REQUEST_TO_DEVICE_ACTOR_MSG: | ||
84 | + onToDeviceActorMsg((DeviceToDeviceActorMsg) msg); | ||
85 | + break; | ||
73 | default: | 86 | default: |
74 | return false; | 87 | return false; |
75 | } | 88 | } |
76 | return true; | 89 | return true; |
77 | } | 90 | } |
78 | 91 | ||
79 | - private void onServiceToRuleEngineMsg(ServiceToRuleEngineMsg msg) { | ||
80 | - ruleChainManager.getRootChainActor().tell(msg, self()); | ||
81 | - } | ||
82 | - | ||
83 | - | ||
84 | -// @Override | ||
85 | -// public void onReceive(Object msg) throws Exception { | ||
86 | -// logger.debug("[{}] Received message: {}", tenantId, msg); | ||
87 | -// if (msg instanceof ToDeviceActorMsg) { | ||
88 | -// onToDeviceActorMsg((ToDeviceActorMsg) msg); | ||
89 | -// } else if (msg instanceof ToPluginActorMsg) { | ||
90 | -// onToPluginMsg((ToPluginActorMsg) msg); | ||
91 | -// } else if (msg instanceof ToDeviceActorNotificationMsg) { | ||
92 | -// onToDeviceActorMsg((ToDeviceActorNotificationMsg) msg); | ||
93 | -// } else if (msg instanceof ClusterEventMsg) { | ||
94 | -// broadcast(msg); | ||
95 | -// } else if (msg instanceof ComponentLifecycleMsg) { | ||
96 | -// onComponentLifecycleMsg((ComponentLifecycleMsg) msg); | ||
97 | -// } else if (msg instanceof PluginTerminationMsg) { | ||
98 | -// onPluginTerminated((PluginTerminationMsg) msg); | ||
99 | -// } else { | ||
100 | -// logger.warning("[{}] Unknown message: {}!", tenantId, msg); | ||
101 | -// } | ||
102 | -// } | ||
103 | - | ||
104 | - private void broadcast(Object msg) { | ||
105 | - pluginManager.broadcast(msg); | 92 | + @Override |
93 | + protected void broadcast(Object msg) { | ||
94 | + super.broadcast(msg); | ||
106 | deviceActors.values().forEach(actorRef -> actorRef.tell(msg, ActorRef.noSender())); | 95 | deviceActors.values().forEach(actorRef -> actorRef.tell(msg, ActorRef.noSender())); |
107 | } | 96 | } |
108 | 97 | ||
109 | - private void onToDeviceActorMsg(ToDeviceActorMsg msg) { | ||
110 | - getOrCreateDeviceActor(msg.getDeviceId()).tell(msg, ActorRef.noSender()); | 98 | + private void onServiceToRuleEngineMsg(ServiceToRuleEngineMsg msg) { |
99 | + ruleChainManager.getRootChainActor().tell(msg, self()); | ||
111 | } | 100 | } |
112 | 101 | ||
113 | - private void onToDeviceActorMsg(ToDeviceActorNotificationMsg msg) { | ||
114 | - getOrCreateDeviceActor(msg.getDeviceId()).tell(msg, ActorRef.noSender()); | 102 | + private void onDeviceActorToRuleEngineMsg(DeviceActorToRuleEngineMsg msg) { |
103 | + ruleChainManager.getRootChainActor().tell(msg, self()); | ||
115 | } | 104 | } |
116 | 105 | ||
117 | - private void onToPluginMsg(ToPluginActorMsg msg) { | ||
118 | - if (msg.getPluginTenantId().equals(tenantId)) { | ||
119 | - ActorRef pluginActor = pluginManager.getOrCreateActor(this.context(), msg.getPluginId()); | ||
120 | - pluginActor.tell(msg, ActorRef.noSender()); | ||
121 | - } else { | ||
122 | - context().parent().tell(msg, ActorRef.noSender()); | ||
123 | - } | 106 | + private void onToDeviceActorMsg(DeviceAwareMsg msg) { |
107 | + getOrCreateDeviceActor(msg.getDeviceId()).tell(msg, ActorRef.noSender()); | ||
124 | } | 108 | } |
125 | 109 | ||
126 | private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) { | 110 | private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) { |
@@ -132,11 +116,6 @@ public class TenantActor extends RuleChainManagerActor { | @@ -132,11 +116,6 @@ public class TenantActor extends RuleChainManagerActor { | ||
132 | } | 116 | } |
133 | } | 117 | } |
134 | 118 | ||
135 | - private void onPluginTerminated(PluginTerminationMsg msg) { | ||
136 | - pluginManager.remove(msg.getId()); | ||
137 | - } | ||
138 | - | ||
139 | - | ||
140 | private ActorRef getOrCreateDeviceActor(DeviceId deviceId) { | 119 | private ActorRef getOrCreateDeviceActor(DeviceId deviceId) { |
141 | return deviceActors.computeIfAbsent(deviceId, k -> context().actorOf(Props.create(new DeviceActor.ActorCreator(systemContext, tenantId, deviceId)) | 120 | return deviceActors.computeIfAbsent(deviceId, k -> context().actorOf(Props.create(new DeviceActor.ActorCreator(systemContext, tenantId, deviceId)) |
142 | .withDispatcher(DefaultActorService.CORE_DISPATCHER_NAME), deviceId.toString())); | 121 | .withDispatcher(DefaultActorService.CORE_DISPATCHER_NAME), deviceId.toString())); |
@@ -131,8 +131,8 @@ public class ThingsboardInstallService { | @@ -131,8 +131,8 @@ public class ThingsboardInstallService { | ||
131 | systemDataLoaderService.createSysAdmin(); | 131 | systemDataLoaderService.createSysAdmin(); |
132 | systemDataLoaderService.createAdminSettings(); | 132 | systemDataLoaderService.createAdminSettings(); |
133 | systemDataLoaderService.loadSystemWidgets(); | 133 | systemDataLoaderService.loadSystemWidgets(); |
134 | - systemDataLoaderService.loadSystemPlugins(); | ||
135 | - systemDataLoaderService.loadSystemRules(); | 134 | +// systemDataLoaderService.loadSystemPlugins(); |
135 | +// systemDataLoaderService.loadSystemRules(); | ||
136 | 136 | ||
137 | if (loadDemo) { | 137 | if (loadDemo) { |
138 | log.info("Loading demo data..."); | 138 | log.info("Loading demo data..."); |
@@ -30,11 +30,10 @@ import org.thingsboard.server.common.data.id.EntityId; | @@ -30,11 +30,10 @@ import org.thingsboard.server.common.data.id.EntityId; | ||
30 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 30 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
31 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | 31 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
32 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; | 32 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
33 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 33 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
34 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 34 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
35 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | 35 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
36 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 36 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
37 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | ||
38 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; | 37 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; |
39 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | 38 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
40 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 39 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
@@ -119,7 +118,7 @@ public class ClusterGrpcService extends ClusterRpcServiceGrpc.ClusterRpcServiceI | @@ -119,7 +118,7 @@ public class ClusterGrpcService extends ClusterRpcServiceGrpc.ClusterRpcServiceI | ||
119 | } | 118 | } |
120 | 119 | ||
121 | @Override | 120 | @Override |
122 | - public void tell(ServerAddress serverAddress, ToDeviceActorMsg toForward) { | 121 | + public void tell(ServerAddress serverAddress, DeviceToDeviceActorMsg toForward) { |
123 | ClusterAPIProtos.ToRpcServerMessage msg = ClusterAPIProtos.ToRpcServerMessage.newBuilder() | 122 | ClusterAPIProtos.ToRpcServerMessage msg = ClusterAPIProtos.ToRpcServerMessage.newBuilder() |
124 | .setToDeviceActorRpcMsg(toProtoMsg(toForward)).build(); | 123 | .setToDeviceActorRpcMsg(toProtoMsg(toForward)).build(); |
125 | tell(serverAddress, msg); | 124 | tell(serverAddress, msg); |
@@ -185,7 +184,7 @@ public class ClusterGrpcService extends ClusterRpcServiceGrpc.ClusterRpcServiceI | @@ -185,7 +184,7 @@ public class ClusterGrpcService extends ClusterRpcServiceGrpc.ClusterRpcServiceI | ||
185 | } | 184 | } |
186 | } | 185 | } |
187 | 186 | ||
188 | - private static ClusterAPIProtos.ToDeviceActorRpcMessage toProtoMsg(ToDeviceActorMsg msg) { | 187 | + private static ClusterAPIProtos.ToDeviceActorRpcMessage toProtoMsg(DeviceToDeviceActorMsg msg) { |
189 | return ClusterAPIProtos.ToDeviceActorRpcMessage.newBuilder().setData( | 188 | return ClusterAPIProtos.ToDeviceActorRpcMessage.newBuilder().setData( |
190 | ByteString.copyFrom(SerializationUtils.serialize(msg)) | 189 | ByteString.copyFrom(SerializationUtils.serialize(msg)) |
191 | ).build(); | 190 | ).build(); |
@@ -19,10 +19,8 @@ import io.grpc.stub.StreamObserver; | @@ -19,10 +19,8 @@ import io.grpc.stub.StreamObserver; | ||
19 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 19 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
20 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | 20 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
21 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; | 21 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
22 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | ||
23 | -import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 22 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
24 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 23 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
25 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | ||
26 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; | 24 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; |
27 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | 25 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
28 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | 26 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
@@ -37,7 +35,7 @@ public interface ClusterRpcService { | @@ -37,7 +35,7 @@ public interface ClusterRpcService { | ||
37 | 35 | ||
38 | void init(RpcMsgListener listener); | 36 | void init(RpcMsgListener listener); |
39 | 37 | ||
40 | - void tell(ServerAddress serverAddress, ToDeviceActorMsg toForward); | 38 | + void tell(ServerAddress serverAddress, DeviceToDeviceActorMsg toForward); |
41 | 39 | ||
42 | void tell(ServerAddress serverAddress, ToDeviceSessionActorMsg toForward); | 40 | void tell(ServerAddress serverAddress, ToDeviceSessionActorMsg toForward); |
43 | 41 |
@@ -20,18 +20,16 @@ import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; | @@ -20,18 +20,16 @@ import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; | ||
20 | import org.thingsboard.server.actors.rpc.RpcSessionTellMsg; | 20 | import org.thingsboard.server.actors.rpc.RpcSessionTellMsg; |
21 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; | 21 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
22 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; | 22 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
23 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 23 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
24 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 24 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
25 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginActorMsg; | 25 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginActorMsg; |
26 | -import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; | ||
27 | -import org.thingsboard.server.gen.cluster.ClusterAPIProtos; | ||
28 | 26 | ||
29 | /** | 27 | /** |
30 | * @author Andrew Shvayka | 28 | * @author Andrew Shvayka |
31 | */ | 29 | */ |
32 | public interface RpcMsgListener { | 30 | public interface RpcMsgListener { |
33 | 31 | ||
34 | - void onMsg(ToDeviceActorMsg msg); | 32 | + void onMsg(DeviceToDeviceActorMsg msg); |
35 | 33 | ||
36 | void onMsg(ToDeviceActorNotificationMsg msg); | 34 | void onMsg(ToDeviceActorNotificationMsg msg); |
37 | 35 |
application/src/main/java/org/thingsboard/server/service/install/DefaultSystemDataLoaderService.java
@@ -181,7 +181,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { | @@ -181,7 +181,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { | ||
181 | 181 | ||
182 | @Override | 182 | @Override |
183 | public void loadSystemPlugins() throws Exception { | 183 | public void loadSystemPlugins() throws Exception { |
184 | - loadPlugins(Paths.get(dataDir, JSON_DIR, SYSTEM_DIR, PLUGINS_DIR), null); | 184 | +// loadPlugins(Paths.get(dataDir, JSON_DIR, SYSTEM_DIR, PLUGINS_DIR), null); |
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||
@@ -227,7 +227,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { | @@ -227,7 +227,7 @@ public class DefaultSystemDataLoaderService implements SystemDataLoaderService { | ||
227 | createDevice(demoTenant.getId(), null, DEFAULT_DEVICE_TYPE, "Raspberry Pi Demo Device", "RASPBERRY_PI_DEMO_TOKEN", "Demo device that is used in " + | 227 | createDevice(demoTenant.getId(), null, DEFAULT_DEVICE_TYPE, "Raspberry Pi Demo Device", "RASPBERRY_PI_DEMO_TOKEN", "Demo device that is used in " + |
228 | "Raspberry Pi GPIO control sample application"); | 228 | "Raspberry Pi GPIO control sample application"); |
229 | 229 | ||
230 | - loadPlugins(Paths.get(dataDir, JSON_DIR, DEMO_DIR, PLUGINS_DIR), demoTenant.getId()); | 230 | +// loadPlugins(Paths.get(dataDir, JSON_DIR, DEMO_DIR, PLUGINS_DIR), demoTenant.getId()); |
231 | // loadRules(Paths.get(dataDir, JSON_DIR, DEMO_DIR, RULES_DIR), demoTenant.getId()); | 231 | // loadRules(Paths.get(dataDir, JSON_DIR, DEMO_DIR, RULES_DIR), demoTenant.getId()); |
232 | loadDashboards(Paths.get(dataDir, JSON_DIR, DEMO_DIR, DASHBOARDS_DIR), demoTenant.getId(), null); | 232 | loadDashboards(Paths.get(dataDir, JSON_DIR, DEMO_DIR, DASHBOARDS_DIR), demoTenant.getId(), null); |
233 | } | 233 | } |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.rpc; | 16 | package org.thingsboard.server.service.rpc; |
17 | 17 | ||
18 | +import akka.actor.ActorRef; | ||
18 | import com.fasterxml.jackson.databind.ObjectMapper; | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
19 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 21 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -105,7 +106,19 @@ public class DefaultDeviceRpcService implements DeviceRpcService { | @@ -105,7 +106,19 @@ public class DefaultDeviceRpcService implements DeviceRpcService { | ||
105 | } | 106 | } |
106 | 107 | ||
107 | @Override | 108 | @Override |
109 | + public void process(ToDeviceRpcRequest request, ServerAddress originator) { | ||
110 | +// if (pluginServerAddress.isPresent()) { | ||
111 | +// systemContext.getRpcService().tell(pluginServerAddress.get(), responsePluginMsg); | ||
112 | +// logger.debug("[{}] Rpc command response sent to remote plugin actor [{}]!", deviceId, requestMd.getMsg().getMsg().getId()); | ||
113 | +// } else { | ||
114 | +// context.parent().tell(responsePluginMsg, ActorRef.noSender()); | ||
115 | +// logger.debug("[{}] Rpc command response sent to local plugin actor [{}]!", deviceId, requestMd.getMsg().getMsg().getId()); | ||
116 | +// } | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
108 | public void process(FromDeviceRpcResponse response) { | 120 | public void process(FromDeviceRpcResponse response) { |
121 | + //TODO: send to another server if needed. | ||
109 | UUID requestId = response.getId(); | 122 | UUID requestId = response.getId(); |
110 | LocalRequestMetaData md = localRpcRequests.remove(requestId); | 123 | LocalRequestMetaData md = localRpcRequests.remove(requestId); |
111 | if (md != null) { | 124 | if (md != null) { |
@@ -17,6 +17,7 @@ package org.thingsboard.server.service.rpc; | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.rpc; | ||
17 | 17 | ||
18 | import org.thingsboard.server.common.data.id.EntityId; | 18 | import org.thingsboard.server.common.data.id.EntityId; |
19 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | 19 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
20 | +import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
20 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 21 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | 22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
22 | import org.thingsboard.server.extensions.api.plugins.msg.RpcError; | 23 | import org.thingsboard.server.extensions.api.plugins.msg.RpcError; |
@@ -31,6 +32,8 @@ public interface DeviceRpcService { | @@ -31,6 +32,8 @@ public interface DeviceRpcService { | ||
31 | 32 | ||
32 | void process(ToDeviceRpcRequest request, LocalRequestMetaData metaData); | 33 | void process(ToDeviceRpcRequest request, LocalRequestMetaData metaData); |
33 | 34 | ||
35 | + void process(ToDeviceRpcRequest request, ServerAddress originator); | ||
36 | + | ||
34 | void process(FromDeviceRpcResponse response); | 37 | void process(FromDeviceRpcResponse response); |
35 | 38 | ||
36 | void logRpcCall(SecurityUser user, EntityId entityId, ToDeviceRpcRequestBody body, boolean oneWay, Optional<RpcError> rpcError, Throwable e); | 39 | void logRpcCall(SecurityUser user, EntityId entityId, ToDeviceRpcRequestBody body, boolean oneWay, Optional<RpcError> rpcError, Throwable e); |
@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; | @@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; | ||
20 | import lombok.ToString; | 20 | import lombok.ToString; |
21 | import org.thingsboard.server.common.data.id.DeviceId; | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | +import org.thingsboard.server.common.msg.MsgType; | ||
23 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
24 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 25 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
25 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | 26 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
@@ -54,4 +55,9 @@ public class ToDeviceRpcRequestMsg implements ToDeviceActorNotificationMsg { | @@ -54,4 +55,9 @@ public class ToDeviceRpcRequestMsg implements ToDeviceActorNotificationMsg { | ||
54 | public TenantId getTenantId() { | 55 | public TenantId getTenantId() { |
55 | return msg.getTenantId(); | 56 | return msg.getTenantId(); |
56 | } | 57 | } |
58 | + | ||
59 | + @Override | ||
60 | + public MsgType getMsgType() { | ||
61 | + return MsgType.DEVICE_RPC_REQUEST_TO_DEVICE_ACTOR_MSG; | ||
62 | + } | ||
57 | } | 63 | } |
@@ -207,18 +207,7 @@ actors: | @@ -207,18 +207,7 @@ actors: | ||
207 | sync: | 207 | sync: |
208 | # Default timeout for processing request using synchronous session (HTTP, CoAP) in milliseconds | 208 | # Default timeout for processing request using synchronous session (HTTP, CoAP) in milliseconds |
209 | timeout: "${ACTORS_SESSION_SYNC_TIMEOUT:10000}" | 209 | timeout: "${ACTORS_SESSION_SYNC_TIMEOUT:10000}" |
210 | - plugin: | ||
211 | - # Default timeout for termination of the plugin actor after it is stopped | ||
212 | - termination.delay: "${ACTORS_PLUGIN_TERMINATION_DELAY:60000}" | ||
213 | - # Default timeout for processing of particular message by particular plugin | ||
214 | - processing.timeout: "${ACTORS_PLUGIN_TIMEOUT:60000}" | ||
215 | - # Errors for particular actor are persisted once per specified amount of milliseconds | ||
216 | - error_persist_frequency: "${ACTORS_PLUGIN_ERROR_FREQUENCY:3000}" | ||
217 | rule: | 210 | rule: |
218 | - # Default timeout for termination of the rule actor after it is stopped | ||
219 | - termination.delay: "${ACTORS_RULE_TERMINATION_DELAY:30000}" | ||
220 | - # Errors for particular actor are persisted once per specified amount of milliseconds | ||
221 | - error_persist_frequency: "${ACTORS_RULE_ERROR_FREQUENCY:3000}" | ||
222 | # Specify thread pool size for database request callbacks executor service | 211 | # Specify thread pool size for database request callbacks executor service |
223 | db_callback_thread_pool_size: "${ACTORS_RULE_DB_CALLBACK_THREAD_POOL_SIZE:1}" | 212 | db_callback_thread_pool_size: "${ACTORS_RULE_DB_CALLBACK_THREAD_POOL_SIZE:1}" |
224 | # Specify thread pool size for javascript executor service | 213 | # Specify thread pool size for javascript executor service |
@@ -235,6 +224,11 @@ actors: | @@ -235,6 +224,11 @@ actors: | ||
235 | # Enable/disable actor statistics | 224 | # Enable/disable actor statistics |
236 | enabled: "${ACTORS_STATISTICS_ENABLED:true}" | 225 | enabled: "${ACTORS_STATISTICS_ENABLED:true}" |
237 | persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:3600000}" | 226 | persist_frequency: "${ACTORS_STATISTICS_PERSIST_FREQUENCY:3600000}" |
227 | + queue: | ||
228 | + # Enable/disable persistence of un-processed messages to the queue | ||
229 | + enabled: "${ACTORS_QUEUE_ENABLED:true}" | ||
230 | + # Maximum allowed timeout for persistence into the queue | ||
231 | + timeout: "${ACTORS_QUEUE_PERSISTENCE_TIMEOUT:30000}" | ||
238 | 232 | ||
239 | cache: | 233 | cache: |
240 | # caffeine or redis | 234 | # caffeine or redis |
@@ -18,27 +18,30 @@ package org.thingsboard.server.common.msg; | @@ -18,27 +18,30 @@ package org.thingsboard.server.common.msg; | ||
18 | /** | 18 | /** |
19 | * Created by ashvayka on 15.03.18. | 19 | * Created by ashvayka on 15.03.18. |
20 | */ | 20 | */ |
21 | +//TODO: add all "See" references | ||
21 | public enum MsgType { | 22 | public enum MsgType { |
22 | 23 | ||
23 | /** | 24 | /** |
25 | + * ADDED/UPDATED/DELETED events for server nodes. | ||
26 | + * | ||
27 | + * See {@link org.thingsboard.server.common.msg.cluster.ClusterEventMsg} | ||
28 | + */ | ||
29 | + CLUSTER_EVENT_MSG, | ||
30 | + | ||
31 | + /** | ||
24 | * ADDED/UPDATED/DELETED events for main entities. | 32 | * ADDED/UPDATED/DELETED events for main entities. |
25 | * | 33 | * |
26 | - * @See {@link org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg} | 34 | + * See {@link org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg} |
27 | */ | 35 | */ |
28 | COMPONENT_LIFE_CYCLE_MSG, | 36 | COMPONENT_LIFE_CYCLE_MSG, |
29 | 37 | ||
30 | /** | 38 | /** |
31 | * Misc messages from the REST API/SERVICE layer to the new rule engine. | 39 | * Misc messages from the REST API/SERVICE layer to the new rule engine. |
32 | * | 40 | * |
33 | - * @See {@link org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg} | 41 | + * See {@link org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg} |
34 | */ | 42 | */ |
35 | SERVICE_TO_RULE_ENGINE_MSG, | 43 | SERVICE_TO_RULE_ENGINE_MSG, |
36 | 44 | ||
37 | - | ||
38 | - SESSION_TO_DEVICE_ACTOR_MSG, | ||
39 | - DEVICE_ACTOR_TO_SESSION_MSG, | ||
40 | - | ||
41 | - | ||
42 | /** | 45 | /** |
43 | * Message that is sent by RuleChainActor to RuleActor with command to process TbMsg. | 46 | * Message that is sent by RuleChainActor to RuleActor with command to process TbMsg. |
44 | */ | 47 | */ |
@@ -59,4 +62,31 @@ public enum MsgType { | @@ -59,4 +62,31 @@ public enum MsgType { | ||
59 | */ | 62 | */ |
60 | RULE_TO_SELF_MSG, | 63 | RULE_TO_SELF_MSG, |
61 | 64 | ||
65 | + /** | ||
66 | + * Message that is sent by Session Actor to Device Actor. Represents messages from the device itself. | ||
67 | + */ | ||
68 | + DEVICE_SESSION_TO_DEVICE_ACTOR_MSG, | ||
69 | + | ||
70 | + DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG, | ||
71 | + | ||
72 | + DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG, | ||
73 | + | ||
74 | + DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG, | ||
75 | + | ||
76 | + DEVICE_RPC_REQUEST_TO_DEVICE_ACTOR_MSG, | ||
77 | + | ||
78 | + DEVICE_ACTOR_RPC_TIMEOUT_MSG, | ||
79 | + | ||
80 | + DEVICE_ACTOR_QUEUE_TIMEOUT_MSG, | ||
81 | + | ||
82 | + /** | ||
83 | + * Message that is sent from the Device Actor to Rule Engine. Requires acknowledgement | ||
84 | + */ | ||
85 | + DEVICE_ACTOR_TO_RULE_ENGINE_MSG, | ||
86 | + | ||
87 | + /** | ||
88 | + * Message that is sent from Rule Engine to the Device Actor when message is successfully pushed to queue. | ||
89 | + */ | ||
90 | + RULE_ENGINE_QUEUE_PUT_ACK_MSG; | ||
91 | + | ||
62 | } | 92 | } |
@@ -31,10 +31,10 @@ import java.util.concurrent.ConcurrentHashMap; | @@ -31,10 +31,10 @@ import java.util.concurrent.ConcurrentHashMap; | ||
31 | @NoArgsConstructor | 31 | @NoArgsConstructor |
32 | public final class TbMsgMetaData implements Serializable { | 32 | public final class TbMsgMetaData implements Serializable { |
33 | 33 | ||
34 | - private Map<String, String> data = new ConcurrentHashMap<>(); | 34 | + private final Map<String, String> data = new ConcurrentHashMap<>(); |
35 | 35 | ||
36 | public TbMsgMetaData(Map<String, String> data) { | 36 | public TbMsgMetaData(Map<String, String> data) { |
37 | - this.data = data; | 37 | + this.data.putAll(data); |
38 | } | 38 | } |
39 | 39 | ||
40 | public String getValue(String key) { | 40 | public String getValue(String key) { |
@@ -16,14 +16,20 @@ | @@ -16,14 +16,20 @@ | ||
16 | package org.thingsboard.server.common.msg.cluster; | 16 | package org.thingsboard.server.common.msg.cluster; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | +import org.thingsboard.server.common.msg.MsgType; | ||
20 | +import org.thingsboard.server.common.msg.TbActorMsg; | ||
19 | 21 | ||
20 | /** | 22 | /** |
21 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
22 | */ | 24 | */ |
23 | @Data | 25 | @Data |
24 | -public final class ClusterEventMsg { | 26 | +public final class ClusterEventMsg implements TbActorMsg { |
25 | 27 | ||
26 | private final ServerAddress serverAddress; | 28 | private final ServerAddress serverAddress; |
27 | private final boolean added; | 29 | private final boolean added; |
28 | 30 | ||
31 | + @Override | ||
32 | + public MsgType getMsgType() { | ||
33 | + return MsgType.CLUSTER_EVENT_MSG; | ||
34 | + } | ||
29 | } | 35 | } |
@@ -16,14 +16,14 @@ | @@ -16,14 +16,14 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @author Andrew Shvayka | 22 | * @author Andrew Shvayka |
23 | */ | 23 | */ |
24 | public class AttributesSubscribeMsg implements FromDeviceMsg { | 24 | public class AttributesSubscribeMsg implements FromDeviceMsg { |
25 | @Override | 25 | @Override |
26 | - public MsgType getMsgType() { | ||
27 | - return MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST; | 26 | + public SessionMsgType getMsgType() { |
27 | + return SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST; | ||
28 | } | 28 | } |
29 | } | 29 | } |
@@ -16,14 +16,15 @@ | @@ -16,14 +16,15 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
23 | */ | 24 | */ |
24 | public class AttributesUnsubscribeMsg implements FromDeviceMsg { | 25 | public class AttributesUnsubscribeMsg implements FromDeviceMsg { |
25 | @Override | 26 | @Override |
26 | - public MsgType getMsgType() { | ||
27 | - return MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST; | 27 | + public SessionMsgType getMsgType() { |
28 | + return SessionMsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST; | ||
28 | } | 29 | } |
29 | } | 30 | } |
@@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | @@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | ||
17 | 17 | ||
18 | import lombok.ToString; | 18 | import lombok.ToString; |
19 | import org.thingsboard.server.common.msg.kv.AttributesKVMsg; | 19 | import org.thingsboard.server.common.msg.kv.AttributesKVMsg; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
22 | 23 | ||
23 | @ToString | 24 | @ToString |
@@ -36,9 +37,8 @@ public class AttributesUpdateNotification implements ToDeviceMsg { | @@ -36,9 +37,8 @@ public class AttributesUpdateNotification implements ToDeviceMsg { | ||
36 | return true; | 37 | return true; |
37 | } | 38 | } |
38 | 39 | ||
39 | - @Override | ||
40 | - public MsgType getMsgType() { | ||
41 | - return MsgType.ATTRIBUTES_UPDATE_NOTIFICATION; | 40 | + public SessionMsgType getSessionMsgType() { |
41 | + return SessionMsgType.ATTRIBUTES_UPDATE_NOTIFICATION; | ||
42 | } | 42 | } |
43 | 43 | ||
44 | public AttributesKVMsg getData() { | 44 | public AttributesKVMsg getData() { |
@@ -15,26 +15,27 @@ | @@ -15,26 +15,27 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.session.MsgType; | 18 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
19 | 20 | ||
20 | public class BasicCommandAckResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse { | 21 | public class BasicCommandAckResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse { |
21 | 22 | ||
22 | private static final long serialVersionUID = 1L; | 23 | private static final long serialVersionUID = 1L; |
23 | 24 | ||
24 | - public static BasicCommandAckResponse onSuccess(MsgType requestMsgType, Integer requestId) { | 25 | + public static BasicCommandAckResponse onSuccess(SessionMsgType requestMsgType, Integer requestId) { |
25 | return BasicCommandAckResponse.onSuccess(requestMsgType, requestId, 200); | 26 | return BasicCommandAckResponse.onSuccess(requestMsgType, requestId, 200); |
26 | } | 27 | } |
27 | 28 | ||
28 | - public static BasicCommandAckResponse onSuccess(MsgType requestMsgType, Integer requestId, Integer code) { | 29 | + public static BasicCommandAckResponse onSuccess(SessionMsgType requestMsgType, Integer requestId, Integer code) { |
29 | return new BasicCommandAckResponse(requestMsgType, requestId, true, null, code); | 30 | return new BasicCommandAckResponse(requestMsgType, requestId, true, null, code); |
30 | } | 31 | } |
31 | 32 | ||
32 | - public static BasicCommandAckResponse onError(MsgType requestMsgType, Integer requestId, Exception error) { | 33 | + public static BasicCommandAckResponse onError(SessionMsgType requestMsgType, Integer requestId, Exception error) { |
33 | return new BasicCommandAckResponse(requestMsgType, requestId, false, error, null); | 34 | return new BasicCommandAckResponse(requestMsgType, requestId, false, error, null); |
34 | } | 35 | } |
35 | 36 | ||
36 | - private BasicCommandAckResponse(MsgType requestMsgType, Integer requestId, boolean success, Exception error, Integer code) { | ||
37 | - super(requestMsgType, requestId, MsgType.TO_DEVICE_RPC_RESPONSE_ACK, success, error, code); | 37 | + private BasicCommandAckResponse(SessionMsgType requestMsgType, Integer requestId, boolean success, Exception error, Integer code) { |
38 | + super(requestMsgType, requestId, SessionMsgType.TO_DEVICE_RPC_RESPONSE_ACK, success, error, code); | ||
38 | } | 39 | } |
39 | 40 | ||
40 | @Override | 41 | @Override |
@@ -16,7 +16,8 @@ | @@ -16,7 +16,8 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import lombok.ToString; | 18 | import lombok.ToString; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | import java.util.Collections; | 22 | import java.util.Collections; |
22 | import java.util.Optional; | 23 | import java.util.Optional; |
@@ -41,8 +42,8 @@ public class BasicGetAttributesRequest extends BasicRequest implements GetAttrib | @@ -41,8 +42,8 @@ public class BasicGetAttributesRequest extends BasicRequest implements GetAttrib | ||
41 | } | 42 | } |
42 | 43 | ||
43 | @Override | 44 | @Override |
44 | - public MsgType getMsgType() { | ||
45 | - return MsgType.GET_ATTRIBUTES_REQUEST; | 45 | + public SessionMsgType getMsgType() { |
46 | + return SessionMsgType.GET_ATTRIBUTES_REQUEST; | ||
46 | } | 47 | } |
47 | 48 | ||
48 | @Override | 49 | @Override |
@@ -17,23 +17,24 @@ package org.thingsboard.server.common.msg.core; | @@ -17,23 +17,24 @@ package org.thingsboard.server.common.msg.core; | ||
17 | 17 | ||
18 | import lombok.ToString; | 18 | import lombok.ToString; |
19 | import org.thingsboard.server.common.msg.kv.AttributesKVMsg; | 19 | import org.thingsboard.server.common.msg.kv.AttributesKVMsg; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | 22 | ||
22 | @ToString | 23 | @ToString |
23 | public class BasicGetAttributesResponse extends BasicResponseMsg<AttributesKVMsg> implements GetAttributesResponse { | 24 | public class BasicGetAttributesResponse extends BasicResponseMsg<AttributesKVMsg> implements GetAttributesResponse { |
24 | 25 | ||
25 | private static final long serialVersionUID = 1L; | 26 | private static final long serialVersionUID = 1L; |
26 | 27 | ||
27 | - public static BasicGetAttributesResponse onSuccess(MsgType requestMsgType, int requestId, AttributesKVMsg code) { | 28 | + public static BasicGetAttributesResponse onSuccess(SessionMsgType requestMsgType, int requestId, AttributesKVMsg code) { |
28 | return new BasicGetAttributesResponse(requestMsgType, requestId, true, null, code); | 29 | return new BasicGetAttributesResponse(requestMsgType, requestId, true, null, code); |
29 | } | 30 | } |
30 | 31 | ||
31 | - public static BasicGetAttributesResponse onError(MsgType requestMsgType, int requestId, Exception error) { | 32 | + public static BasicGetAttributesResponse onError(SessionMsgType requestMsgType, int requestId, Exception error) { |
32 | return new BasicGetAttributesResponse(requestMsgType, requestId, false, error, null); | 33 | return new BasicGetAttributesResponse(requestMsgType, requestId, false, error, null); |
33 | } | 34 | } |
34 | 35 | ||
35 | - private BasicGetAttributesResponse(MsgType requestMsgType, int requestId, boolean success, Exception error, AttributesKVMsg code) { | ||
36 | - super(requestMsgType, requestId, MsgType.GET_ATTRIBUTES_RESPONSE, success, error, code); | 36 | + private BasicGetAttributesResponse(SessionMsgType requestMsgType, int requestId, boolean success, Exception error, AttributesKVMsg code) { |
37 | + super(requestMsgType, requestId, SessionMsgType.GET_ATTRIBUTES_RESPONSE, success, error, code); | ||
37 | } | 38 | } |
38 | 39 | ||
39 | } | 40 | } |
@@ -18,32 +18,33 @@ package org.thingsboard.server.common.msg.core; | @@ -18,32 +18,33 @@ package org.thingsboard.server.common.msg.core; | ||
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | import java.util.Optional; | 19 | import java.util.Optional; |
20 | 20 | ||
21 | -import org.thingsboard.server.common.msg.session.MsgType; | 21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
22 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
22 | 23 | ||
23 | 24 | ||
24 | public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> { | 25 | public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> { |
25 | 26 | ||
26 | private static final long serialVersionUID = 1L; | 27 | private static final long serialVersionUID = 1L; |
27 | 28 | ||
28 | - private final MsgType requestMsgType; | 29 | + private final SessionMsgType requestMsgType; |
29 | private final Integer requestId; | 30 | private final Integer requestId; |
30 | - private final MsgType msgType; | 31 | + private final SessionMsgType sessionMsgType; |
31 | private final boolean success; | 32 | private final boolean success; |
32 | private final T data; | 33 | private final T data; |
33 | private final Exception error; | 34 | private final Exception error; |
34 | 35 | ||
35 | - protected BasicResponseMsg(MsgType requestMsgType, Integer requestId, MsgType msgType, boolean success, Exception error, T data) { | 36 | + protected BasicResponseMsg(SessionMsgType requestMsgType, Integer requestId, SessionMsgType sessionMsgType, boolean success, Exception error, T data) { |
36 | super(); | 37 | super(); |
37 | this.requestMsgType = requestMsgType; | 38 | this.requestMsgType = requestMsgType; |
38 | this.requestId = requestId; | 39 | this.requestId = requestId; |
39 | - this.msgType = msgType; | 40 | + this.sessionMsgType = sessionMsgType; |
40 | this.success = success; | 41 | this.success = success; |
41 | this.error = error; | 42 | this.error = error; |
42 | this.data = data; | 43 | this.data = data; |
43 | } | 44 | } |
44 | 45 | ||
45 | @Override | 46 | @Override |
46 | - public MsgType getRequestMsgType() { | 47 | + public SessionMsgType getRequestMsgType() { |
47 | return requestMsgType; | 48 | return requestMsgType; |
48 | } | 49 | } |
49 | 50 | ||
@@ -72,8 +73,7 @@ public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> | @@ -72,8 +73,7 @@ public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> | ||
72 | return "BasicResponseMsg [success=" + success + ", data=" + data + ", error=" + error + "]"; | 73 | return "BasicResponseMsg [success=" + success + ", data=" + data + ", error=" + error + "]"; |
73 | } | 74 | } |
74 | 75 | ||
75 | - @Override | ||
76 | - public MsgType getMsgType() { | ||
77 | - return msgType; | 76 | + public SessionMsgType getSessionMsgType() { |
77 | + return sessionMsgType; | ||
78 | } | 78 | } |
79 | } | 79 | } |
@@ -16,26 +16,27 @@ | @@ -16,26 +16,27 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import lombok.ToString; | 18 | import lombok.ToString; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | @ToString | 22 | @ToString |
22 | public class BasicStatusCodeResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse { | 23 | public class BasicStatusCodeResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse { |
23 | 24 | ||
24 | private static final long serialVersionUID = 1L; | 25 | private static final long serialVersionUID = 1L; |
25 | 26 | ||
26 | - public static BasicStatusCodeResponse onSuccess(MsgType requestMsgType, Integer requestId) { | 27 | + public static BasicStatusCodeResponse onSuccess(SessionMsgType requestMsgType, Integer requestId) { |
27 | return BasicStatusCodeResponse.onSuccess(requestMsgType, requestId, 0); | 28 | return BasicStatusCodeResponse.onSuccess(requestMsgType, requestId, 0); |
28 | } | 29 | } |
29 | 30 | ||
30 | - public static BasicStatusCodeResponse onSuccess(MsgType requestMsgType, Integer requestId, Integer code) { | 31 | + public static BasicStatusCodeResponse onSuccess(SessionMsgType requestMsgType, Integer requestId, Integer code) { |
31 | return new BasicStatusCodeResponse(requestMsgType, requestId, true, null, code); | 32 | return new BasicStatusCodeResponse(requestMsgType, requestId, true, null, code); |
32 | } | 33 | } |
33 | 34 | ||
34 | - public static BasicStatusCodeResponse onError(MsgType requestMsgType, Integer requestId, Exception error) { | 35 | + public static BasicStatusCodeResponse onError(SessionMsgType requestMsgType, Integer requestId, Exception error) { |
35 | return new BasicStatusCodeResponse(requestMsgType, requestId, false, error, null); | 36 | return new BasicStatusCodeResponse(requestMsgType, requestId, false, error, null); |
36 | } | 37 | } |
37 | 38 | ||
38 | - private BasicStatusCodeResponse(MsgType requestMsgType, Integer requestId, boolean success, Exception error, Integer code) { | ||
39 | - super(requestMsgType, requestId, MsgType.STATUS_CODE_RESPONSE, success, error, code); | 39 | + private BasicStatusCodeResponse(SessionMsgType requestMsgType, Integer requestId, boolean success, Exception error, Integer code) { |
40 | + super(requestMsgType, requestId, SessionMsgType.STATUS_CODE_RESPONSE, success, error, code); | ||
40 | } | 41 | } |
41 | } | 42 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/core/BasicTelemetryUploadRequest.java
@@ -21,7 +21,8 @@ import java.util.List; | @@ -21,7 +21,8 @@ import java.util.List; | ||
21 | import java.util.Map; | 21 | import java.util.Map; |
22 | 22 | ||
23 | import org.thingsboard.server.common.data.kv.KvEntry; | 23 | import org.thingsboard.server.common.data.kv.KvEntry; |
24 | -import org.thingsboard.server.common.msg.session.MsgType; | 24 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
25 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
25 | 26 | ||
26 | public class BasicTelemetryUploadRequest extends BasicRequest implements TelemetryUploadRequest { | 27 | public class BasicTelemetryUploadRequest extends BasicRequest implements TelemetryUploadRequest { |
27 | 28 | ||
@@ -48,8 +49,8 @@ public class BasicTelemetryUploadRequest extends BasicRequest implements Telemet | @@ -48,8 +49,8 @@ public class BasicTelemetryUploadRequest extends BasicRequest implements Telemet | ||
48 | } | 49 | } |
49 | 50 | ||
50 | @Override | 51 | @Override |
51 | - public MsgType getMsgType() { | ||
52 | - return MsgType.POST_TELEMETRY_REQUEST; | 52 | + public SessionMsgType getMsgType() { |
53 | + return SessionMsgType.POST_TELEMETRY_REQUEST; | ||
53 | } | 54 | } |
54 | 55 | ||
55 | @Override | 56 | @Override |
@@ -20,7 +20,8 @@ import java.util.LinkedHashSet; | @@ -20,7 +20,8 @@ import java.util.LinkedHashSet; | ||
20 | import java.util.Set; | 20 | import java.util.Set; |
21 | 21 | ||
22 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 22 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
23 | -import org.thingsboard.server.common.msg.session.MsgType; | 23 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
24 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
24 | 25 | ||
25 | public class BasicUpdateAttributesRequest extends BasicRequest implements UpdateAttributesRequest { | 26 | public class BasicUpdateAttributesRequest extends BasicRequest implements UpdateAttributesRequest { |
26 | 27 | ||
@@ -46,8 +47,8 @@ public class BasicUpdateAttributesRequest extends BasicRequest implements Update | @@ -46,8 +47,8 @@ public class BasicUpdateAttributesRequest extends BasicRequest implements Update | ||
46 | } | 47 | } |
47 | 48 | ||
48 | @Override | 49 | @Override |
49 | - public MsgType getMsgType() { | ||
50 | - return MsgType.POST_ATTRIBUTES_REQUEST; | 50 | + public SessionMsgType getMsgType() { |
51 | + return SessionMsgType.POST_ATTRIBUTES_REQUEST; | ||
51 | } | 52 | } |
52 | 53 | ||
53 | @Override | 54 | @Override |
@@ -18,12 +18,12 @@ package org.thingsboard.server.common.msg.core; | @@ -18,12 +18,12 @@ package org.thingsboard.server.common.msg.core; | ||
18 | import java.io.Serializable; | 18 | import java.io.Serializable; |
19 | import java.util.Optional; | 19 | import java.util.Optional; |
20 | 20 | ||
21 | -import org.thingsboard.server.common.msg.session.MsgType; | 21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
23 | 23 | ||
24 | public interface ResponseMsg<T extends Serializable> extends ToDeviceMsg { | 24 | public interface ResponseMsg<T extends Serializable> extends ToDeviceMsg { |
25 | 25 | ||
26 | - MsgType getRequestMsgType(); | 26 | + SessionMsgType getRequestMsgType(); |
27 | 27 | ||
28 | Integer getRequestId(); | 28 | Integer getRequestId(); |
29 | 29 |
@@ -16,14 +16,15 @@ | @@ -16,14 +16,15 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
23 | */ | 24 | */ |
24 | public class RpcSubscribeMsg implements FromDeviceMsg { | 25 | public class RpcSubscribeMsg implements FromDeviceMsg { |
25 | @Override | 26 | @Override |
26 | - public MsgType getMsgType() { | ||
27 | - return MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST; | 27 | + public SessionMsgType getMsgType() { |
28 | + return SessionMsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST; | ||
28 | } | 29 | } |
29 | } | 30 | } |
@@ -16,14 +16,15 @@ | @@ -16,14 +16,15 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
23 | */ | 24 | */ |
24 | public class RpcUnsubscribeMsg implements FromDeviceMsg { | 25 | public class RpcUnsubscribeMsg implements FromDeviceMsg { |
25 | @Override | 26 | @Override |
26 | - public MsgType getMsgType() { | ||
27 | - return MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST; | 27 | + public SessionMsgType getMsgType() { |
28 | + return SessionMsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST; | ||
28 | } | 29 | } |
29 | } | 30 | } |
@@ -21,7 +21,7 @@ package org.thingsboard.server.common.msg.core; | @@ -21,7 +21,7 @@ package org.thingsboard.server.common.msg.core; | ||
21 | 21 | ||
22 | public enum RuleEngineError { | 22 | public enum RuleEngineError { |
23 | 23 | ||
24 | - NO_RULES, NO_ACTIVE_RULES, NO_FILTERS_MATCHED, NO_REQUEST_FROM_ACTIONS, NO_TWO_WAY_ACTIONS, NO_RESPONSE_FROM_ACTIONS, PLUGIN_TIMEOUT(true); | 24 | + NO_RULES, NO_ACTIVE_RULES, NO_FILTERS_MATCHED, NO_REQUEST_FROM_ACTIONS, NO_TWO_WAY_ACTIONS, NO_RESPONSE_FROM_ACTIONS, QUEUE_PUT_TIMEOUT(true); |
25 | 25 | ||
26 | private final boolean critical; | 26 | private final boolean critical; |
27 | 27 |
@@ -16,7 +16,8 @@ | @@ -16,7 +16,8 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 21 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
21 | 22 | ||
22 | /** | 23 | /** |
@@ -25,7 +26,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceMsg; | @@ -25,7 +26,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceMsg; | ||
25 | @Data | 26 | @Data |
26 | public class RuleEngineErrorMsg implements ToDeviceMsg { | 27 | public class RuleEngineErrorMsg implements ToDeviceMsg { |
27 | 28 | ||
28 | - private final MsgType inMsgType; | 29 | + private final SessionMsgType inSessionMsgType; |
29 | private final RuleEngineError error; | 30 | private final RuleEngineError error; |
30 | 31 | ||
31 | @Override | 32 | @Override |
@@ -33,9 +34,8 @@ public class RuleEngineErrorMsg implements ToDeviceMsg { | @@ -33,9 +34,8 @@ public class RuleEngineErrorMsg implements ToDeviceMsg { | ||
33 | return false; | 34 | return false; |
34 | } | 35 | } |
35 | 36 | ||
36 | - @Override | ||
37 | - public MsgType getMsgType() { | ||
38 | - return MsgType.RULE_ENGINE_ERROR; | 37 | + public SessionMsgType getSessionMsgType() { |
38 | + return SessionMsgType.RULE_ENGINE_ERROR; | ||
39 | } | 39 | } |
40 | 40 | ||
41 | public String getErrorMsg() { | 41 | public String getErrorMsg() { |
@@ -52,7 +52,7 @@ public class RuleEngineErrorMsg implements ToDeviceMsg { | @@ -52,7 +52,7 @@ public class RuleEngineErrorMsg implements ToDeviceMsg { | ||
52 | return "Rule filters match, but no rule with two-way action configured!"; | 52 | return "Rule filters match, but no rule with two-way action configured!"; |
53 | case NO_RESPONSE_FROM_ACTIONS: | 53 | case NO_RESPONSE_FROM_ACTIONS: |
54 | return "Rule filters match, message processed by plugin, but no response produced by rule action!"; | 54 | return "Rule filters match, message processed by plugin, but no response produced by rule action!"; |
55 | - case PLUGIN_TIMEOUT: | 55 | + case QUEUE_PUT_TIMEOUT: |
56 | return "Timeout during processing of message by plugin!"; | 56 | return "Timeout during processing of message by plugin!"; |
57 | default: | 57 | default: |
58 | throw new RuntimeException("Error " + error + " is not supported!"); | 58 | throw new RuntimeException("Error " + error + " is not supported!"); |
@@ -16,14 +16,15 @@ | @@ -16,14 +16,15 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
23 | */ | 24 | */ |
24 | public class SessionCloseMsg implements FromDeviceMsg { | 25 | public class SessionCloseMsg implements FromDeviceMsg { |
25 | @Override | 26 | @Override |
26 | - public MsgType getMsgType() { | ||
27 | - return MsgType.SESSION_CLOSE; | 27 | + public SessionMsgType getMsgType() { |
28 | + return SessionMsgType.SESSION_CLOSE; | ||
28 | } | 29 | } |
29 | } | 30 | } |
@@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | @@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | ||
17 | 17 | ||
18 | import lombok.ToString; | 18 | import lombok.ToString; |
19 | import org.thingsboard.server.common.msg.kv.AttributesKVMsg; | 19 | import org.thingsboard.server.common.msg.kv.AttributesKVMsg; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
22 | 23 | ||
23 | @ToString | 24 | @ToString |
@@ -30,9 +31,8 @@ public class SessionCloseNotification implements ToDeviceMsg { | @@ -30,9 +31,8 @@ public class SessionCloseNotification implements ToDeviceMsg { | ||
30 | return true; | 31 | return true; |
31 | } | 32 | } |
32 | 33 | ||
33 | - @Override | ||
34 | - public MsgType getMsgType() { | ||
35 | - return MsgType.SESSION_CLOSE; | 34 | + public SessionMsgType getSessionMsgType() { |
35 | + return SessionMsgType.SESSION_CLOSE; | ||
36 | } | 36 | } |
37 | 37 | ||
38 | } | 38 | } |
@@ -16,14 +16,15 @@ | @@ -16,14 +16,15 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 18 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | 21 | ||
21 | /** | 22 | /** |
22 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
23 | */ | 24 | */ |
24 | public class SessionOpenMsg implements FromDeviceMsg { | 25 | public class SessionOpenMsg implements FromDeviceMsg { |
25 | @Override | 26 | @Override |
26 | - public MsgType getMsgType() { | ||
27 | - return MsgType.SESSION_OPEN; | 27 | + public SessionMsgType getMsgType() { |
28 | + return SessionMsgType.SESSION_OPEN; | ||
28 | } | 29 | } |
29 | } | 30 | } |
@@ -16,7 +16,8 @@ | @@ -16,7 +16,8 @@ | ||
16 | package org.thingsboard.server.common.msg.core; | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
20 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 21 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
21 | 22 | ||
22 | /** | 23 | /** |
@@ -29,9 +30,8 @@ public class ToDeviceRpcRequestMsg implements ToDeviceMsg { | @@ -29,9 +30,8 @@ public class ToDeviceRpcRequestMsg implements ToDeviceMsg { | ||
29 | private final String method; | 30 | private final String method; |
30 | private final String params; | 31 | private final String params; |
31 | 32 | ||
32 | - @Override | ||
33 | - public MsgType getMsgType() { | ||
34 | - return MsgType.TO_DEVICE_RPC_REQUEST; | 33 | + public SessionMsgType getSessionMsgType() { |
34 | + return SessionMsgType.TO_DEVICE_RPC_REQUEST; | ||
35 | } | 35 | } |
36 | 36 | ||
37 | @Override | 37 | @Override |
@@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | @@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | ||
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | 22 | ||
22 | /** | 23 | /** |
23 | * @author Andrew Shvayka | 24 | * @author Andrew Shvayka |
@@ -29,7 +30,7 @@ public class ToDeviceRpcResponseMsg implements FromDeviceMsg { | @@ -29,7 +30,7 @@ public class ToDeviceRpcResponseMsg implements FromDeviceMsg { | ||
29 | private final String data; | 30 | private final String data; |
30 | 31 | ||
31 | @Override | 32 | @Override |
32 | - public MsgType getMsgType() { | ||
33 | - return MsgType.TO_DEVICE_RPC_RESPONSE; | 33 | + public SessionMsgType getMsgType() { |
34 | + return SessionMsgType.TO_DEVICE_RPC_RESPONSE; | ||
34 | } | 35 | } |
35 | } | 36 | } |
@@ -17,7 +17,7 @@ package org.thingsboard.server.common.msg.core; | @@ -17,7 +17,7 @@ package org.thingsboard.server.common.msg.core; | ||
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * @author Andrew Shvayka | 23 | * @author Andrew Shvayka |
@@ -30,7 +30,7 @@ public class ToServerRpcRequestMsg implements FromDeviceRequestMsg { | @@ -30,7 +30,7 @@ public class ToServerRpcRequestMsg implements FromDeviceRequestMsg { | ||
30 | private final String params; | 30 | private final String params; |
31 | 31 | ||
32 | @Override | 32 | @Override |
33 | - public MsgType getMsgType() { | ||
34 | - return MsgType.TO_SERVER_RPC_REQUEST; | 33 | + public SessionMsgType getMsgType() { |
34 | + return SessionMsgType.TO_SERVER_RPC_REQUEST; | ||
35 | } | 35 | } |
36 | } | 36 | } |
@@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | @@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; | ||
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
22 | 23 | ||
23 | /** | 24 | /** |
@@ -29,9 +30,8 @@ public class ToServerRpcResponseMsg implements ToDeviceMsg { | @@ -29,9 +30,8 @@ public class ToServerRpcResponseMsg implements ToDeviceMsg { | ||
29 | private final int requestId; | 30 | private final int requestId; |
30 | private final String data; | 31 | private final String data; |
31 | 32 | ||
32 | - @Override | ||
33 | - public MsgType getMsgType() { | ||
34 | - return MsgType.TO_SERVER_RPC_RESPONSE; | 33 | + public SessionMsgType getSessionMsgType() { |
34 | + return SessionMsgType.TO_SERVER_RPC_RESPONSE; | ||
35 | } | 35 | } |
36 | 36 | ||
37 | @Override | 37 | @Override |
common/message/src/main/java/org/thingsboard/server/common/msg/device/BasicDeviceToDeviceActorMsg.java
renamed from
common/message/src/main/java/org/thingsboard/server/common/msg/device/BasicToDeviceActorMsg.java
@@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.id.CustomerId; | @@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.id.CustomerId; | ||
20 | import org.thingsboard.server.common.data.id.DeviceId; | 20 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | import org.thingsboard.server.common.data.id.SessionId; | 21 | import org.thingsboard.server.common.data.id.SessionId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | +import org.thingsboard.server.common.msg.MsgType; | ||
23 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
24 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 25 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
25 | import org.thingsboard.server.common.msg.session.SessionType; | 26 | import org.thingsboard.server.common.msg.session.SessionType; |
@@ -28,7 +29,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceActorSessionMsg; | @@ -28,7 +29,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceActorSessionMsg; | ||
28 | import java.util.Optional; | 29 | import java.util.Optional; |
29 | 30 | ||
30 | @ToString | 31 | @ToString |
31 | -public class BasicToDeviceActorMsg implements ToDeviceActorMsg { | 32 | +public class BasicDeviceToDeviceActorMsg implements DeviceToDeviceActorMsg { |
32 | 33 | ||
33 | private static final long serialVersionUID = -1866795134993115408L; | 34 | private static final long serialVersionUID = -1866795134993115408L; |
34 | 35 | ||
@@ -40,16 +41,16 @@ public class BasicToDeviceActorMsg implements ToDeviceActorMsg { | @@ -40,16 +41,16 @@ public class BasicToDeviceActorMsg implements ToDeviceActorMsg { | ||
40 | private final ServerAddress serverAddress; | 41 | private final ServerAddress serverAddress; |
41 | private final FromDeviceMsg msg; | 42 | private final FromDeviceMsg msg; |
42 | 43 | ||
43 | - public BasicToDeviceActorMsg(ToDeviceActorMsg other, FromDeviceMsg msg) { | 44 | + public BasicDeviceToDeviceActorMsg(DeviceToDeviceActorMsg other, FromDeviceMsg msg) { |
44 | this(null, other.getTenantId(), other.getCustomerId(), other.getDeviceId(), other.getSessionId(), other.getSessionType(), msg); | 45 | this(null, other.getTenantId(), other.getCustomerId(), other.getDeviceId(), other.getSessionId(), other.getSessionType(), msg); |
45 | } | 46 | } |
46 | 47 | ||
47 | - public BasicToDeviceActorMsg(ToDeviceActorSessionMsg msg, SessionType sessionType) { | 48 | + public BasicDeviceToDeviceActorMsg(ToDeviceActorSessionMsg msg, SessionType sessionType) { |
48 | this(null, msg.getTenantId(), msg.getCustomerId(), msg.getDeviceId(), msg.getSessionId(), sessionType, msg.getSessionMsg().getMsg()); | 49 | this(null, msg.getTenantId(), msg.getCustomerId(), msg.getDeviceId(), msg.getSessionId(), sessionType, msg.getSessionMsg().getMsg()); |
49 | } | 50 | } |
50 | 51 | ||
51 | - private BasicToDeviceActorMsg(ServerAddress serverAddress, TenantId tenantId, CustomerId customerId, DeviceId deviceId, SessionId sessionId, SessionType sessionType, | ||
52 | - FromDeviceMsg msg) { | 52 | + private BasicDeviceToDeviceActorMsg(ServerAddress serverAddress, TenantId tenantId, CustomerId customerId, DeviceId deviceId, SessionId sessionId, SessionType sessionType, |
53 | + FromDeviceMsg msg) { | ||
53 | super(); | 54 | super(); |
54 | this.serverAddress = serverAddress; | 55 | this.serverAddress = serverAddress; |
55 | this.tenantId = tenantId; | 56 | this.tenantId = tenantId; |
@@ -95,7 +96,12 @@ public class BasicToDeviceActorMsg implements ToDeviceActorMsg { | @@ -95,7 +96,12 @@ public class BasicToDeviceActorMsg implements ToDeviceActorMsg { | ||
95 | } | 96 | } |
96 | 97 | ||
97 | @Override | 98 | @Override |
98 | - public ToDeviceActorMsg toOtherAddress(ServerAddress otherAddress) { | ||
99 | - return new BasicToDeviceActorMsg(otherAddress, tenantId, customerId, deviceId, sessionId, sessionType, msg); | 99 | + public DeviceToDeviceActorMsg toOtherAddress(ServerAddress otherAddress) { |
100 | + return new BasicDeviceToDeviceActorMsg(otherAddress, tenantId, customerId, deviceId, sessionId, sessionType, msg); | ||
101 | + } | ||
102 | + | ||
103 | + @Override | ||
104 | + public MsgType getMsgType() { | ||
105 | + return MsgType.DEVICE_SESSION_TO_DEVICE_ACTOR_MSG; | ||
100 | } | 106 | } |
101 | } | 107 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/device/DeviceToDeviceActorMsg.java
renamed from
common/message/src/main/java/org/thingsboard/server/common/msg/device/ToDeviceActorMsg.java
@@ -19,6 +19,7 @@ import java.io.Serializable; | @@ -19,6 +19,7 @@ import java.io.Serializable; | ||
19 | import java.util.Optional; | 19 | import java.util.Optional; |
20 | 20 | ||
21 | import org.thingsboard.server.common.data.id.SessionId; | 21 | import org.thingsboard.server.common.data.id.SessionId; |
22 | +import org.thingsboard.server.common.msg.TbActorMsg; | ||
22 | import org.thingsboard.server.common.msg.aware.CustomerAwareMsg; | 23 | import org.thingsboard.server.common.msg.aware.CustomerAwareMsg; |
23 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; | 24 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
24 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; | 25 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; |
@@ -26,7 +27,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | @@ -26,7 +27,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
26 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 27 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
27 | import org.thingsboard.server.common.msg.session.SessionType; | 28 | import org.thingsboard.server.common.msg.session.SessionType; |
28 | 29 | ||
29 | -public interface ToDeviceActorMsg extends DeviceAwareMsg, CustomerAwareMsg, TenantAwareMsg, Serializable { | 30 | +public interface DeviceToDeviceActorMsg extends TbActorMsg, DeviceAwareMsg, CustomerAwareMsg, TenantAwareMsg, Serializable { |
30 | 31 | ||
31 | SessionId getSessionId(); | 32 | SessionId getSessionId(); |
32 | 33 | ||
@@ -36,5 +37,5 @@ public interface ToDeviceActorMsg extends DeviceAwareMsg, CustomerAwareMsg, Tena | @@ -36,5 +37,5 @@ public interface ToDeviceActorMsg extends DeviceAwareMsg, CustomerAwareMsg, Tena | ||
36 | 37 | ||
37 | FromDeviceMsg getPayload(); | 38 | FromDeviceMsg getPayload(); |
38 | 39 | ||
39 | - ToDeviceActorMsg toOtherAddress(ServerAddress otherAddress); | 40 | + DeviceToDeviceActorMsg toOtherAddress(ServerAddress otherAddress); |
40 | } | 41 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/session/SessionMsgType.java
renamed from
common/message/src/main/java/org/thingsboard/server/common/msg/session/MsgType.java
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.common.msg.session; | 16 | package org.thingsboard.server.common.msg.session; |
17 | 17 | ||
18 | -public enum MsgType { | 18 | +public enum SessionMsgType { |
19 | GET_ATTRIBUTES_REQUEST(true), POST_ATTRIBUTES_REQUEST(true), GET_ATTRIBUTES_RESPONSE, | 19 | GET_ATTRIBUTES_REQUEST(true), POST_ATTRIBUTES_REQUEST(true), GET_ATTRIBUTES_RESPONSE, |
20 | SUBSCRIBE_ATTRIBUTES_REQUEST, UNSUBSCRIBE_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATE_NOTIFICATION, | 20 | SUBSCRIBE_ATTRIBUTES_REQUEST, UNSUBSCRIBE_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATE_NOTIFICATION, |
21 | 21 | ||
@@ -32,11 +32,11 @@ public enum MsgType { | @@ -32,11 +32,11 @@ public enum MsgType { | ||
32 | 32 | ||
33 | private final boolean requiresRulesProcessing; | 33 | private final boolean requiresRulesProcessing; |
34 | 34 | ||
35 | - MsgType() { | 35 | + SessionMsgType() { |
36 | this(false); | 36 | this(false); |
37 | } | 37 | } |
38 | 38 | ||
39 | - MsgType(boolean requiresRulesProcessing) { | 39 | + SessionMsgType(boolean requiresRulesProcessing) { |
40 | this.requiresRulesProcessing = requiresRulesProcessing; | 40 | this.requiresRulesProcessing = requiresRulesProcessing; |
41 | } | 41 | } |
42 | 42 |
common/message/src/main/java/org/thingsboard/server/common/msg/timeout/DeviceActorQueueTimeoutMsg.java
renamed from
extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/msg/TimeoutUUIDMsg.java
@@ -13,17 +13,24 @@ | @@ -13,17 +13,24 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.extensions.api.plugins.msg; | 16 | +package org.thingsboard.server.common.msg.timeout; |
17 | + | ||
18 | +import org.thingsboard.server.common.msg.MsgType; | ||
19 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
17 | 20 | ||
18 | import java.util.UUID; | 21 | import java.util.UUID; |
19 | 22 | ||
20 | /** | 23 | /** |
21 | * @author Andrew Shvayka | 24 | * @author Andrew Shvayka |
22 | */ | 25 | */ |
23 | -public final class TimeoutUUIDMsg extends TimeoutMsg<UUID> { | 26 | +public final class DeviceActorQueueTimeoutMsg extends TimeoutMsg<UUID> { |
24 | 27 | ||
25 | - public TimeoutUUIDMsg(UUID id, long timeout) { | 28 | + public DeviceActorQueueTimeoutMsg(UUID id, long timeout) { |
26 | super(id, timeout); | 29 | super(id, timeout); |
27 | } | 30 | } |
28 | 31 | ||
32 | + @Override | ||
33 | + public MsgType getMsgType() { | ||
34 | + return MsgType.DEVICE_ACTOR_QUEUE_TIMEOUT_MSG; | ||
35 | + } | ||
29 | } | 36 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/timeout/DeviceActorRpcTimeoutMsg.java
renamed from
extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/msg/TimeoutIntMsg.java
@@ -13,15 +13,21 @@ | @@ -13,15 +13,21 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.extensions.api.plugins.msg; | 16 | +package org.thingsboard.server.common.msg.timeout; |
17 | + | ||
18 | +import org.thingsboard.server.common.msg.MsgType; | ||
17 | 19 | ||
18 | /** | 20 | /** |
19 | * @author Andrew Shvayka | 21 | * @author Andrew Shvayka |
20 | */ | 22 | */ |
21 | -public final class TimeoutIntMsg extends TimeoutMsg<Integer> { | 23 | +public final class DeviceActorRpcTimeoutMsg extends TimeoutMsg<Integer> { |
22 | 24 | ||
23 | - public TimeoutIntMsg(Integer id, long timeout) { | 25 | + public DeviceActorRpcTimeoutMsg(Integer id, long timeout) { |
24 | super(id, timeout); | 26 | super(id, timeout); |
25 | } | 27 | } |
26 | 28 | ||
29 | + @Override | ||
30 | + public MsgType getMsgType() { | ||
31 | + return MsgType.DEVICE_ACTOR_RPC_TIMEOUT_MSG; | ||
32 | + } | ||
27 | } | 33 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/timeout/TimeoutMsg.java
renamed from
extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/msg/TimeoutMsg.java
@@ -13,15 +13,16 @@ | @@ -13,15 +13,16 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.extensions.api.plugins.msg; | 16 | +package org.thingsboard.server.common.msg.timeout; |
17 | 17 | ||
18 | import lombok.Data; | 18 | import lombok.Data; |
19 | +import org.thingsboard.server.common.msg.TbActorMsg; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * @author Andrew Shvayka | 22 | * @author Andrew Shvayka |
22 | */ | 23 | */ |
23 | @Data | 24 | @Data |
24 | -public class TimeoutMsg<T> { | 25 | +public abstract class TimeoutMsg<T> implements TbActorMsg { |
25 | private final T id; | 26 | private final T id; |
26 | private final long timeout; | 27 | private final long timeout; |
27 | } | 28 | } |
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | package org.thingsboard.server.common.transport; | 16 | package org.thingsboard.server.common.transport; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg; | 18 | import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg; |
19 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
20 | import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg; | 20 | import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg; |
21 | import org.thingsboard.server.common.msg.session.SessionContext; | 21 | import org.thingsboard.server.common.msg.session.SessionContext; |
22 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; | 22 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
@@ -25,7 +25,7 @@ import java.util.Optional; | @@ -25,7 +25,7 @@ import java.util.Optional; | ||
25 | 25 | ||
26 | public interface TransportAdaptor<C extends SessionContext, T, V> { | 26 | public interface TransportAdaptor<C extends SessionContext, T, V> { |
27 | 27 | ||
28 | - AdaptorToSessionActorMsg convertToActorMsg(C ctx, MsgType type, T inbound) throws AdaptorException; | 28 | + AdaptorToSessionActorMsg convertToActorMsg(C ctx, SessionMsgType type, T inbound) throws AdaptorException; |
29 | 29 | ||
30 | Optional<V> convertToAdaptorMsg(C ctx, SessionActorToAdaptorMsg msg) throws AdaptorException; | 30 | Optional<V> convertToAdaptorMsg(C ctx, SessionActorToAdaptorMsg msg) throws AdaptorException; |
31 | 31 |
@@ -75,6 +75,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | @@ -75,6 +75,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC | ||
75 | log.trace("Save system rule chain with predefined id {}", SYSTEM_TENANT); | 75 | log.trace("Save system rule chain with predefined id {}", SYSTEM_TENANT); |
76 | ruleChain.setTenantId(SYSTEM_TENANT); | 76 | ruleChain.setTenantId(SYSTEM_TENANT); |
77 | } | 77 | } |
78 | + //TODO: Temporary Hack to continue tests; | ||
79 | + ruleChain.setRoot(true); | ||
78 | RuleChain savedRuleChain = ruleChainDao.save(ruleChain); | 80 | RuleChain savedRuleChain = ruleChainDao.save(ruleChain); |
79 | if (ruleChain.isRoot() && ruleChain.getTenantId() != null && ruleChain.getId() == null) { | 81 | if (ruleChain.isRoot() && ruleChain.getTenantId() != null && ruleChain.getId() == null) { |
80 | try { | 82 | try { |
@@ -22,6 +22,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | @@ -22,6 +22,7 @@ import org.thingsboard.server.common.data.id.DeviceId; | ||
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.kv.AttributeKey; | 23 | import org.thingsboard.server.common.data.kv.AttributeKey; |
24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; | 24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | +import org.thingsboard.server.common.msg.MsgType; | ||
25 | 26 | ||
26 | import java.util.List; | 27 | import java.util.List; |
27 | import java.util.Set; | 28 | import java.util.Set; |
@@ -54,4 +55,8 @@ public class DeviceAttributesEventNotificationMsg implements ToDeviceActorNotifi | @@ -54,4 +55,8 @@ public class DeviceAttributesEventNotificationMsg implements ToDeviceActorNotifi | ||
54 | return new DeviceAttributesEventNotificationMsg(tenantId, deviceId, keys, null, null, true); | 55 | return new DeviceAttributesEventNotificationMsg(tenantId, deviceId, keys, null, null, true); |
55 | } | 56 | } |
56 | 57 | ||
58 | + @Override | ||
59 | + public MsgType getMsgType() { | ||
60 | + return MsgType.DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG; | ||
61 | + } | ||
57 | } | 62 | } |
@@ -21,6 +21,7 @@ import lombok.ToString; | @@ -21,6 +21,7 @@ import lombok.ToString; | ||
21 | import org.thingsboard.server.common.data.id.DeviceId; | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | import org.thingsboard.server.common.data.id.TenantId; | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | import org.thingsboard.server.common.data.kv.AttributeKey; | 23 | import org.thingsboard.server.common.data.kv.AttributeKey; |
24 | +import org.thingsboard.server.common.msg.MsgType; | ||
24 | 25 | ||
25 | import java.util.Set; | 26 | import java.util.Set; |
26 | 27 | ||
@@ -33,4 +34,8 @@ public class DeviceCredentialsUpdateNotificationMsg implements ToDeviceActorNoti | @@ -33,4 +34,8 @@ public class DeviceCredentialsUpdateNotificationMsg implements ToDeviceActorNoti | ||
33 | private final TenantId tenantId; | 34 | private final TenantId tenantId; |
34 | private final DeviceId deviceId; | 35 | private final DeviceId deviceId; |
35 | 36 | ||
37 | + @Override | ||
38 | + public MsgType getMsgType() { | ||
39 | + return MsgType.DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG; | ||
40 | + } | ||
36 | } | 41 | } |
@@ -19,6 +19,7 @@ import lombok.AllArgsConstructor; | @@ -19,6 +19,7 @@ import lombok.AllArgsConstructor; | ||
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import org.thingsboard.server.common.data.id.DeviceId; | 20 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | import org.thingsboard.server.common.data.id.TenantId; | 21 | import org.thingsboard.server.common.data.id.TenantId; |
22 | +import org.thingsboard.server.common.msg.MsgType; | ||
22 | 23 | ||
23 | @Data | 24 | @Data |
24 | @AllArgsConstructor | 25 | @AllArgsConstructor |
@@ -27,4 +28,9 @@ public class DeviceNameOrTypeUpdateMsg implements ToDeviceActorNotificationMsg { | @@ -27,4 +28,9 @@ public class DeviceNameOrTypeUpdateMsg implements ToDeviceActorNotificationMsg { | ||
27 | private final DeviceId deviceId; | 28 | private final DeviceId deviceId; |
28 | private final String deviceName; | 29 | private final String deviceName; |
29 | private final String deviceType; | 30 | private final String deviceType; |
31 | + | ||
32 | + @Override | ||
33 | + public MsgType getMsgType() { | ||
34 | + return MsgType.DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG; | ||
35 | + } | ||
30 | } | 36 | } |
@@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.api.device; | 16 | package org.thingsboard.server.extensions.api.device; |
17 | 17 | ||
18 | +import org.thingsboard.server.common.msg.TbActorMsg; | ||
18 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; | 19 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
19 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; | 20 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; |
20 | 21 | ||
@@ -23,6 +24,6 @@ import java.io.Serializable; | @@ -23,6 +24,6 @@ import java.io.Serializable; | ||
23 | /** | 24 | /** |
24 | * @author Andrew Shvayka | 25 | * @author Andrew Shvayka |
25 | */ | 26 | */ |
26 | -public interface ToDeviceActorNotificationMsg extends TenantAwareMsg, DeviceAwareMsg, Serializable { | 27 | +public interface ToDeviceActorNotificationMsg extends TbActorMsg, TenantAwareMsg, DeviceAwareMsg, Serializable { |
27 | 28 | ||
28 | } | 29 | } |
@@ -21,7 +21,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | @@ -21,7 +21,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
21 | import org.thingsboard.server.extensions.api.plugins.handlers.*; | 21 | import org.thingsboard.server.extensions.api.plugins.handlers.*; |
22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | 22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
23 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 23 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
24 | -import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; | 24 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; |
25 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | 25 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
26 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; | 26 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
27 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | 27 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; |
@@ -21,7 +21,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | @@ -21,7 +21,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
21 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; | 21 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; | 22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
23 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 23 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
24 | -import org.thingsboard.server.extensions.api.plugins.msg.TimeoutMsg; | 24 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; |
25 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; | 25 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
26 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; | 26 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
27 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | 27 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.api.plugins; | 16 | package org.thingsboard.server.extensions.api.plugins; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 19 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
20 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; | 20 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg; | 21 | import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg; |
@@ -28,7 +28,7 @@ import java.util.Optional; | @@ -28,7 +28,7 @@ import java.util.Optional; | ||
28 | 28 | ||
29 | public interface PluginAction<T> extends ConfigurableComponent<T>, RuleLifecycleComponent { | 29 | public interface PluginAction<T> extends ConfigurableComponent<T>, RuleLifecycleComponent { |
30 | 30 | ||
31 | - Optional<RuleToPluginMsg> convert(RuleContext ctx, ToDeviceActorMsg toDeviceActorMsg, RuleProcessingMetaData deviceMsgMd); | 31 | + Optional<RuleToPluginMsg> convert(RuleContext ctx, DeviceToDeviceActorMsg deviceToDeviceActorMsg, RuleProcessingMetaData deviceMsgMd); |
32 | 32 | ||
33 | Optional<ToDeviceMsg> convert(PluginToRuleMsg<?> response); | 33 | Optional<ToDeviceMsg> convert(PluginToRuleMsg<?> response); |
34 | 34 |
@@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.relation.EntityRelation; | @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.relation.EntityRelation; | ||
25 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; | 25 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
26 | import org.thingsboard.server.common.msg.cluster.ServerAddress; | 26 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
27 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | 27 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
28 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | ||
28 | import org.thingsboard.server.extensions.api.plugins.msg.*; | 29 | import org.thingsboard.server.extensions.api.plugins.msg.*; |
29 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; | 30 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
30 | import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; | 31 | import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; |
@@ -18,7 +18,8 @@ package org.thingsboard.server.extensions.api.plugins.handlers; | @@ -18,7 +18,8 @@ package org.thingsboard.server.extensions.api.plugins.handlers; | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.thingsboard.server.common.data.id.RuleId; | 19 | import org.thingsboard.server.common.data.id.RuleId; |
20 | import org.thingsboard.server.common.data.id.TenantId; | 20 | import org.thingsboard.server.common.data.id.TenantId; |
21 | -import org.thingsboard.server.common.msg.session.MsgType; | 21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
22 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
22 | import org.thingsboard.server.extensions.api.plugins.PluginContext; | 23 | import org.thingsboard.server.extensions.api.plugins.PluginContext; |
23 | import org.thingsboard.server.extensions.api.plugins.msg.GetAttributesRequestRuleToPluginMsg; | 24 | import org.thingsboard.server.extensions.api.plugins.msg.GetAttributesRequestRuleToPluginMsg; |
24 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 25 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -56,8 +57,8 @@ public class DefaultRuleMsgHandler implements RuleMsgHandler { | @@ -56,8 +57,8 @@ public class DefaultRuleMsgHandler implements RuleMsgHandler { | ||
56 | msgTypeNotSupported(msg.getPayload().getMsgType()); | 57 | msgTypeNotSupported(msg.getPayload().getMsgType()); |
57 | } | 58 | } |
58 | 59 | ||
59 | - private void msgTypeNotSupported(MsgType msgType) { | ||
60 | - throw new RuntimeException("Not supported msg type: " + msgType + "!"); | 60 | + private void msgTypeNotSupported(SessionMsgType sessionMsgType) { |
61 | + throw new RuntimeException("Not supported msg type: " + sessionMsgType + "!"); | ||
61 | } | 62 | } |
62 | 63 | ||
63 | } | 64 | } |
extensions-api/src/main/java/org/thingsboard/server/extensions/api/plugins/msg/ToDeviceRpcRequestPluginMsg.java
deleted
100644 → 0
1 | -/** | ||
2 | - * Copyright © 2016-2018 The Thingsboard Authors | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.thingsboard.server.extensions.api.plugins.msg; | ||
17 | - | ||
18 | -import lombok.Getter; | ||
19 | -import lombok.RequiredArgsConstructor; | ||
20 | -import lombok.ToString; | ||
21 | -import org.thingsboard.server.common.data.id.DeviceId; | ||
22 | -import org.thingsboard.server.common.data.id.PluginId; | ||
23 | -import org.thingsboard.server.common.data.id.TenantId; | ||
24 | -import org.thingsboard.server.common.msg.cluster.ServerAddress; | ||
25 | -import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; | ||
26 | -import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; | ||
27 | - | ||
28 | -import java.util.Optional; | ||
29 | - | ||
30 | -/** | ||
31 | - * @author Andrew Shvayka | ||
32 | - */ | ||
33 | -@ToString | ||
34 | -@RequiredArgsConstructor | ||
35 | -public class ToDeviceRpcRequestPluginMsg implements ToDeviceActorNotificationMsg { | ||
36 | - | ||
37 | - private final ServerAddress serverAddress; | ||
38 | - @Getter | ||
39 | - private final PluginId pluginId; | ||
40 | - @Getter | ||
41 | - private final TenantId pluginTenantId; | ||
42 | - @Getter | ||
43 | - private final ToDeviceRpcRequest msg; | ||
44 | - | ||
45 | - public ToDeviceRpcRequestPluginMsg(PluginId pluginId, TenantId pluginTenantId, ToDeviceRpcRequest msg) { | ||
46 | - this(null, pluginId, pluginTenantId, msg); | ||
47 | - } | ||
48 | - | ||
49 | - public Optional<ServerAddress> getServerAddress() { | ||
50 | - return Optional.ofNullable(serverAddress); | ||
51 | - } | ||
52 | - | ||
53 | - @Override | ||
54 | - public DeviceId getDeviceId() { | ||
55 | - return msg.getDeviceId(); | ||
56 | - } | ||
57 | - | ||
58 | - @Override | ||
59 | - public TenantId getTenantId() { | ||
60 | - return msg.getTenantId(); | ||
61 | - } | ||
62 | -} | ||
63 | - |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.api.rules; | 16 | package org.thingsboard.server.extensions.api.rules; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; | 19 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
20 | 20 | ||
21 | /** | 21 | /** |
@@ -23,6 +23,6 @@ import org.thingsboard.server.extensions.api.component.ConfigurableComponent; | @@ -23,6 +23,6 @@ import org.thingsboard.server.extensions.api.component.ConfigurableComponent; | ||
23 | */ | 23 | */ |
24 | public interface RuleFilter<T> extends ConfigurableComponent<T>, RuleLifecycleComponent { | 24 | public interface RuleFilter<T> extends ConfigurableComponent<T>, RuleLifecycleComponent { |
25 | 25 | ||
26 | - boolean filter(RuleContext ctx, ToDeviceActorMsg msg); | 26 | + boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg); |
27 | 27 | ||
28 | } | 28 | } |
@@ -15,15 +15,13 @@ | @@ -15,15 +15,13 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.api.rules; | 16 | package org.thingsboard.server.extensions.api.rules; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; | 19 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
20 | 20 | ||
21 | -import javax.script.ScriptException; | ||
22 | - | ||
23 | /** | 21 | /** |
24 | * @author Andrew Shvayka | 22 | * @author Andrew Shvayka |
25 | */ | 23 | */ |
26 | public interface RuleProcessor<T> extends ConfigurableComponent<T>, RuleLifecycleComponent { | 24 | public interface RuleProcessor<T> extends ConfigurableComponent<T>, RuleLifecycleComponent { |
27 | 25 | ||
28 | - RuleProcessingMetaData process(RuleContext ctx, ToDeviceActorMsg msg) throws RuleException; | 26 | + RuleProcessingMetaData process(RuleContext ctx, DeviceToDeviceActorMsg msg) throws RuleException; |
29 | } | 27 | } |
extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/mail/SendMailAction.java
@@ -20,7 +20,7 @@ import org.apache.velocity.Template; | @@ -20,7 +20,7 @@ import org.apache.velocity.Template; | ||
20 | import org.apache.velocity.VelocityContext; | 20 | import org.apache.velocity.VelocityContext; |
21 | import org.apache.velocity.runtime.parser.ParseException; | 21 | import org.apache.velocity.runtime.parser.ParseException; |
22 | import org.springframework.util.StringUtils; | 22 | import org.springframework.util.StringUtils; |
23 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 23 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
25 | import org.thingsboard.server.extensions.api.component.Action; | 25 | import org.thingsboard.server.extensions.api.component.Action; |
26 | import org.thingsboard.server.extensions.api.plugins.PluginAction; | 26 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
@@ -74,7 +74,7 @@ public class SendMailAction extends SimpleRuleLifecycleComponent implements Plug | @@ -74,7 +74,7 @@ public class SendMailAction extends SimpleRuleLifecycleComponent implements Plug | ||
74 | } | 74 | } |
75 | 75 | ||
76 | @Override | 76 | @Override |
77 | - public Optional<RuleToPluginMsg> convert(RuleContext ctx, ToDeviceActorMsg toDeviceActorMsg, RuleProcessingMetaData metadata) { | 77 | + public Optional<RuleToPluginMsg> convert(RuleContext ctx, DeviceToDeviceActorMsg deviceToDeviceActorMsg, RuleProcessingMetaData metadata) { |
78 | String sendFlag = configuration.getSendFlag(); | 78 | String sendFlag = configuration.getSendFlag(); |
79 | if (StringUtils.isEmpty(sendFlag) || (Boolean) metadata.get(sendFlag).orElse(Boolean.FALSE)) { | 79 | if (StringUtils.isEmpty(sendFlag) || (Boolean) metadata.get(sendFlag).orElse(Boolean.FALSE)) { |
80 | VelocityContext context = VelocityUtils.createContext(metadata); | 80 | VelocityContext context = VelocityUtils.createContext(metadata); |
@@ -86,7 +86,7 @@ public class SendMailAction extends SimpleRuleLifecycleComponent implements Plug | @@ -86,7 +86,7 @@ public class SendMailAction extends SimpleRuleLifecycleComponent implements Plug | ||
86 | bccTemplate.ifPresent(t -> builder.bcc(VelocityUtils.merge(t, context))); | 86 | bccTemplate.ifPresent(t -> builder.bcc(VelocityUtils.merge(t, context))); |
87 | subjectTemplate.ifPresent(t -> builder.subject(VelocityUtils.merge(t, context))); | 87 | subjectTemplate.ifPresent(t -> builder.subject(VelocityUtils.merge(t, context))); |
88 | bodyTemplate.ifPresent(t -> builder.body(VelocityUtils.merge(t, context))); | 88 | bodyTemplate.ifPresent(t -> builder.body(VelocityUtils.merge(t, context))); |
89 | - return Optional.of(new SendMailRuleToPluginActionMsg(toDeviceActorMsg.getTenantId(), toDeviceActorMsg.getCustomerId(), toDeviceActorMsg.getDeviceId(), | 89 | + return Optional.of(new SendMailRuleToPluginActionMsg(deviceToDeviceActorMsg.getTenantId(), deviceToDeviceActorMsg.getCustomerId(), deviceToDeviceActorMsg.getDeviceId(), |
90 | builder.build())); | 90 | builder.build())); |
91 | } else { | 91 | } else { |
92 | return Optional.empty(); | 92 | return Optional.empty(); |
extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/rpc/RpcPluginAction.java
@@ -16,9 +16,10 @@ | @@ -16,9 +16,10 @@ | ||
16 | package org.thingsboard.server.extensions.core.action.rpc; | 16 | package org.thingsboard.server.extensions.core.action.rpc; |
17 | 17 | ||
18 | import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; | 18 | import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; |
19 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 19 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
20 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 20 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
21 | -import org.thingsboard.server.common.msg.session.MsgType; | 21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
22 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 23 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
23 | import org.thingsboard.server.extensions.api.component.Action; | 24 | import org.thingsboard.server.extensions.api.component.Action; |
24 | import org.thingsboard.server.extensions.api.component.EmptyComponentConfiguration; | 25 | import org.thingsboard.server.extensions.api.component.EmptyComponentConfiguration; |
@@ -41,12 +42,12 @@ public class RpcPluginAction extends SimpleRuleLifecycleComponent implements Plu | @@ -41,12 +42,12 @@ public class RpcPluginAction extends SimpleRuleLifecycleComponent implements Plu | ||
41 | } | 42 | } |
42 | 43 | ||
43 | @Override | 44 | @Override |
44 | - public Optional<RuleToPluginMsg> convert(RuleContext ctx, ToDeviceActorMsg toDeviceActorMsg, RuleProcessingMetaData deviceMsgMd) { | ||
45 | - FromDeviceMsg msg = toDeviceActorMsg.getPayload(); | ||
46 | - if (msg.getMsgType() == MsgType.TO_SERVER_RPC_REQUEST) { | 45 | + public Optional<RuleToPluginMsg> convert(RuleContext ctx, DeviceToDeviceActorMsg deviceToDeviceActorMsg, RuleProcessingMetaData deviceMsgMd) { |
46 | + FromDeviceMsg msg = deviceToDeviceActorMsg.getPayload(); | ||
47 | + if (msg.getMsgType() == SessionMsgType.TO_SERVER_RPC_REQUEST) { | ||
47 | ToServerRpcRequestMsg payload = (ToServerRpcRequestMsg) msg; | 48 | ToServerRpcRequestMsg payload = (ToServerRpcRequestMsg) msg; |
48 | - return Optional.of(new RpcRequestRuleToPluginMsg(toDeviceActorMsg.getTenantId(), toDeviceActorMsg.getCustomerId(), | ||
49 | - toDeviceActorMsg.getDeviceId(), payload)); | 49 | + return Optional.of(new RpcRequestRuleToPluginMsg(deviceToDeviceActorMsg.getTenantId(), deviceToDeviceActorMsg.getCustomerId(), |
50 | + deviceToDeviceActorMsg.getDeviceId(), payload)); | ||
50 | } else { | 51 | } else { |
51 | return Optional.empty(); | 52 | return Optional.empty(); |
52 | } | 53 | } |
@@ -20,7 +20,7 @@ import org.apache.velocity.Template; | @@ -20,7 +20,7 @@ import org.apache.velocity.Template; | ||
20 | import org.apache.velocity.VelocityContext; | 20 | import org.apache.velocity.VelocityContext; |
21 | import org.apache.velocity.runtime.parser.ParseException; | 21 | import org.apache.velocity.runtime.parser.ParseException; |
22 | import org.springframework.util.StringUtils; | 22 | import org.springframework.util.StringUtils; |
23 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 23 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
25 | import org.thingsboard.server.extensions.api.component.Action; | 25 | import org.thingsboard.server.extensions.api.component.Action; |
26 | import org.thingsboard.server.extensions.api.plugins.PluginAction; | 26 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
@@ -64,7 +64,7 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem | @@ -64,7 +64,7 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem | ||
64 | } | 64 | } |
65 | 65 | ||
66 | @Override | 66 | @Override |
67 | - public Optional<RuleToPluginMsg> convert(RuleContext ctx, ToDeviceActorMsg toDeviceActorMsg, RuleProcessingMetaData metadata) { | 67 | + public Optional<RuleToPluginMsg> convert(RuleContext ctx, DeviceToDeviceActorMsg deviceToDeviceActorMsg, RuleProcessingMetaData metadata) { |
68 | String sendFlag = configuration.getSendFlag(); | 68 | String sendFlag = configuration.getSendFlag(); |
69 | if (StringUtils.isEmpty(sendFlag) || (Boolean) metadata.get(sendFlag).orElse(Boolean.FALSE)) { | 69 | if (StringUtils.isEmpty(sendFlag) || (Boolean) metadata.get(sendFlag).orElse(Boolean.FALSE)) { |
70 | VelocityContext context = VelocityUtils.createContext(metadata); | 70 | VelocityContext context = VelocityUtils.createContext(metadata); |
@@ -77,7 +77,7 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem | @@ -77,7 +77,7 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem | ||
77 | rpcCallMethodTemplate.ifPresent(t -> builder.rpcCallMethod(VelocityUtils.merge(t, context))); | 77 | rpcCallMethodTemplate.ifPresent(t -> builder.rpcCallMethod(VelocityUtils.merge(t, context))); |
78 | rpcCallBodyTemplate.ifPresent(t -> builder.rpcCallBody(VelocityUtils.merge(t, context))); | 78 | rpcCallBodyTemplate.ifPresent(t -> builder.rpcCallBody(VelocityUtils.merge(t, context))); |
79 | builder.rpcCallTimeoutInSec(configuration.getRpcCallTimeoutInSec()); | 79 | builder.rpcCallTimeoutInSec(configuration.getRpcCallTimeoutInSec()); |
80 | - return Optional.of(new ServerSideRpcCallRuleToPluginActionMsg(toDeviceActorMsg.getTenantId(), toDeviceActorMsg.getCustomerId(), toDeviceActorMsg.getDeviceId(), | 80 | + return Optional.of(new ServerSideRpcCallRuleToPluginActionMsg(deviceToDeviceActorMsg.getTenantId(), deviceToDeviceActorMsg.getCustomerId(), deviceToDeviceActorMsg.getDeviceId(), |
81 | builder.build())); | 81 | builder.build())); |
82 | } else { | 82 | } else { |
83 | return Optional.empty(); | 83 | return Optional.empty(); |
@@ -19,9 +19,10 @@ import org.springframework.util.StringUtils; | @@ -19,9 +19,10 @@ import org.springframework.util.StringUtils; | ||
19 | import org.thingsboard.server.common.msg.core.GetAttributesRequest; | 19 | import org.thingsboard.server.common.msg.core.GetAttributesRequest; |
20 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | 20 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
21 | import org.thingsboard.server.common.msg.core.UpdateAttributesRequest; | 21 | import org.thingsboard.server.common.msg.core.UpdateAttributesRequest; |
22 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 22 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
23 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 23 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
24 | -import org.thingsboard.server.common.msg.session.MsgType; | 24 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
25 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
25 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 26 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
26 | import org.thingsboard.server.extensions.api.component.Action; | 27 | import org.thingsboard.server.extensions.api.component.Action; |
27 | import org.thingsboard.server.extensions.api.plugins.PluginAction; | 28 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
@@ -50,20 +51,20 @@ public class TelemetryPluginAction extends SimpleRuleLifecycleComponent implemen | @@ -50,20 +51,20 @@ public class TelemetryPluginAction extends SimpleRuleLifecycleComponent implemen | ||
50 | } | 51 | } |
51 | 52 | ||
52 | @Override | 53 | @Override |
53 | - public Optional<RuleToPluginMsg> convert(RuleContext ctx, ToDeviceActorMsg toDeviceActorMsg, RuleProcessingMetaData deviceMsgMd) { | ||
54 | - FromDeviceMsg msg = toDeviceActorMsg.getPayload(); | ||
55 | - if (msg.getMsgType() == MsgType.POST_TELEMETRY_REQUEST) { | 54 | + public Optional<RuleToPluginMsg> convert(RuleContext ctx, DeviceToDeviceActorMsg deviceToDeviceActorMsg, RuleProcessingMetaData deviceMsgMd) { |
55 | + FromDeviceMsg msg = deviceToDeviceActorMsg.getPayload(); | ||
56 | + if (msg.getMsgType() == SessionMsgType.POST_TELEMETRY_REQUEST) { | ||
56 | TelemetryUploadRequest payload = (TelemetryUploadRequest) msg; | 57 | TelemetryUploadRequest payload = (TelemetryUploadRequest) msg; |
57 | - return Optional.of(new TelemetryUploadRequestRuleToPluginMsg(toDeviceActorMsg.getTenantId(), toDeviceActorMsg.getCustomerId(), | ||
58 | - toDeviceActorMsg.getDeviceId(), payload, ttl)); | ||
59 | - } else if (msg.getMsgType() == MsgType.POST_ATTRIBUTES_REQUEST) { | 58 | + return Optional.of(new TelemetryUploadRequestRuleToPluginMsg(deviceToDeviceActorMsg.getTenantId(), deviceToDeviceActorMsg.getCustomerId(), |
59 | + deviceToDeviceActorMsg.getDeviceId(), payload, ttl)); | ||
60 | + } else if (msg.getMsgType() == SessionMsgType.POST_ATTRIBUTES_REQUEST) { | ||
60 | UpdateAttributesRequest payload = (UpdateAttributesRequest) msg; | 61 | UpdateAttributesRequest payload = (UpdateAttributesRequest) msg; |
61 | - return Optional.of(new UpdateAttributesRequestRuleToPluginMsg(toDeviceActorMsg.getTenantId(), toDeviceActorMsg.getCustomerId(), | ||
62 | - toDeviceActorMsg.getDeviceId(), payload)); | ||
63 | - } else if (msg.getMsgType() == MsgType.GET_ATTRIBUTES_REQUEST) { | 62 | + return Optional.of(new UpdateAttributesRequestRuleToPluginMsg(deviceToDeviceActorMsg.getTenantId(), deviceToDeviceActorMsg.getCustomerId(), |
63 | + deviceToDeviceActorMsg.getDeviceId(), payload)); | ||
64 | + } else if (msg.getMsgType() == SessionMsgType.GET_ATTRIBUTES_REQUEST) { | ||
64 | GetAttributesRequest payload = (GetAttributesRequest) msg; | 65 | GetAttributesRequest payload = (GetAttributesRequest) msg; |
65 | - return Optional.of(new GetAttributesRequestRuleToPluginMsg(toDeviceActorMsg.getTenantId(), toDeviceActorMsg.getCustomerId(), | ||
66 | - toDeviceActorMsg.getDeviceId(), payload)); | 66 | + return Optional.of(new GetAttributesRequestRuleToPluginMsg(deviceToDeviceActorMsg.getTenantId(), deviceToDeviceActorMsg.getCustomerId(), |
67 | + deviceToDeviceActorMsg.getDeviceId(), payload)); | ||
67 | } else { | 68 | } else { |
68 | return Optional.empty(); | 69 | return Optional.empty(); |
69 | } | 70 | } |
@@ -19,7 +19,7 @@ import lombok.extern.slf4j.Slf4j; | @@ -19,7 +19,7 @@ import lombok.extern.slf4j.Slf4j; | ||
19 | import org.apache.velocity.Template; | 19 | import org.apache.velocity.Template; |
20 | import org.apache.velocity.VelocityContext; | 20 | import org.apache.velocity.VelocityContext; |
21 | import org.apache.velocity.runtime.parser.ParseException; | 21 | import org.apache.velocity.runtime.parser.ParseException; |
22 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 22 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
23 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 23 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
25 | import org.thingsboard.server.extensions.api.plugins.PluginAction; | 25 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
@@ -52,7 +52,7 @@ public abstract class AbstractTemplatePluginAction<T extends TemplateActionConfi | @@ -52,7 +52,7 @@ public abstract class AbstractTemplatePluginAction<T extends TemplateActionConfi | ||
52 | } | 52 | } |
53 | 53 | ||
54 | @Override | 54 | @Override |
55 | - public Optional<RuleToPluginMsg> convert(RuleContext ctx, ToDeviceActorMsg msg, RuleProcessingMetaData deviceMsgMd) { | 55 | + public Optional<RuleToPluginMsg> convert(RuleContext ctx, DeviceToDeviceActorMsg msg, RuleProcessingMetaData deviceMsgMd) { |
56 | FromDeviceRequestMsg payload; | 56 | FromDeviceRequestMsg payload; |
57 | if (msg.getPayload() instanceof FromDeviceRequestMsg) { | 57 | if (msg.getPayload() instanceof FromDeviceRequestMsg) { |
58 | payload = (FromDeviceRequestMsg) msg.getPayload(); | 58 | payload = (FromDeviceRequestMsg) msg.getPayload(); |
@@ -70,14 +70,14 @@ public abstract class AbstractTemplatePluginAction<T extends TemplateActionConfi | @@ -70,14 +70,14 @@ public abstract class AbstractTemplatePluginAction<T extends TemplateActionConfi | ||
70 | return Optional.empty(); | 70 | return Optional.empty(); |
71 | } | 71 | } |
72 | 72 | ||
73 | - protected String getMsgBody(RuleContext ctx, ToDeviceActorMsg msg) { | 73 | + protected String getMsgBody(RuleContext ctx, DeviceToDeviceActorMsg msg) { |
74 | log.trace("Creating context for: {} and payload {}", ctx.getDeviceMetaData(), msg.getPayload()); | 74 | log.trace("Creating context for: {} and payload {}", ctx.getDeviceMetaData(), msg.getPayload()); |
75 | VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg.getPayload()); | 75 | VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg.getPayload()); |
76 | return VelocityUtils.merge(template, context); | 76 | return VelocityUtils.merge(template, context); |
77 | } | 77 | } |
78 | 78 | ||
79 | abstract protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, | 79 | abstract protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, |
80 | - ToDeviceActorMsg msg, | 80 | + DeviceToDeviceActorMsg msg, |
81 | FromDeviceRequestMsg payload); | 81 | FromDeviceRequestMsg payload); |
82 | 82 | ||
83 | @Override | 83 | @Override |
@@ -16,8 +16,7 @@ | @@ -16,8 +16,7 @@ | ||
16 | package org.thingsboard.server.extensions.core.filter; | 16 | package org.thingsboard.server.extensions.core.filter; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | -import org.thingsboard.server.common.data.kv.KvEntry; | ||
20 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 19 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
21 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 20 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
22 | import org.thingsboard.server.extensions.api.rules.RuleFilter; | 21 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
23 | 22 | ||
@@ -39,7 +38,7 @@ public abstract class BasicJsFilter implements RuleFilter<JsFilterConfiguration> | @@ -39,7 +38,7 @@ public abstract class BasicJsFilter implements RuleFilter<JsFilterConfiguration> | ||
39 | } | 38 | } |
40 | 39 | ||
41 | @Override | 40 | @Override |
42 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | 41 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { |
43 | try { | 42 | try { |
44 | return doFilter(ctx, msg); | 43 | return doFilter(ctx, msg); |
45 | } catch (ScriptException e) { | 44 | } catch (ScriptException e) { |
@@ -48,7 +47,7 @@ public abstract class BasicJsFilter implements RuleFilter<JsFilterConfiguration> | @@ -48,7 +47,7 @@ public abstract class BasicJsFilter implements RuleFilter<JsFilterConfiguration> | ||
48 | } | 47 | } |
49 | } | 48 | } |
50 | 49 | ||
51 | - protected abstract boolean doFilter(RuleContext ctx, ToDeviceActorMsg msg) throws ScriptException; | 50 | + protected abstract boolean doFilter(RuleContext ctx, DeviceToDeviceActorMsg msg) throws ScriptException; |
52 | 51 | ||
53 | @Override | 52 | @Override |
54 | public void resume() { | 53 | public void resume() { |
@@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.core.filter; | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.core.filter; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.thingsboard.server.common.msg.core.UpdateAttributesRequest; | 19 | import org.thingsboard.server.common.msg.core.UpdateAttributesRequest; |
20 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 20 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
21 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 21 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
22 | import org.thingsboard.server.extensions.api.component.Filter; | 22 | import org.thingsboard.server.extensions.api.component.Filter; |
23 | import org.thingsboard.server.extensions.api.device.DeviceAttributes; | 23 | import org.thingsboard.server.extensions.api.device.DeviceAttributes; |
@@ -34,7 +34,7 @@ import javax.script.ScriptException; | @@ -34,7 +34,7 @@ import javax.script.ScriptException; | ||
34 | public class DeviceAttributesFilter extends BasicJsFilter { | 34 | public class DeviceAttributesFilter extends BasicJsFilter { |
35 | 35 | ||
36 | @Override | 36 | @Override |
37 | - protected boolean doFilter(RuleContext ctx, ToDeviceActorMsg msg) throws ScriptException { | 37 | + protected boolean doFilter(RuleContext ctx, DeviceToDeviceActorMsg msg) throws ScriptException { |
38 | return evaluator.execute(toBindings(ctx.getDeviceMetaData().getDeviceAttributes(), msg != null ? msg.getPayload() : null)); | 38 | return evaluator.execute(toBindings(ctx.getDeviceMetaData().getDeviceAttributes(), msg != null ? msg.getPayload() : null)); |
39 | } | 39 | } |
40 | 40 |
@@ -18,7 +18,7 @@ package org.thingsboard.server.extensions.core.filter; | @@ -18,7 +18,7 @@ package org.thingsboard.server.extensions.core.filter; | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.thingsboard.server.common.data.kv.KvEntry; | 19 | import org.thingsboard.server.common.data.kv.KvEntry; |
20 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | 20 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
21 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 21 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
22 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 22 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
23 | import org.thingsboard.server.extensions.api.component.Filter; | 23 | import org.thingsboard.server.extensions.api.component.Filter; |
24 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 24 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
@@ -34,7 +34,7 @@ import java.util.List; | @@ -34,7 +34,7 @@ import java.util.List; | ||
34 | public class DeviceTelemetryFilter extends BasicJsFilter { | 34 | public class DeviceTelemetryFilter extends BasicJsFilter { |
35 | 35 | ||
36 | @Override | 36 | @Override |
37 | - protected boolean doFilter(RuleContext ctx, ToDeviceActorMsg msg) throws ScriptException { | 37 | + protected boolean doFilter(RuleContext ctx, DeviceToDeviceActorMsg msg) throws ScriptException { |
38 | FromDeviceMsg deviceMsg = msg.getPayload(); | 38 | FromDeviceMsg deviceMsg = msg.getPayload(); |
39 | if (deviceMsg instanceof TelemetryUploadRequest) { | 39 | if (deviceMsg instanceof TelemetryUploadRequest) { |
40 | TelemetryUploadRequest telemetryMsg = (TelemetryUploadRequest) deviceMsg; | 40 | TelemetryUploadRequest telemetryMsg = (TelemetryUploadRequest) deviceMsg; |
@@ -16,8 +16,7 @@ | @@ -16,8 +16,7 @@ | ||
16 | package org.thingsboard.server.extensions.core.filter; | 16 | package org.thingsboard.server.extensions.core.filter; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | -import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; | ||
20 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 19 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
21 | import org.thingsboard.server.extensions.api.component.Filter; | 20 | import org.thingsboard.server.extensions.api.component.Filter; |
22 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 21 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | import org.thingsboard.server.extensions.api.rules.RuleFilter; | 22 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
@@ -27,8 +26,6 @@ import java.util.Arrays; | @@ -27,8 +26,6 @@ import java.util.Arrays; | ||
27 | import java.util.Set; | 26 | import java.util.Set; |
28 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
29 | 28 | ||
30 | -import static org.thingsboard.server.common.msg.session.MsgType.TO_SERVER_RPC_REQUEST; | ||
31 | - | ||
32 | /** | 29 | /** |
33 | * @author Andrew Shvayka | 30 | * @author Andrew Shvayka |
34 | */ | 31 | */ |
@@ -46,7 +43,7 @@ public class DeviceTypeFilter extends SimpleRuleLifecycleComponent implements Ru | @@ -46,7 +43,7 @@ public class DeviceTypeFilter extends SimpleRuleLifecycleComponent implements Ru | ||
46 | } | 43 | } |
47 | 44 | ||
48 | @Override | 45 | @Override |
49 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | 46 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { |
50 | return deviceTypes.contains(ctx.getDeviceMetaData().getDeviceType()); | 47 | return deviceTypes.contains(ctx.getDeviceMetaData().getDeviceType()); |
51 | } | 48 | } |
52 | } | 49 | } |
@@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.core.filter; | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.core.filter; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; | 19 | import org.thingsboard.server.common.msg.core.ToServerRpcRequestMsg; |
20 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 20 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
21 | import org.thingsboard.server.extensions.api.component.Filter; | 21 | import org.thingsboard.server.extensions.api.component.Filter; |
22 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 22 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | import org.thingsboard.server.extensions.api.rules.RuleFilter; | 23 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
@@ -27,7 +27,7 @@ import java.util.Arrays; | @@ -27,7 +27,7 @@ import java.util.Arrays; | ||
27 | import java.util.Set; | 27 | import java.util.Set; |
28 | import java.util.stream.Collectors; | 28 | import java.util.stream.Collectors; |
29 | 29 | ||
30 | -import static org.thingsboard.server.common.msg.session.MsgType.TO_SERVER_RPC_REQUEST; | 30 | +import static org.thingsboard.server.common.msg.session.SessionMsgType.TO_SERVER_RPC_REQUEST; |
31 | 31 | ||
32 | /** | 32 | /** |
33 | * @author Andrew Shvayka | 33 | * @author Andrew Shvayka |
@@ -46,7 +46,7 @@ public class MethodNameFilter extends SimpleRuleLifecycleComponent implements Ru | @@ -46,7 +46,7 @@ public class MethodNameFilter extends SimpleRuleLifecycleComponent implements Ru | ||
46 | } | 46 | } |
47 | 47 | ||
48 | @Override | 48 | @Override |
49 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | 49 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { |
50 | if (msg.getPayload().getMsgType() == TO_SERVER_RPC_REQUEST) { | 50 | if (msg.getPayload().getMsgType() == TO_SERVER_RPC_REQUEST) { |
51 | return methods.contains(((ToServerRpcRequestMsg) msg.getPayload()).getMethod()); | 51 | return methods.contains(((ToServerRpcRequestMsg) msg.getPayload()).getMethod()); |
52 | } else { | 52 | } else { |
@@ -16,8 +16,9 @@ | @@ -16,8 +16,9 @@ | ||
16 | package org.thingsboard.server.extensions.core.filter; | 16 | package org.thingsboard.server.extensions.core.filter; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | ||
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 19 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | import org.thingsboard.server.extensions.api.component.Filter; | 22 | import org.thingsboard.server.extensions.api.component.Filter; |
22 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 23 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | import org.thingsboard.server.extensions.api.rules.RuleFilter; | 24 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
@@ -35,30 +36,30 @@ import java.util.stream.Collectors; | @@ -35,30 +36,30 @@ import java.util.stream.Collectors; | ||
35 | @Slf4j | 36 | @Slf4j |
36 | public class MsgTypeFilter extends SimpleRuleLifecycleComponent implements RuleFilter<MsgTypeFilterConfiguration> { | 37 | public class MsgTypeFilter extends SimpleRuleLifecycleComponent implements RuleFilter<MsgTypeFilterConfiguration> { |
37 | 38 | ||
38 | - private List<MsgType> msgTypes; | 39 | + private List<SessionMsgType> sessionMsgTypes; |
39 | 40 | ||
40 | @Override | 41 | @Override |
41 | public void init(MsgTypeFilterConfiguration configuration) { | 42 | public void init(MsgTypeFilterConfiguration configuration) { |
42 | - msgTypes = Arrays.stream(configuration.getMessageTypes()).map(type -> { | 43 | + sessionMsgTypes = Arrays.stream(configuration.getMessageTypes()).map(type -> { |
43 | switch (type) { | 44 | switch (type) { |
44 | case "GET_ATTRIBUTES": | 45 | case "GET_ATTRIBUTES": |
45 | - return MsgType.GET_ATTRIBUTES_REQUEST; | 46 | + return SessionMsgType.GET_ATTRIBUTES_REQUEST; |
46 | case "POST_ATTRIBUTES": | 47 | case "POST_ATTRIBUTES": |
47 | - return MsgType.POST_ATTRIBUTES_REQUEST; | 48 | + return SessionMsgType.POST_ATTRIBUTES_REQUEST; |
48 | case "POST_TELEMETRY": | 49 | case "POST_TELEMETRY": |
49 | - return MsgType.POST_TELEMETRY_REQUEST; | 50 | + return SessionMsgType.POST_TELEMETRY_REQUEST; |
50 | case "RPC_REQUEST": | 51 | case "RPC_REQUEST": |
51 | - return MsgType.TO_SERVER_RPC_REQUEST; | 52 | + return SessionMsgType.TO_SERVER_RPC_REQUEST; |
52 | default: | 53 | default: |
53 | - throw new InvalidParameterException("Can't map " + type + " to " + MsgType.class.getName() + "!"); | 54 | + throw new InvalidParameterException("Can't map " + type + " to " + SessionMsgType.class.getName() + "!"); |
54 | } | 55 | } |
55 | }).collect(Collectors.toList()); | 56 | }).collect(Collectors.toList()); |
56 | } | 57 | } |
57 | 58 | ||
58 | @Override | 59 | @Override |
59 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | ||
60 | - for (MsgType msgType : msgTypes) { | ||
61 | - if (msgType == msg.getPayload().getMsgType()) { | 60 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { |
61 | + for (SessionMsgType sessionMsgType : sessionMsgTypes) { | ||
62 | + if (sessionMsgType == msg.getPayload().getMsgType()) { | ||
62 | return true; | 63 | return true; |
63 | } | 64 | } |
64 | } | 65 | } |
@@ -22,7 +22,7 @@ import org.apache.velocity.VelocityContext; | @@ -22,7 +22,7 @@ import org.apache.velocity.VelocityContext; | ||
22 | import org.apache.velocity.runtime.parser.ParseException; | 22 | import org.apache.velocity.runtime.parser.ParseException; |
23 | import org.thingsboard.server.common.data.DataConstants; | 23 | import org.thingsboard.server.common.data.DataConstants; |
24 | import org.thingsboard.server.common.data.Event; | 24 | import org.thingsboard.server.common.data.Event; |
25 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 25 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
26 | import org.thingsboard.server.extensions.api.component.Processor; | 26 | import org.thingsboard.server.extensions.api.component.Processor; |
27 | import org.thingsboard.server.extensions.api.rules.*; | 27 | import org.thingsboard.server.extensions.api.rules.*; |
28 | import org.thingsboard.server.extensions.core.utils.VelocityUtils; | 28 | import org.thingsboard.server.extensions.core.utils.VelocityUtils; |
@@ -57,7 +57,7 @@ public class AlarmDeduplicationProcessor extends SimpleRuleLifecycleComponent | @@ -57,7 +57,7 @@ public class AlarmDeduplicationProcessor extends SimpleRuleLifecycleComponent | ||
57 | } | 57 | } |
58 | 58 | ||
59 | @Override | 59 | @Override |
60 | - public RuleProcessingMetaData process(RuleContext ctx, ToDeviceActorMsg msg) throws RuleException { | 60 | + public RuleProcessingMetaData process(RuleContext ctx, DeviceToDeviceActorMsg msg) throws RuleException { |
61 | RuleProcessingMetaData md = new RuleProcessingMetaData(); | 61 | RuleProcessingMetaData md = new RuleProcessingMetaData(); |
62 | VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg.getPayload()); | 62 | VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg.getPayload()); |
63 | String alarmId = VelocityUtils.merge(alarmIdTemplate, context); | 63 | String alarmId = VelocityUtils.merge(alarmIdTemplate, context); |
@@ -27,7 +27,7 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus; | @@ -27,7 +27,7 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus; | ||
27 | import org.thingsboard.server.common.data.kv.KvEntry; | 27 | import org.thingsboard.server.common.data.kv.KvEntry; |
28 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | 28 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
29 | import org.thingsboard.server.common.msg.core.UpdateAttributesRequest; | 29 | import org.thingsboard.server.common.msg.core.UpdateAttributesRequest; |
30 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 30 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
31 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 31 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
32 | import org.thingsboard.server.extensions.api.component.Processor; | 32 | import org.thingsboard.server.extensions.api.component.Processor; |
33 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 33 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
@@ -102,7 +102,7 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration | @@ -102,7 +102,7 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration | ||
102 | } | 102 | } |
103 | 103 | ||
104 | @Override | 104 | @Override |
105 | - public RuleProcessingMetaData process(RuleContext ctx, ToDeviceActorMsg wrapper) throws RuleException { | 105 | + public RuleProcessingMetaData process(RuleContext ctx, DeviceToDeviceActorMsg wrapper) throws RuleException { |
106 | RuleProcessingMetaData md = new RuleProcessingMetaData(); | 106 | RuleProcessingMetaData md = new RuleProcessingMetaData(); |
107 | 107 | ||
108 | FromDeviceMsg msg = wrapper.getPayload(); | 108 | FromDeviceMsg msg = wrapper.getPayload(); |
@@ -17,7 +17,8 @@ package org.thingsboard.server.extensions.kafka.action; | @@ -17,7 +17,8 @@ package org.thingsboard.server.extensions.kafka.action; | ||
17 | 17 | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | 22 | ||
22 | import java.io.Serializable; | 23 | import java.io.Serializable; |
23 | 24 | ||
@@ -30,5 +31,5 @@ public class KafkaActionPayload implements Serializable { | @@ -30,5 +31,5 @@ public class KafkaActionPayload implements Serializable { | ||
30 | private final boolean sync; | 31 | private final boolean sync; |
31 | 32 | ||
32 | private final Integer requestId; | 33 | private final Integer requestId; |
33 | - private final MsgType msgType; | 34 | + private final SessionMsgType sessionMsgType; |
34 | } | 35 | } |
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | package org.thingsboard.server.extensions.kafka.action; | 16 | package org.thingsboard.server.extensions.kafka.action; |
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 19 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
20 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 20 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
21 | import org.thingsboard.server.extensions.api.component.Action; | 21 | import org.thingsboard.server.extensions.api.component.Action; |
22 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 22 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -30,7 +30,7 @@ import java.util.Optional; | @@ -30,7 +30,7 @@ import java.util.Optional; | ||
30 | public class KafkaPluginAction extends AbstractTemplatePluginAction<KafkaPluginActionConfiguration> { | 30 | public class KafkaPluginAction extends AbstractTemplatePluginAction<KafkaPluginActionConfiguration> { |
31 | 31 | ||
32 | @Override | 32 | @Override |
33 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 33 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
34 | KafkaActionPayload.KafkaActionPayloadBuilder builder = KafkaActionPayload.builder(); | 34 | KafkaActionPayload.KafkaActionPayloadBuilder builder = KafkaActionPayload.builder(); |
35 | builder.msgType(payload.getMsgType()); | 35 | builder.msgType(payload.getMsgType()); |
36 | builder.requestId(payload.getRequestId()); | 36 | builder.requestId(payload.getRequestId()); |
@@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.mqtt.action; | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.mqtt.action; | ||
17 | 17 | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | 21 | ||
22 | import java.io.Serializable; | 22 | import java.io.Serializable; |
23 | 23 | ||
@@ -30,5 +30,5 @@ public class MqttActionPayload implements Serializable { | @@ -30,5 +30,5 @@ public class MqttActionPayload implements Serializable { | ||
30 | private final String msgBody; | 30 | private final String msgBody; |
31 | 31 | ||
32 | private final Integer requestId; | 32 | private final Integer requestId; |
33 | - private final MsgType msgType; | 33 | + private final SessionMsgType sessionMsgType; |
34 | } | 34 | } |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.mqtt.action; | 16 | package org.thingsboard.server.extensions.mqtt.action; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | import org.thingsboard.server.extensions.api.component.Action; | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -28,7 +28,7 @@ import java.util.Optional; | @@ -28,7 +28,7 @@ import java.util.Optional; | ||
28 | public class MqttPluginAction extends AbstractTemplatePluginAction<MqttPluginActionConfiguration> { | 28 | public class MqttPluginAction extends AbstractTemplatePluginAction<MqttPluginActionConfiguration> { |
29 | 29 | ||
30 | @Override | 30 | @Override |
31 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 31 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
32 | MqttActionPayload.MqttActionPayloadBuilder builder = MqttActionPayload.builder(); | 32 | MqttActionPayload.MqttActionPayloadBuilder builder = MqttActionPayload.builder(); |
33 | builder.sync(configuration.isSync()); | 33 | builder.sync(configuration.isSync()); |
34 | builder.msgType(payload.getMsgType()); | 34 | builder.msgType(payload.getMsgType()); |
@@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.rabbitmq.action; | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.rabbitmq.action; | ||
17 | 17 | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | 21 | ||
22 | import java.io.Serializable; | 22 | import java.io.Serializable; |
23 | 23 | ||
@@ -35,5 +35,5 @@ public class RabbitMqActionPayload implements Serializable { | @@ -35,5 +35,5 @@ public class RabbitMqActionPayload implements Serializable { | ||
35 | 35 | ||
36 | private final boolean sync; | 36 | private final boolean sync; |
37 | private final Integer requestId; | 37 | private final Integer requestId; |
38 | - private final MsgType msgType; | 38 | + private final SessionMsgType sessionMsgType; |
39 | } | 39 | } |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.rabbitmq.action; | 16 | package org.thingsboard.server.extensions.rabbitmq.action; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | import org.thingsboard.server.extensions.api.component.Action; | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -32,7 +32,7 @@ import java.util.Optional; | @@ -32,7 +32,7 @@ import java.util.Optional; | ||
32 | public class RabbitMqPluginAction extends AbstractTemplatePluginAction<RabbitMqPluginActionConfiguration> { | 32 | public class RabbitMqPluginAction extends AbstractTemplatePluginAction<RabbitMqPluginActionConfiguration> { |
33 | 33 | ||
34 | @Override | 34 | @Override |
35 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 35 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
36 | RabbitMqActionPayload.RabbitMqActionPayloadBuilder builder = RabbitMqActionPayload.builder(); | 36 | RabbitMqActionPayload.RabbitMqActionPayloadBuilder builder = RabbitMqActionPayload.builder(); |
37 | builder.sync(configuration.isSync()); | 37 | builder.sync(configuration.isSync()); |
38 | builder.exchange(configuration.getExchange()); | 38 | builder.exchange(configuration.getExchange()); |
@@ -19,7 +19,8 @@ import lombok.Builder; | @@ -19,7 +19,8 @@ import lombok.Builder; | ||
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | import org.springframework.http.HttpMethod; | 20 | import org.springframework.http.HttpMethod; |
21 | import org.springframework.http.HttpStatus; | 21 | import org.springframework.http.HttpStatus; |
22 | -import org.thingsboard.server.common.msg.session.MsgType; | 22 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
23 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
23 | 24 | ||
24 | import java.io.Serializable; | 25 | import java.io.Serializable; |
25 | 26 | ||
@@ -33,5 +34,5 @@ public class RestApiCallActionPayload implements Serializable { | @@ -33,5 +34,5 @@ public class RestApiCallActionPayload implements Serializable { | ||
33 | private final boolean sync; | 34 | private final boolean sync; |
34 | 35 | ||
35 | private final Integer requestId; | 36 | private final Integer requestId; |
36 | - private final MsgType msgType; | 37 | + private final SessionMsgType sessionMsgType; |
37 | } | 38 | } |
@@ -18,7 +18,7 @@ package org.thingsboard.server.extensions.rest.action; | @@ -18,7 +18,7 @@ package org.thingsboard.server.extensions.rest.action; | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.springframework.http.HttpMethod; | 19 | import org.springframework.http.HttpMethod; |
20 | import org.springframework.http.HttpStatus; | 20 | import org.springframework.http.HttpStatus; |
21 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 21 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
22 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 22 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
23 | import org.thingsboard.server.extensions.api.component.Action; | 23 | import org.thingsboard.server.extensions.api.component.Action; |
24 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 24 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -33,7 +33,7 @@ import java.util.Optional; | @@ -33,7 +33,7 @@ import java.util.Optional; | ||
33 | public class RestApiCallPluginAction extends AbstractTemplatePluginAction<RestApiCallPluginActionConfiguration> { | 33 | public class RestApiCallPluginAction extends AbstractTemplatePluginAction<RestApiCallPluginActionConfiguration> { |
34 | 34 | ||
35 | @Override | 35 | @Override |
36 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 36 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
37 | RestApiCallActionPayload.RestApiCallActionPayloadBuilder builder = RestApiCallActionPayload.builder(); | 37 | RestApiCallActionPayload.RestApiCallActionPayloadBuilder builder = RestApiCallActionPayload.builder(); |
38 | builder.msgType(payload.getMsgType()); | 38 | builder.msgType(payload.getMsgType()); |
39 | builder.requestId(payload.getRequestId()); | 39 | builder.requestId(payload.getRequestId()); |
@@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.sns.action; | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.sns.action; | ||
17 | 17 | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | 21 | ||
22 | import java.io.Serializable; | 22 | import java.io.Serializable; |
23 | 23 | ||
@@ -32,6 +32,6 @@ public class SnsTopicActionPayload implements Serializable { | @@ -32,6 +32,6 @@ public class SnsTopicActionPayload implements Serializable { | ||
32 | private final String msgBody; | 32 | private final String msgBody; |
33 | 33 | ||
34 | private final Integer requestId; | 34 | private final Integer requestId; |
35 | - private final MsgType msgType; | 35 | + private final SessionMsgType sessionMsgType; |
36 | private final boolean sync; | 36 | private final boolean sync; |
37 | } | 37 | } |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.sns.action; | 16 | package org.thingsboard.server.extensions.sns.action; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | import org.thingsboard.server.extensions.api.component.Action; | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -31,7 +31,7 @@ import java.util.Optional; | @@ -31,7 +31,7 @@ import java.util.Optional; | ||
31 | public class SnsTopicPluginAction extends AbstractTemplatePluginAction<SnsTopicPluginActionConfiguration> { | 31 | public class SnsTopicPluginAction extends AbstractTemplatePluginAction<SnsTopicPluginActionConfiguration> { |
32 | 32 | ||
33 | @Override | 33 | @Override |
34 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 34 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
35 | SnsTopicActionPayload.SnsTopicActionPayloadBuilder builder = SnsTopicActionPayload.builder(); | 35 | SnsTopicActionPayload.SnsTopicActionPayloadBuilder builder = SnsTopicActionPayload.builder(); |
36 | builder.msgType(payload.getMsgType()); | 36 | builder.msgType(payload.getMsgType()); |
37 | builder.requestId(payload.getRequestId()); | 37 | builder.requestId(payload.getRequestId()); |
@@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.sqs.action.fifo; | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.sqs.action.fifo; | ||
17 | 17 | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | 21 | ||
22 | import java.io.Serializable; | 22 | import java.io.Serializable; |
23 | 23 | ||
@@ -33,7 +33,7 @@ public class SqsFifoQueueActionPayload implements Serializable { | @@ -33,7 +33,7 @@ public class SqsFifoQueueActionPayload implements Serializable { | ||
33 | private final String deviceId; | 33 | private final String deviceId; |
34 | 34 | ||
35 | private final Integer requestId; | 35 | private final Integer requestId; |
36 | - private final MsgType msgType; | 36 | + private final SessionMsgType sessionMsgType; |
37 | private final boolean sync; | 37 | private final boolean sync; |
38 | 38 | ||
39 | } | 39 | } |
@@ -15,15 +15,12 @@ | @@ -15,15 +15,12 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.sqs.action.fifo; | 16 | package org.thingsboard.server.extensions.sqs.action.fifo; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | import org.thingsboard.server.extensions.api.component.Action; | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
22 | import org.thingsboard.server.extensions.api.rules.RuleContext; | 22 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | import org.thingsboard.server.extensions.core.action.template.AbstractTemplatePluginAction; | 23 | import org.thingsboard.server.extensions.core.action.template.AbstractTemplatePluginAction; |
24 | -import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueueActionMsg; | ||
25 | -import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueueActionPayload; | ||
26 | -import org.thingsboard.server.extensions.sqs.action.standard.SqsStandardQueuePluginActionConfiguration; | ||
27 | 24 | ||
28 | import java.util.Optional; | 25 | import java.util.Optional; |
29 | 26 | ||
@@ -34,7 +31,7 @@ import java.util.Optional; | @@ -34,7 +31,7 @@ import java.util.Optional; | ||
34 | public class SqsFifoQueuePluginAction extends AbstractTemplatePluginAction<SqsFifoQueuePluginActionConfiguration> { | 31 | public class SqsFifoQueuePluginAction extends AbstractTemplatePluginAction<SqsFifoQueuePluginActionConfiguration> { |
35 | 32 | ||
36 | @Override | 33 | @Override |
37 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 34 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
38 | SqsFifoQueueActionPayload.SqsFifoQueueActionPayloadBuilder builder = SqsFifoQueueActionPayload.builder(); | 35 | SqsFifoQueueActionPayload.SqsFifoQueueActionPayloadBuilder builder = SqsFifoQueueActionPayload.builder(); |
39 | builder.msgType(payload.getMsgType()); | 36 | builder.msgType(payload.getMsgType()); |
40 | builder.requestId(payload.getRequestId()); | 37 | builder.requestId(payload.getRequestId()); |
@@ -17,7 +17,8 @@ package org.thingsboard.server.extensions.sqs.action.standard; | @@ -17,7 +17,8 @@ package org.thingsboard.server.extensions.sqs.action.standard; | ||
17 | 17 | ||
18 | import lombok.Builder; | 18 | import lombok.Builder; |
19 | import lombok.Data; | 19 | import lombok.Data; |
20 | -import org.thingsboard.server.common.msg.session.MsgType; | 20 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
21 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
21 | 22 | ||
22 | import java.io.Serializable; | 23 | import java.io.Serializable; |
23 | 24 | ||
@@ -33,7 +34,7 @@ public class SqsStandardQueueActionPayload implements Serializable { | @@ -33,7 +34,7 @@ public class SqsStandardQueueActionPayload implements Serializable { | ||
33 | private final int delaySeconds; | 34 | private final int delaySeconds; |
34 | 35 | ||
35 | private final Integer requestId; | 36 | private final Integer requestId; |
36 | - private final MsgType msgType; | 37 | + private final SessionMsgType sessionMsgType; |
37 | private final boolean sync; | 38 | private final boolean sync; |
38 | 39 | ||
39 | } | 40 | } |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.extensions.sqs.action.standard; | 16 | package org.thingsboard.server.extensions.sqs.action.standard; |
17 | 17 | ||
18 | -import org.thingsboard.server.common.msg.device.ToDeviceActorMsg; | 18 | +import org.thingsboard.server.common.msg.device.DeviceToDeviceActorMsg; |
19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | import org.thingsboard.server.extensions.api.component.Action; | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
@@ -31,7 +31,7 @@ import java.util.Optional; | @@ -31,7 +31,7 @@ import java.util.Optional; | ||
31 | public class SqsStandardQueuePluginAction extends AbstractTemplatePluginAction<SqsStandardQueuePluginActionConfiguration> { | 31 | public class SqsStandardQueuePluginAction extends AbstractTemplatePluginAction<SqsStandardQueuePluginActionConfiguration> { |
32 | 32 | ||
33 | @Override | 33 | @Override |
34 | - protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, ToDeviceActorMsg msg, FromDeviceRequestMsg payload) { | 34 | + protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, DeviceToDeviceActorMsg msg, FromDeviceRequestMsg payload) { |
35 | SqsStandardQueueActionPayload.SqsStandardQueueActionPayloadBuilder builder = SqsStandardQueueActionPayload.builder(); | 35 | SqsStandardQueueActionPayload.SqsStandardQueueActionPayloadBuilder builder = SqsStandardQueueActionPayload.builder(); |
36 | builder.msgType(payload.getMsgType()); | 36 | builder.msgType(payload.getMsgType()); |
37 | builder.requestId(payload.getRequestId()); | 37 | builder.requestId(payload.getRequestId()); |
@@ -65,7 +65,7 @@ public class SqsMessageHandler implements RuleMsgHandler { | @@ -65,7 +65,7 @@ public class SqsMessageHandler implements RuleMsgHandler { | ||
65 | sqs.sendMessage(sendMsgRequest); | 65 | sqs.sendMessage(sendMsgRequest); |
66 | if (payload.isSync()) { | 66 | if (payload.isSync()) { |
67 | ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, | 67 | ctx.reply(new ResponsePluginToRuleMsg(msg.getUid(), tenantId, ruleId, |
68 | - BasicStatusCodeResponse.onSuccess(payload.getMsgType(), payload.getRequestId()))); | 68 | + BasicStatusCodeResponse.onSuccess(payload.getSessionMsgType(), payload.getRequestId()))); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 |
@@ -28,8 +28,10 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry; | @@ -28,8 +28,10 @@ import org.thingsboard.server.common.data.kv.BasicTsKvEntry; | ||
28 | import org.thingsboard.server.common.data.kv.KvEntry; | 28 | import org.thingsboard.server.common.data.kv.KvEntry; |
29 | import org.thingsboard.server.common.data.kv.TsKvEntry; | 29 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
30 | import org.thingsboard.server.common.data.plugin.ComponentType; | 30 | import org.thingsboard.server.common.data.plugin.ComponentType; |
31 | +import org.thingsboard.server.common.msg.MsgType; | ||
31 | import org.thingsboard.server.common.msg.TbMsg; | 32 | import org.thingsboard.server.common.msg.TbMsg; |
32 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; | 33 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
34 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
33 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; | 35 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
34 | 36 | ||
35 | import java.nio.charset.StandardCharsets; | 37 | import java.nio.charset.StandardCharsets; |
@@ -59,7 +61,7 @@ public class TbMsgTelemetryNode implements TbNode { | @@ -59,7 +61,7 @@ public class TbMsgTelemetryNode implements TbNode { | ||
59 | 61 | ||
60 | @Override | 62 | @Override |
61 | public void onMsg(TbContext ctx, TbMsg msg) { | 63 | public void onMsg(TbContext ctx, TbMsg msg) { |
62 | - if (!msg.getType().equals("POST_TELEMETRY")) { | 64 | + if (!msg.getType().equals(SessionMsgType.POST_TELEMETRY_REQUEST.name())) { |
63 | ctx.tellError(msg, new IllegalArgumentException("Unsupported msg type: " + msg.getType())); | 65 | ctx.tellError(msg, new IllegalArgumentException("Unsupported msg type: " + msg.getType())); |
64 | return; | 66 | return; |
65 | } | 67 | } |
@@ -90,7 +90,7 @@ public class CoapTransportResource extends CoapResource { | @@ -90,7 +90,7 @@ public class CoapTransportResource extends CoapResource { | ||
90 | } else if (exchange.getRequestOptions().hasObserve()) { | 90 | } else if (exchange.getRequestOptions().hasObserve()) { |
91 | processExchangeGetRequest(exchange, featureType.get()); | 91 | processExchangeGetRequest(exchange, featureType.get()); |
92 | } else if (featureType.get() == FeatureType.ATTRIBUTES) { | 92 | } else if (featureType.get() == FeatureType.ATTRIBUTES) { |
93 | - processRequest(exchange, MsgType.GET_ATTRIBUTES_REQUEST); | 93 | + processRequest(exchange, SessionMsgType.GET_ATTRIBUTES_REQUEST); |
94 | } else { | 94 | } else { |
95 | log.trace("Invalid feature type parameter"); | 95 | log.trace("Invalid feature type parameter"); |
96 | exchange.respond(ResponseCode.BAD_REQUEST); | 96 | exchange.respond(ResponseCode.BAD_REQUEST); |
@@ -99,13 +99,13 @@ public class CoapTransportResource extends CoapResource { | @@ -99,13 +99,13 @@ public class CoapTransportResource extends CoapResource { | ||
99 | 99 | ||
100 | private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) { | 100 | private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) { |
101 | boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1; | 101 | boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1; |
102 | - MsgType msgType; | 102 | + SessionMsgType sessionMsgType; |
103 | if (featureType == FeatureType.RPC) { | 103 | if (featureType == FeatureType.RPC) { |
104 | - msgType = unsubscribe ? MsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : MsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST; | 104 | + sessionMsgType = unsubscribe ? SessionMsgType.UNSUBSCRIBE_RPC_COMMANDS_REQUEST : SessionMsgType.SUBSCRIBE_RPC_COMMANDS_REQUEST; |
105 | } else { | 105 | } else { |
106 | - msgType = unsubscribe ? MsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST; | 106 | + sessionMsgType = unsubscribe ? SessionMsgType.UNSUBSCRIBE_ATTRIBUTES_REQUEST : SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST; |
107 | } | 107 | } |
108 | - Optional<SessionId> sessionId = processRequest(exchange, msgType); | 108 | + Optional<SessionId> sessionId = processRequest(exchange, sessionMsgType); |
109 | if (sessionId.isPresent()) { | 109 | if (sessionId.isPresent()) { |
110 | if (exchange.getRequestOptions().getObserve() == 1) { | 110 | if (exchange.getRequestOptions().getObserve() == 1) { |
111 | exchange.respond(ResponseCode.VALID); | 111 | exchange.respond(ResponseCode.VALID); |
@@ -122,24 +122,24 @@ public class CoapTransportResource extends CoapResource { | @@ -122,24 +122,24 @@ public class CoapTransportResource extends CoapResource { | ||
122 | } else { | 122 | } else { |
123 | switch (featureType.get()) { | 123 | switch (featureType.get()) { |
124 | case ATTRIBUTES: | 124 | case ATTRIBUTES: |
125 | - processRequest(exchange, MsgType.POST_ATTRIBUTES_REQUEST); | 125 | + processRequest(exchange, SessionMsgType.POST_ATTRIBUTES_REQUEST); |
126 | break; | 126 | break; |
127 | case TELEMETRY: | 127 | case TELEMETRY: |
128 | - processRequest(exchange, MsgType.POST_TELEMETRY_REQUEST); | 128 | + processRequest(exchange, SessionMsgType.POST_TELEMETRY_REQUEST); |
129 | break; | 129 | break; |
130 | case RPC: | 130 | case RPC: |
131 | Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest()); | 131 | Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest()); |
132 | if (requestId.isPresent()) { | 132 | if (requestId.isPresent()) { |
133 | - processRequest(exchange, MsgType.TO_DEVICE_RPC_RESPONSE); | 133 | + processRequest(exchange, SessionMsgType.TO_DEVICE_RPC_RESPONSE); |
134 | } else { | 134 | } else { |
135 | - processRequest(exchange, MsgType.TO_SERVER_RPC_REQUEST); | 135 | + processRequest(exchange, SessionMsgType.TO_SERVER_RPC_REQUEST); |
136 | } | 136 | } |
137 | break; | 137 | break; |
138 | } | 138 | } |
139 | } | 139 | } |
140 | } | 140 | } |
141 | 141 | ||
142 | - private Optional<SessionId> processRequest(CoapExchange exchange, MsgType type) { | 142 | + private Optional<SessionId> processRequest(CoapExchange exchange, SessionMsgType type) { |
143 | log.trace("Processing {}", exchange.advanced().getRequest()); | 143 | log.trace("Processing {}", exchange.advanced().getRequest()); |
144 | exchange.accept(); | 144 | exchange.accept(); |
145 | Exchange advanced = exchange.advanced(); | 145 | Exchange advanced = exchange.advanced(); |
@@ -28,9 +28,10 @@ import org.thingsboard.server.common.msg.kv.AttributesKVMsg; | @@ -28,9 +28,10 @@ import org.thingsboard.server.common.msg.kv.AttributesKVMsg; | ||
28 | import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg; | 28 | import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg; |
29 | import org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg; | 29 | import org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg; |
30 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; | 30 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
31 | -import org.thingsboard.server.common.msg.session.MsgType; | 31 | +import org.thingsboard.server.common.msg.session.SessionMsgType; |
32 | import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg; | 32 | import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg; |
33 | import org.thingsboard.server.common.msg.session.SessionContext; | 33 | import org.thingsboard.server.common.msg.session.SessionContext; |
34 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | ||
34 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; | 35 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
35 | import org.thingsboard.server.common.msg.session.ex.ProcessingTimeoutException; | 36 | import org.thingsboard.server.common.msg.session.ex.ProcessingTimeoutException; |
36 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; | 37 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
@@ -48,7 +49,7 @@ import org.thingsboard.server.transport.coap.session.CoapSessionCtx; | @@ -48,7 +49,7 @@ import org.thingsboard.server.transport.coap.session.CoapSessionCtx; | ||
48 | public class JsonCoapAdaptor implements CoapTransportAdaptor { | 49 | public class JsonCoapAdaptor implements CoapTransportAdaptor { |
49 | 50 | ||
50 | @Override | 51 | @Override |
51 | - public AdaptorToSessionActorMsg convertToActorMsg(CoapSessionCtx ctx, MsgType type, Request inbound) throws AdaptorException { | 52 | + public AdaptorToSessionActorMsg convertToActorMsg(CoapSessionCtx ctx, SessionMsgType type, Request inbound) throws AdaptorException { |
52 | FromDeviceMsg msg = null; | 53 | FromDeviceMsg msg = null; |
53 | switch (type) { | 54 | switch (type) { |
54 | case POST_TELEMETRY_REQUEST: | 55 | case POST_TELEMETRY_REQUEST: |
@@ -104,7 +105,7 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | @@ -104,7 +105,7 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | ||
104 | @Override | 105 | @Override |
105 | public Optional<Response> convertToAdaptorMsg(CoapSessionCtx ctx, SessionActorToAdaptorMsg source) throws AdaptorException { | 106 | public Optional<Response> convertToAdaptorMsg(CoapSessionCtx ctx, SessionActorToAdaptorMsg source) throws AdaptorException { |
106 | ToDeviceMsg msg = source.getMsg(); | 107 | ToDeviceMsg msg = source.getMsg(); |
107 | - switch (msg.getMsgType()) { | 108 | + switch (msg.getSessionMsgType()) { |
108 | case STATUS_CODE_RESPONSE: | 109 | case STATUS_CODE_RESPONSE: |
109 | case TO_DEVICE_RPC_RESPONSE_ACK: | 110 | case TO_DEVICE_RPC_RESPONSE_ACK: |
110 | return Optional.of(convertStatusCodeResponse((StatusCodeResponse) msg)); | 111 | return Optional.of(convertStatusCodeResponse((StatusCodeResponse) msg)); |
@@ -119,19 +120,19 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | @@ -119,19 +120,19 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { | ||
119 | case RULE_ENGINE_ERROR: | 120 | case RULE_ENGINE_ERROR: |
120 | return Optional.of(convertToRuleEngineErrorResponse(ctx, (RuleEngineErrorMsg) msg)); | 121 | return Optional.of(convertToRuleEngineErrorResponse(ctx, (RuleEngineErrorMsg) msg)); |
121 | default: | 122 | default: |
122 | - log.warn("[{}] Unsupported msg type: {}!", source.getSessionId(), msg.getMsgType()); | ||
123 | - throw new AdaptorException(new IllegalArgumentException("Unsupported msg type: " + msg.getMsgType() + "!")); | 123 | + log.warn("[{}] Unsupported msg type: {}!", source.getSessionId(), msg.getSessionMsgType()); |
124 | + throw new AdaptorException(new IllegalArgumentException("Unsupported msg type: " + msg.getSessionMsgType() + "!")); | ||
124 | } | 125 | } |
125 | } | 126 | } |
126 | 127 | ||
127 | private Response convertToRuleEngineErrorResponse(CoapSessionCtx ctx, RuleEngineErrorMsg msg) { | 128 | private Response convertToRuleEngineErrorResponse(CoapSessionCtx ctx, RuleEngineErrorMsg msg) { |
128 | ResponseCode status = ResponseCode.INTERNAL_SERVER_ERROR; | 129 | ResponseCode status = ResponseCode.INTERNAL_SERVER_ERROR; |
129 | switch (msg.getError()) { | 130 | switch (msg.getError()) { |
130 | - case PLUGIN_TIMEOUT: | 131 | + case QUEUE_PUT_TIMEOUT: |
131 | status = ResponseCode.GATEWAY_TIMEOUT; | 132 | status = ResponseCode.GATEWAY_TIMEOUT; |
132 | break; | 133 | break; |
133 | default: | 134 | default: |
134 | - if (msg.getInMsgType() == MsgType.TO_SERVER_RPC_REQUEST) { | 135 | + if (msg.getInSessionMsgType() == SessionMsgType.TO_SERVER_RPC_REQUEST) { |
135 | status = ResponseCode.BAD_REQUEST; | 136 | status = ResponseCode.BAD_REQUEST; |
136 | } | 137 | } |
137 | break; | 138 | break; |
@@ -113,9 +113,9 @@ public class CoapServerTest { | @@ -113,9 +113,9 @@ public class CoapServerTest { | ||
113 | try { | 113 | try { |
114 | FromDeviceMsg deviceMsg = sessionMsg.getMsg(); | 114 | FromDeviceMsg deviceMsg = sessionMsg.getMsg(); |
115 | ToDeviceMsg toDeviceMsg = null; | 115 | ToDeviceMsg toDeviceMsg = null; |
116 | - if (deviceMsg.getMsgType() == MsgType.POST_TELEMETRY_REQUEST) { | 116 | + if (deviceMsg.getMsgType() == SessionMsgType.POST_TELEMETRY_REQUEST) { |
117 | toDeviceMsg = BasicStatusCodeResponse.onSuccess(deviceMsg.getMsgType(), BasicRequest.DEFAULT_REQUEST_ID); | 117 | toDeviceMsg = BasicStatusCodeResponse.onSuccess(deviceMsg.getMsgType(), BasicRequest.DEFAULT_REQUEST_ID); |
118 | - } else if (deviceMsg.getMsgType() == MsgType.GET_ATTRIBUTES_REQUEST) { | 118 | + } else if (deviceMsg.getMsgType() == SessionMsgType.GET_ATTRIBUTES_REQUEST) { |
119 | List<AttributeKvEntry> data = new ArrayList<>(); | 119 | List<AttributeKvEntry> data = new ArrayList<>(); |
120 | data.add(new BaseAttributeKvEntry(new StringDataEntry("key1", "value1"), System.currentTimeMillis())); | 120 | data.add(new BaseAttributeKvEntry(new StringDataEntry("key1", "value1"), System.currentTimeMillis())); |
121 | data.add(new BaseAttributeKvEntry(new LongDataEntry("key2", 42L), System.currentTimeMillis())); | 121 | data.add(new BaseAttributeKvEntry(new LongDataEntry("key2", 42L), System.currentTimeMillis())); |
@@ -57,7 +57,7 @@ public class HttpSessionCtx extends DeviceAwareSessionContext { | @@ -57,7 +57,7 @@ public class HttpSessionCtx extends DeviceAwareSessionContext { | ||
57 | @Override | 57 | @Override |
58 | public void onMsg(SessionActorToAdaptorMsg source) throws SessionException { | 58 | public void onMsg(SessionActorToAdaptorMsg source) throws SessionException { |
59 | ToDeviceMsg msg = source.getMsg(); | 59 | ToDeviceMsg msg = source.getMsg(); |
60 | - switch (msg.getMsgType()) { | 60 | + switch (msg.getSessionMsgType()) { |
61 | case GET_ATTRIBUTES_RESPONSE: | 61 | case GET_ATTRIBUTES_RESPONSE: |
62 | reply((GetAttributesResponse) msg); | 62 | reply((GetAttributesResponse) msg); |
63 | return; | 63 | return; |
@@ -84,11 +84,11 @@ public class HttpSessionCtx extends DeviceAwareSessionContext { | @@ -84,11 +84,11 @@ public class HttpSessionCtx extends DeviceAwareSessionContext { | ||
84 | private void reply(RuleEngineErrorMsg msg) { | 84 | private void reply(RuleEngineErrorMsg msg) { |
85 | HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; | 85 | HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; |
86 | switch (msg.getError()) { | 86 | switch (msg.getError()) { |
87 | - case PLUGIN_TIMEOUT: | 87 | + case QUEUE_PUT_TIMEOUT: |
88 | status = HttpStatus.REQUEST_TIMEOUT; | 88 | status = HttpStatus.REQUEST_TIMEOUT; |
89 | break; | 89 | break; |
90 | default: | 90 | default: |
91 | - if (msg.getInMsgType() == MsgType.TO_SERVER_RPC_REQUEST) { | 91 | + if (msg.getInSessionMsgType() == SessionMsgType.TO_SERVER_RPC_REQUEST) { |
92 | status = HttpStatus.BAD_REQUEST; | 92 | status = HttpStatus.BAD_REQUEST; |
93 | } | 93 | } |
94 | break; | 94 | break; |
@@ -53,7 +53,7 @@ import java.util.List; | @@ -53,7 +53,7 @@ import java.util.List; | ||
53 | import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*; | 53 | import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*; |
54 | import static io.netty.handler.codec.mqtt.MqttMessageType.*; | 54 | import static io.netty.handler.codec.mqtt.MqttMessageType.*; |
55 | import static io.netty.handler.codec.mqtt.MqttQoS.*; | 55 | import static io.netty.handler.codec.mqtt.MqttQoS.*; |
56 | -import static org.thingsboard.server.common.msg.session.MsgType.*; | 56 | +import static org.thingsboard.server.common.msg.session.SessionMsgType.*; |
57 | import static org.thingsboard.server.transport.mqtt.MqttTopics.*; | 57 | import static org.thingsboard.server.transport.mqtt.MqttTopics.*; |
58 | 58 | ||
59 | /** | 59 | /** |
@@ -53,7 +53,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | @@ -53,7 +53,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | ||
53 | private static final ByteBufAllocator ALLOCATOR = new UnpooledByteBufAllocator(false); | 53 | private static final ByteBufAllocator ALLOCATOR = new UnpooledByteBufAllocator(false); |
54 | 54 | ||
55 | @Override | 55 | @Override |
56 | - public AdaptorToSessionActorMsg convertToActorMsg(DeviceSessionCtx ctx, MsgType type, MqttMessage inbound) throws AdaptorException { | 56 | + public AdaptorToSessionActorMsg convertToActorMsg(DeviceSessionCtx ctx, SessionMsgType type, MqttMessage inbound) throws AdaptorException { |
57 | FromDeviceMsg msg; | 57 | FromDeviceMsg msg; |
58 | switch (type) { | 58 | switch (type) { |
59 | case POST_TELEMETRY_REQUEST: | 59 | case POST_TELEMETRY_REQUEST: |
@@ -94,7 +94,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | @@ -94,7 +94,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | ||
94 | public Optional<MqttMessage> convertToAdaptorMsg(DeviceSessionCtx ctx, SessionActorToAdaptorMsg sessionMsg) throws AdaptorException { | 94 | public Optional<MqttMessage> convertToAdaptorMsg(DeviceSessionCtx ctx, SessionActorToAdaptorMsg sessionMsg) throws AdaptorException { |
95 | MqttMessage result = null; | 95 | MqttMessage result = null; |
96 | ToDeviceMsg msg = sessionMsg.getMsg(); | 96 | ToDeviceMsg msg = sessionMsg.getMsg(); |
97 | - switch (msg.getMsgType()) { | 97 | + switch (msg.getSessionMsgType()) { |
98 | case STATUS_CODE_RESPONSE: | 98 | case STATUS_CODE_RESPONSE: |
99 | case GET_ATTRIBUTES_RESPONSE: | 99 | case GET_ATTRIBUTES_RESPONSE: |
100 | ResponseMsg<?> responseMsg = (ResponseMsg) msg; | 100 | ResponseMsg<?> responseMsg = (ResponseMsg) msg; |
@@ -134,12 +134,12 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | @@ -134,12 +134,12 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { | ||
134 | private MqttMessage convertResponseMsg(DeviceSessionCtx ctx, ToDeviceMsg msg, | 134 | private MqttMessage convertResponseMsg(DeviceSessionCtx ctx, ToDeviceMsg msg, |
135 | ResponseMsg<?> responseMsg, Optional<Exception> responseError) throws AdaptorException { | 135 | ResponseMsg<?> responseMsg, Optional<Exception> responseError) throws AdaptorException { |
136 | MqttMessage result = null; | 136 | MqttMessage result = null; |
137 | - MsgType requestMsgType = responseMsg.getRequestMsgType(); | 137 | + SessionMsgType requestMsgType = responseMsg.getRequestMsgType(); |
138 | Integer requestId = responseMsg.getRequestId(); | 138 | Integer requestId = responseMsg.getRequestId(); |
139 | if (requestId >= 0) { | 139 | if (requestId >= 0) { |
140 | - if (requestMsgType == MsgType.POST_ATTRIBUTES_REQUEST || requestMsgType == MsgType.POST_TELEMETRY_REQUEST) { | 140 | + if (requestMsgType == SessionMsgType.POST_ATTRIBUTES_REQUEST || requestMsgType == SessionMsgType.POST_TELEMETRY_REQUEST) { |
141 | result = MqttTransportHandler.createMqttPubAckMsg(requestId); | 141 | result = MqttTransportHandler.createMqttPubAckMsg(requestId); |
142 | - } else if (requestMsgType == MsgType.GET_ATTRIBUTES_REQUEST) { | 142 | + } else if (requestMsgType == SessionMsgType.GET_ATTRIBUTES_REQUEST) { |
143 | GetAttributesResponse response = (GetAttributesResponse) msg; | 143 | GetAttributesResponse response = (GetAttributesResponse) msg; |
144 | Optional<AttributesKVMsg> responseData = response.getData(); | 144 | Optional<AttributesKVMsg> responseData = response.getData(); |
145 | if (response.isSuccess() && responseData.isPresent()) { | 145 | if (response.isSuccess() && responseData.isPresent()) { |
@@ -80,13 +80,13 @@ public class GatewayDeviceSessionCtx extends DeviceAwareSessionContext { | @@ -80,13 +80,13 @@ public class GatewayDeviceSessionCtx extends DeviceAwareSessionContext { | ||
80 | 80 | ||
81 | private Optional<MqttMessage> getToDeviceMsg(SessionActorToAdaptorMsg sessionMsg) { | 81 | private Optional<MqttMessage> getToDeviceMsg(SessionActorToAdaptorMsg sessionMsg) { |
82 | ToDeviceMsg msg = sessionMsg.getMsg(); | 82 | ToDeviceMsg msg = sessionMsg.getMsg(); |
83 | - switch (msg.getMsgType()) { | 83 | + switch (msg.getSessionMsgType()) { |
84 | case STATUS_CODE_RESPONSE: | 84 | case STATUS_CODE_RESPONSE: |
85 | ResponseMsg<?> responseMsg = (ResponseMsg) msg; | 85 | ResponseMsg<?> responseMsg = (ResponseMsg) msg; |
86 | if (responseMsg.isSuccess()) { | 86 | if (responseMsg.isSuccess()) { |
87 | - MsgType requestMsgType = responseMsg.getRequestMsgType(); | 87 | + SessionMsgType requestMsgType = responseMsg.getRequestMsgType(); |
88 | Integer requestId = responseMsg.getRequestId(); | 88 | Integer requestId = responseMsg.getRequestId(); |
89 | - if (requestId >= 0 && requestMsgType == MsgType.POST_ATTRIBUTES_REQUEST || requestMsgType == MsgType.POST_TELEMETRY_REQUEST) { | 89 | + if (requestId >= 0 && requestMsgType == SessionMsgType.POST_ATTRIBUTES_REQUEST || requestMsgType == SessionMsgType.POST_TELEMETRY_REQUEST) { |
90 | return Optional.of(MqttTransportHandler.createMqttPubAckMsg(requestId)); | 90 | return Optional.of(MqttTransportHandler.createMqttPubAckMsg(requestId)); |
91 | } | 91 | } |
92 | } | 92 | } |