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 | 61 | import org.thingsboard.server.service.component.ComponentDiscoveryService; |
62 | 62 | import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
63 | 63 | import org.thingsboard.server.service.mail.MailExecutorService; |
64 | +import org.thingsboard.server.service.rpc.DeviceRpcService; | |
64 | 65 | import org.thingsboard.server.service.script.JsExecutorService; |
65 | 66 | import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService; |
66 | 67 | |
... | ... | @@ -163,6 +164,10 @@ public class ActorSystemContext { |
163 | 164 | |
164 | 165 | @Autowired |
165 | 166 | @Getter |
167 | + private DeviceRpcService deviceRpcService; | |
168 | + | |
169 | + @Autowired | |
170 | + @Getter | |
166 | 171 | @Setter |
167 | 172 | private PluginWebSocketMsgEndpoint wsMsgEndpoint; |
168 | 173 | |
... | ... | @@ -186,17 +191,13 @@ public class ActorSystemContext { |
186 | 191 | @Getter |
187 | 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 | 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 | 199 | @Getter |
199 | - private long pluginErrorPersistFrequency; | |
200 | + private long queuePersistenceTimeout; | |
200 | 201 | |
201 | 202 | @Value("${actors.rule.chain.error_persist_frequency}") |
202 | 203 | @Getter |
... | ... | @@ -206,14 +207,6 @@ public class ActorSystemContext { |
206 | 207 | @Getter |
207 | 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 | 210 | @Value("${actors.statistics.enabled}") |
218 | 211 | @Getter |
219 | 212 | private boolean statisticsEnabled; | ... | ... |
... | ... | @@ -29,13 +29,12 @@ import org.thingsboard.server.actors.shared.plugin.SystemPluginManager; |
29 | 29 | import org.thingsboard.server.actors.shared.rulechain.SystemRuleChainManager; |
30 | 30 | import org.thingsboard.server.actors.tenant.TenantActor; |
31 | 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 | 32 | import org.thingsboard.server.common.data.id.TenantId; |
35 | 33 | import org.thingsboard.server.common.data.page.PageDataIterable; |
36 | 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 | 38 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
40 | 39 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
41 | 40 | import org.thingsboard.server.dao.model.ModelConstants; |
... | ... | @@ -90,12 +89,22 @@ public class AppActor extends RuleChainManagerActor { |
90 | 89 | @Override |
91 | 90 | protected boolean process(TbActorMsg msg) { |
92 | 91 | switch (msg.getMsgType()) { |
92 | + case CLUSTER_EVENT_MSG: | |
93 | + broadcast(msg); | |
94 | + break; | |
93 | 95 | case COMPONENT_LIFE_CYCLE_MSG: |
94 | 96 | onComponentLifecycleMsg((ComponentLifecycleMsg) msg); |
95 | 97 | break; |
96 | 98 | case SERVICE_TO_RULE_ENGINE_MSG: |
97 | 99 | onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); |
98 | 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 | 108 | default: |
100 | 109 | return false; |
101 | 110 | } |
... | ... | @@ -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 | 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 | 128 | private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) { |
156 | 129 | ActorRef target; |
157 | 130 | if (SYSTEM_TENANT.equals(msg.getTenantId())) { |
... | ... | @@ -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 | 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 | 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 | 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 | 24 | import org.thingsboard.server.common.data.id.TenantId; |
25 | 25 | import org.thingsboard.server.common.msg.TbActorMsg; |
26 | 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 | 30 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
29 | -import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; | |
30 | 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 | 35 | public class DeviceActor extends ContextAwareActor { |
36 | 36 | |
37 | 37 | private final LoggingAdapter logger = Logging.getLogger(getContext().system(), this); |
38 | 38 | |
39 | - private final TenantId tenantId; | |
40 | - private final DeviceId deviceId; | |
41 | 39 | private final DeviceActorMessageProcessor processor; |
42 | 40 | |
43 | 41 | private DeviceActor(ActorSystemContext systemContext, TenantId tenantId, DeviceId deviceId) { |
44 | 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 | 46 | @Override |
51 | 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 | 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 | 59 | processor.processCredentialsUpdate(); |
70 | - } else if (msg instanceof DeviceNameOrTypeUpdateMsg){ | |
60 | + break; | |
61 | + case DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG: | |
71 | 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 | 82 | public static class ActorCreator extends ContextBasedCreator<DeviceActor> { | ... | ... |
... | ... | @@ -18,31 +18,63 @@ package org.thingsboard.server.actors.device; |
18 | 18 | import akka.actor.ActorContext; |
19 | 19 | import akka.actor.ActorRef; |
20 | 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 | 25 | import org.thingsboard.server.actors.ActorSystemContext; |
22 | 26 | import org.thingsboard.server.actors.shared.AbstractContextAwareMsgProcessor; |
23 | 27 | import org.thingsboard.server.common.data.DataConstants; |
24 | 28 | import org.thingsboard.server.common.data.Device; |
25 | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
26 | 30 | import org.thingsboard.server.common.data.id.SessionId; |
31 | +import org.thingsboard.server.common.data.id.TenantId; | |
27 | 32 | import org.thingsboard.server.common.data.kv.AttributeKey; |
28 | 33 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
34 | +import org.thingsboard.server.common.data.kv.KvEntry; | |
29 | 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 | 39 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
31 | 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 | 55 | import org.thingsboard.server.common.msg.kv.BasicAttributeKVMsg; |
35 | 56 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
36 | 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 | 61 | import org.thingsboard.server.common.msg.session.SessionType; |
39 | 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 | 65 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
42 | 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 | 78 | import java.util.concurrent.ExecutionException; |
47 | 79 | import java.util.concurrent.TimeoutException; |
48 | 80 | import java.util.function.Consumer; |
... | ... | @@ -54,25 +86,30 @@ import java.util.stream.Collectors; |
54 | 86 | */ |
55 | 87 | public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor { |
56 | 88 | |
89 | + private final TenantId tenantId; | |
57 | 90 | private final DeviceId deviceId; |
58 | 91 | private final Map<SessionId, SessionInfo> sessions; |
59 | 92 | private final Map<SessionId, SessionInfo> attributeSubscriptions; |
60 | 93 | private final Map<SessionId, SessionInfo> rpcSubscriptions; |
61 | - | |
62 | 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 | 99 | private int rpcSeq = 0; |
65 | 100 | private String deviceName; |
66 | 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 | 105 | super(systemContext, logger); |
106 | + this.tenantId = tenantId; | |
71 | 107 | this.deviceId = deviceId; |
72 | 108 | this.sessions = new HashMap<>(); |
73 | 109 | this.attributeSubscriptions = new HashMap<>(); |
74 | 110 | this.rpcSubscriptions = new HashMap<>(); |
75 | 111 | this.rpcPendingMap = new HashMap<>(); |
112 | + this.pendingMsgs = new HashMap<>(); | |
76 | 113 | initAttributes(); |
77 | 114 | } |
78 | 115 | |
... | ... | @@ -81,19 +118,12 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
81 | 118 | Device device = systemContext.getDeviceService().findDeviceById(deviceId); |
82 | 119 | this.deviceName = device.getName(); |
83 | 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 | 127 | ToDeviceRpcRequest request = msg.getMsg(); |
98 | 128 | ToDeviceRpcRequestBody body = request.getBody(); |
99 | 129 | ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg( |
... | ... | @@ -120,9 +150,8 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
120 | 150 | syncSessionSet.forEach(rpcSubscriptions::remove); |
121 | 151 | |
122 | 152 | if (request.isOneway() && sent) { |
123 | - ToPluginRpcResponseDeviceMsg responsePluginMsg = toPluginRpcResponseMsg(msg, (String) null); | |
124 | - context.parent().tell(responsePluginMsg, ActorRef.noSender()); | |
125 | 153 | logger.debug("[{}] Rpc command response sent [{}]!", deviceId, request.getId()); |
154 | + systemContext.getDeviceRpcService().process(new FromDeviceRpcResponse(msg.getMsg().getId(), null, null)); | |
126 | 155 | } else { |
127 | 156 | registerPendingRpcRequest(context, msg, sent, rpcRequest, timeout); |
128 | 157 | } |
... | ... | @@ -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 | 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 | 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 | 173 | ToDeviceRpcRequestMetadata requestMd = rpcPendingMap.remove(msg.getId()); |
145 | 174 | if (requestMd != null) { |
146 | 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 | 222 | ToDeviceRpcRequestBody body = request.getBody(); |
176 | 223 | if (request.isOneway()) { |
177 | 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 | 227 | ToDeviceRpcRequestMsg rpcRequest = new ToDeviceRpcRequestMsg( |
182 | 228 | entry.getKey(), |
... | ... | @@ -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 | 238 | processSubscriptionCommands(context, msg); |
193 | 239 | processRpcResponses(context, msg); |
194 | 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 | 300 | void processAttributesUpdate(ActorContext context, DeviceAttributesEventNotificationMsg msg) { |
198 | - refreshAttributes(msg); | |
199 | 301 | if (attributeSubscriptions.size() > 0) { |
200 | 302 | ToDeviceMsg notification = null; |
201 | 303 | if (msg.isDeleted()) { |
... | ... | @@ -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 | 331 | SessionId sessionId = msg.getSessionId(); |
243 | 332 | FromDeviceMsg inMsg = msg.getPayload(); |
244 | - if (inMsg.getMsgType() == MsgType.TO_DEVICE_RPC_RESPONSE) { | |
333 | + if (inMsg.getMsgType() == SessionMsgType.TO_DEVICE_RPC_RESPONSE) { | |
245 | 334 | logger.debug("[{}] Processing rpc command response [{}]", deviceId, sessionId); |
246 | 335 | ToDeviceRpcResponseMsg responseMsg = (ToDeviceRpcResponseMsg) inMsg; |
247 | 336 | ToDeviceRpcRequestMetadata requestMd = rpcPendingMap.remove(responseMsg.getRequestId()); |
248 | 337 | boolean success = requestMd != null; |
249 | 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 | 340 | } else { |
260 | 341 | logger.debug("[{}] Rpc command response [{}] is stale!", deviceId, responseMsg.getRequestId()); |
261 | 342 | } |
262 | 343 | if (msg.getSessionType() == SessionType.SYNC) { |
263 | 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 | 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 | 353 | if (!msg.isAdded()) { |
273 | 354 | logger.debug("[{}] Clearing attributes/rpc subscription for server [{}]", deviceId, msg.getServerAddress()); |
274 | 355 | Predicate<Map.Entry<SessionId, SessionInfo>> filter = e -> e.getValue().getServer() |
... | ... | @@ -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 | 363 | SessionId sessionId = msg.getSessionId(); |
315 | 364 | SessionType sessionType = msg.getSessionType(); |
316 | 365 | FromDeviceMsg inMsg = msg.getPayload(); |
317 | - if (inMsg.getMsgType() == MsgType.SUBSCRIBE_ATTRIBUTES_REQUEST) { | |
366 | + if (inMsg.getMsgType() == SessionMsgType.SUBSCRIBE_ATTRIBUTES_REQUEST) { | |
318 | 367 | logger.debug("[{}] Registering attributes subscription for session [{}]", deviceId, sessionId); |
319 | 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 | 370 | logger.debug("[{}] Canceling attributes subscription for session [{}]", deviceId, sessionId); |
322 | 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 | 373 | logger.debug("[{}] Registering rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType); |
325 | 374 | rpcSubscriptions.put(sessionId, new SessionInfo(sessionType, msg.getServerAddress())); |
326 | 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 | 377 | logger.debug("[{}] Canceling rpc subscription for session [{}][{}]", deviceId, sessionId, sessionType); |
329 | 378 | rpcSubscriptions.remove(sessionId); |
330 | 379 | } |
331 | 380 | } |
332 | 381 | |
333 | - private void processSessionStateMsgs(ToDeviceActorMsg msg) { | |
382 | + private void processSessionStateMsgs(DeviceToDeviceActorMsg msg) { | |
334 | 383 | SessionId sessionId = msg.getSessionId(); |
335 | 384 | FromDeviceMsg inMsg = msg.getPayload(); |
336 | 385 | if (inMsg instanceof SessionOpenMsg) { |
... | ... | @@ -364,7 +413,7 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
364 | 413 | } |
365 | 414 | } |
366 | 415 | |
367 | - public void processCredentialsUpdate() { | |
416 | + void processCredentialsUpdate() { | |
368 | 417 | sessions.forEach((k, v) -> { |
369 | 418 | sendMsgToSessionActor(new BasicToDeviceSessionActorMsg(new SessionCloseNotification(), k), v.getServer()); |
370 | 419 | }); |
... | ... | @@ -372,8 +421,12 @@ public class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcesso |
372 | 421 | rpcSubscriptions.clear(); |
373 | 422 | } |
374 | 423 | |
375 | - public void processNameOrTypeUpdate(DeviceNameOrTypeUpdateMsg msg) { | |
424 | + void processNameOrTypeUpdate(DeviceNameOrTypeUpdateMsg msg) { | |
376 | 425 | this.deviceName = msg.getDeviceName(); |
377 | 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 | 16 | package org.thingsboard.server.actors.device; |
17 | 17 | |
18 | 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 | 22 | * @author Andrew Shvayka |
23 | 23 | */ |
24 | 24 | @Data |
25 | 25 | public class ToDeviceRpcRequestMetadata { |
26 | - private final ToDeviceRpcRequestPluginMsg msg; | |
26 | + private final ToDeviceRpcRequestMsg msg; | |
27 | 27 | private final boolean sent; |
28 | 28 | } | ... | ... |
... | ... | @@ -26,7 +26,7 @@ import org.thingsboard.server.common.data.id.TenantId; |
26 | 26 | import org.thingsboard.server.common.msg.TbActorMsg; |
27 | 27 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
28 | 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 | 30 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; |
31 | 31 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
32 | 32 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
... | ... | @@ -153,6 +153,7 @@ public class PluginActor extends ComponentActor<PluginId, PluginActorMessageProc |
153 | 153 | |
154 | 154 | @Override |
155 | 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 | 30 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
31 | 31 | import org.thingsboard.server.common.msg.core.BasicStatusCodeResponse; |
32 | 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 | 35 | import org.thingsboard.server.extensions.api.plugins.Plugin; |
35 | 36 | import org.thingsboard.server.extensions.api.plugins.PluginInitializationException; |
36 | 37 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
37 | 38 | import org.thingsboard.server.extensions.api.plugins.msg.ResponsePluginToRuleMsg; |
38 | 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 | 41 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
41 | 42 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
42 | 43 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; |
... | ... | @@ -108,7 +109,7 @@ public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> |
108 | 109 | } catch (Exception ex) { |
109 | 110 | logger.debug("[{}] Failed to process RuleToPlugin msg: [{}] [{}]", tenantId, msg.getMsg(), ex); |
110 | 111 | RuleToPluginMsg ruleMsg = msg.getMsg(); |
111 | - MsgType responceMsgType = MsgType.RULE_ENGINE_ERROR; | |
112 | + SessionMsgType responceMsgType = SessionMsgType.RULE_ENGINE_ERROR; | |
112 | 113 | Integer requestId = 0; |
113 | 114 | if (ruleMsg.getPayload() instanceof FromDeviceRequestMsg) { |
114 | 115 | requestId = ((FromDeviceRequestMsg) ruleMsg.getPayload()).getRequestId(); |
... | ... | @@ -216,7 +217,7 @@ public class PluginActorMessageProcessor extends ComponentMsgProcessor<PluginId> |
216 | 217 | @Override |
217 | 218 | public void onStop(ActorContext context) { |
218 | 219 | onStop(); |
219 | - scheduleMsgWithDelay(context, new PluginTerminationMsg(entityId), systemContext.getPluginActorTerminationDelay()); | |
220 | +// scheduleMsgWithDelay(context, new PluginTerminationMsg(entityId), systemContext.getPluginActorTerminationDelay()); | |
220 | 221 | } |
221 | 222 | |
222 | 223 | private void onStop() { | ... | ... |
... | ... | @@ -41,6 +41,7 @@ import org.thingsboard.server.common.data.rule.RuleChain; |
41 | 41 | import org.thingsboard.server.common.data.rule.RuleMetaData; |
42 | 42 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
43 | 43 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
44 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | |
44 | 45 | import org.thingsboard.server.extensions.api.device.DeviceAttributesEventNotificationMsg; |
45 | 46 | import org.thingsboard.server.extensions.api.plugins.PluginApiCallSecurityContext; |
46 | 47 | import org.thingsboard.server.extensions.api.plugins.PluginCallback; | ... | ... |
... | ... | @@ -19,10 +19,12 @@ import akka.actor.ActorRef; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
21 | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | +import org.thingsboard.server.common.data.id.PluginId; | |
22 | 23 | import org.thingsboard.server.common.data.id.TenantId; |
23 | 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 | 27 | import org.thingsboard.server.controller.plugin.PluginWebSocketMsgEndpoint; |
25 | -import org.thingsboard.server.common.data.id.PluginId; | |
26 | 28 | import org.thingsboard.server.dao.asset.AssetService; |
27 | 29 | import org.thingsboard.server.dao.attributes.AttributesService; |
28 | 30 | import org.thingsboard.server.dao.audit.AuditLogService; |
... | ... | @@ -35,9 +37,6 @@ import org.thingsboard.server.dao.rule.RuleService; |
35 | 37 | import org.thingsboard.server.dao.tenant.TenantService; |
36 | 38 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
37 | 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 | 40 | import org.thingsboard.server.service.cluster.routing.ClusterRoutingService; |
42 | 41 | import org.thingsboard.server.service.cluster.rpc.ClusterRpcService; |
43 | 42 | import scala.concurrent.duration.Duration; |
... | ... | @@ -106,8 +105,8 @@ public final class SharedPluginProcessingContext { |
106 | 105 | |
107 | 106 | public void sendRpcRequest(ToDeviceRpcRequest msg) { |
108 | 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 | 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 | 28 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
29 | 29 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
30 | 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 | 32 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
33 | 33 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
34 | 34 | import org.thingsboard.server.extensions.api.plugins.msg.*; |
... | ... | @@ -86,7 +86,7 @@ public class BasicRpcSessionListener implements GrpcSessionListener { |
86 | 86 | @Override |
87 | 87 | public void onToDeviceActorRpcMsg(GrpcSession session, ClusterAPIProtos.ToDeviceActorRpcMessage msg) { |
88 | 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 | 92 | @Override | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2018 The Thingsboard Authors |
3 | - * | |
3 | + * <p> | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 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 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
... | ... | @@ -18,6 +18,7 @@ package org.thingsboard.server.actors.ruleChain; |
18 | 18 | import akka.actor.OneForOneStrategy; |
19 | 19 | import akka.actor.SupervisorStrategy; |
20 | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
21 | +import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | |
21 | 22 | import org.thingsboard.server.actors.service.ComponentActor; |
22 | 23 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
23 | 24 | import org.thingsboard.server.common.data.id.RuleChainId; |
... | ... | @@ -44,6 +45,9 @@ public class RuleChainActor extends ComponentActor<RuleChainId, RuleChainActorMe |
44 | 45 | case SERVICE_TO_RULE_ENGINE_MSG: |
45 | 46 | processor.onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); |
46 | 47 | break; |
48 | + case DEVICE_ACTOR_TO_RULE_ENGINE_MSG: | |
49 | + processor.onDeviceActorToRuleEngineMsg((DeviceActorToRuleEngineMsg) msg); | |
50 | + break; | |
47 | 51 | case RULE_TO_RULE_CHAIN_TELL_NEXT_MSG: |
48 | 52 | processor.onTellNext((RuleNodeToRuleChainTellNextMsg) msg); |
49 | 53 | break; | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2018 The Thingsboard Authors |
3 | - * | |
3 | + * <p> | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 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 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
... | ... | @@ -20,6 +20,8 @@ import akka.actor.ActorRef; |
20 | 20 | import akka.actor.Props; |
21 | 21 | import akka.event.LoggingAdapter; |
22 | 22 | import org.thingsboard.server.actors.ActorSystemContext; |
23 | +import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | |
24 | +import org.thingsboard.server.actors.device.RuleEngineQueuePutAckMsg; | |
23 | 25 | import org.thingsboard.server.actors.service.DefaultActorService; |
24 | 26 | import org.thingsboard.server.actors.shared.ComponentMsgProcessor; |
25 | 27 | import org.thingsboard.server.common.data.EntityType; |
... | ... | @@ -157,6 +159,14 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh |
157 | 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 | 170 | void onTellNext(RuleNodeToRuleChainTellNextMsg envelope) { |
161 | 171 | checkActive(); |
162 | 172 | RuleNodeId originator = envelope.getOriginator(); |
... | ... | @@ -191,5 +201,4 @@ public class RuleChainActorMessageProcessor extends ComponentMsgProcessor<RuleCh |
191 | 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 | public abstract class RuleChainManagerActor extends ContextAwareActor { |
32 | 32 | |
33 | 33 | protected final RuleChainManager ruleChainManager; |
34 | - protected final PluginManager pluginManager; | |
35 | 34 | protected final RuleChainService ruleChainService; |
36 | 35 | |
37 | 36 | public RuleChainManagerActor(ActorSystemContext systemContext, RuleChainManager ruleChainManager, PluginManager pluginManager) { |
38 | 37 | super(systemContext); |
39 | 38 | this.ruleChainManager = ruleChainManager; |
40 | - this.pluginManager = pluginManager; | |
41 | 39 | this.ruleChainService = systemContext.getRuleChainService(); |
42 | 40 | } |
43 | 41 | |
44 | 42 | protected void initRuleChains() { |
45 | - pluginManager.init(this.context()); | |
46 | 43 | ruleChainManager.init(this.context()); |
47 | 44 | } |
48 | 45 | |
49 | 46 | protected ActorRef getEntityActorRef(EntityId entityId) { |
50 | 47 | ActorRef target = null; |
51 | 48 | switch (entityId.getEntityType()) { |
52 | - case PLUGIN: | |
53 | - target = pluginManager.getOrCreateActor(this.context(), (PluginId) entityId); | |
54 | - break; | |
55 | 49 | case RULE_CHAIN: |
56 | 50 | target = ruleChainManager.getOrCreateActor(this.context(), (RuleChainId) entityId); |
57 | 51 | break; |
58 | 52 | } |
59 | 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 | 39 | import org.thingsboard.server.common.msg.core.ToDeviceSessionActorMsg; |
40 | 40 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
41 | 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 | 43 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
44 | 44 | import org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg; |
45 | 45 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
... | ... | @@ -156,7 +156,7 @@ public class DefaultActorService implements ActorService { |
156 | 156 | } |
157 | 157 | |
158 | 158 | @Override |
159 | - public void onMsg(ToDeviceActorMsg msg) { | |
159 | + public void onMsg(DeviceToDeviceActorMsg msg) { | |
160 | 160 | log.trace("Processing device rpc msg: {}", msg); |
161 | 161 | appActor.tell(msg, ActorRef.noSender()); |
162 | 162 | } | ... | ... |
... | ... | @@ -22,12 +22,11 @@ import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
22 | 22 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
23 | 23 | import org.thingsboard.server.common.msg.core.*; |
24 | 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 | 26 | import org.thingsboard.server.common.msg.session.*; |
27 | 27 | |
28 | 28 | import akka.actor.ActorContext; |
29 | 29 | import akka.event.LoggingAdapter; |
30 | -import org.thingsboard.server.common.msg.session.ctrl.*; | |
31 | 30 | import org.thingsboard.server.common.msg.session.ex.SessionException; |
32 | 31 | |
33 | 32 | import java.util.HashMap; |
... | ... | @@ -37,7 +36,7 @@ import java.util.Optional; |
37 | 36 | class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
38 | 37 | |
39 | 38 | private boolean firstMsg = true; |
40 | - private Map<Integer, ToDeviceActorMsg> pendingMap = new HashMap<>(); | |
39 | + private Map<Integer, DeviceToDeviceActorMsg> pendingMap = new HashMap<>(); | |
41 | 40 | private Optional<ServerAddress> currentTargetServer; |
42 | 41 | private boolean subscribedToAttributeUpdates; |
43 | 42 | private boolean subscribedToRpcCommands; |
... | ... | @@ -53,7 +52,7 @@ class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
53 | 52 | toDeviceMsg(new SessionOpenMsg()).ifPresent(m -> forwardToAppActor(ctx, m)); |
54 | 53 | firstMsg = false; |
55 | 54 | } |
56 | - ToDeviceActorMsg pendingMsg = toDeviceMsg(msg); | |
55 | + DeviceToDeviceActorMsg pendingMsg = toDeviceMsg(msg); | |
57 | 56 | FromDeviceMsg fromDeviceMsg = pendingMsg.getPayload(); |
58 | 57 | switch (fromDeviceMsg.getMsgType()) { |
59 | 58 | case POST_TELEMETRY_REQUEST: |
... | ... | @@ -86,8 +85,8 @@ class ASyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
86 | 85 | @Override |
87 | 86 | public void processToDeviceMsg(ActorContext context, ToDeviceMsg msg) { |
88 | 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 | 90 | case STATUS_CODE_RESPONSE: |
92 | 91 | case GET_ATTRIBUTES_RESPONSE: |
93 | 92 | ResponseMsg responseMsg = (ResponseMsg) msg; | ... | ... |
... | ... | @@ -22,8 +22,8 @@ import org.thingsboard.server.common.data.id.DeviceId; |
22 | 22 | import org.thingsboard.server.common.data.id.SessionId; |
23 | 23 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
24 | 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 | 27 | import org.thingsboard.server.common.msg.session.*; |
28 | 28 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
29 | 29 | |
... | ... | @@ -37,7 +37,7 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP |
37 | 37 | |
38 | 38 | protected final SessionId sessionId; |
39 | 39 | protected SessionContext sessionCtx; |
40 | - protected ToDeviceActorMsg toDeviceActorMsgPrototype; | |
40 | + protected DeviceToDeviceActorMsg deviceToDeviceActorMsgPrototype; | |
41 | 41 | |
42 | 42 | protected AbstractSessionActorMsgProcessor(ActorSystemContext ctx, LoggingAdapter logger, SessionId sessionId) { |
43 | 43 | super(ctx, logger); |
... | ... | @@ -64,29 +64,29 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP |
64 | 64 | |
65 | 65 | protected void updateSessionCtx(ToDeviceActorSessionMsg msg, SessionType type) { |
66 | 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 | 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 | 78 | } else { |
79 | 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 | 84 | Optional<ServerAddress> address = systemContext.getRoutingService().resolveById(toForward.getDeviceId()); |
85 | 85 | forwardToAppActor(ctx, toForward, address); |
86 | 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 | 90 | Optional<ServerAddress> newAddress = systemContext.getRoutingService().resolveById(toForward.getDeviceId()); |
91 | 91 | if (!newAddress.equals(oldAddress)) { |
92 | 92 | if (newAddress.isPresent()) { |
... | ... | @@ -99,7 +99,7 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP |
99 | 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 | 103 | if (address.isPresent()) { |
104 | 104 | systemContext.getRpcService().tell(address.get(), |
105 | 105 | toForward.toOtherAddress(systemContext.getRoutingService().getCurrentServer())); |
... | ... | @@ -114,6 +114,6 @@ abstract class AbstractSessionActorMsgProcessor extends AbstractContextAwareMsgP |
114 | 114 | } |
115 | 115 | |
116 | 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 | 20 | import org.thingsboard.server.common.data.id.SessionId; |
21 | 21 | import org.thingsboard.server.common.msg.cluster.ClusterEventMsg; |
22 | 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 | 24 | import org.thingsboard.server.common.msg.session.*; |
25 | 25 | import org.thingsboard.server.common.msg.session.ToDeviceActorSessionMsg; |
26 | 26 | import org.thingsboard.server.common.msg.session.ctrl.SessionCloseMsg; |
... | ... | @@ -32,7 +32,7 @@ import akka.event.LoggingAdapter; |
32 | 32 | import java.util.Optional; |
33 | 33 | |
34 | 34 | class SyncMsgProcessor extends AbstractSessionActorMsgProcessor { |
35 | - private ToDeviceActorMsg pendingMsg; | |
35 | + private DeviceToDeviceActorMsg pendingMsg; | |
36 | 36 | private Optional<ServerAddress> currentTargetServer; |
37 | 37 | private boolean pendingResponse; |
38 | 38 | ... | ... |
... | ... | @@ -17,10 +17,9 @@ package org.thingsboard.server.actors.tenant; |
17 | 17 | |
18 | 18 | import akka.actor.ActorRef; |
19 | 19 | import akka.actor.Props; |
20 | -import akka.event.Logging; | |
21 | -import akka.event.LoggingAdapter; | |
22 | 20 | import org.thingsboard.server.actors.ActorSystemContext; |
23 | 21 | import org.thingsboard.server.actors.device.DeviceActor; |
22 | +import org.thingsboard.server.actors.device.DeviceActorToRuleEngineMsg; | |
24 | 23 | import org.thingsboard.server.actors.plugin.PluginTerminationMsg; |
25 | 24 | import org.thingsboard.server.actors.ruleChain.RuleChainManagerActor; |
26 | 25 | import org.thingsboard.server.actors.service.ContextBasedCreator; |
... | ... | @@ -30,7 +29,8 @@ import org.thingsboard.server.actors.shared.rulechain.TenantRuleChainManager; |
30 | 29 | import org.thingsboard.server.common.data.id.DeviceId; |
31 | 30 | import org.thingsboard.server.common.data.id.TenantId; |
32 | 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 | 34 | import org.thingsboard.server.common.msg.plugin.ComponentLifecycleMsg; |
35 | 35 | import org.thingsboard.server.common.msg.system.ServiceToRuleEngineMsg; |
36 | 36 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
... | ... | @@ -64,63 +64,47 @@ public class TenantActor extends RuleChainManagerActor { |
64 | 64 | @Override |
65 | 65 | protected boolean process(TbActorMsg msg) { |
66 | 66 | switch (msg.getMsgType()) { |
67 | + case CLUSTER_EVENT_MSG: | |
68 | + broadcast(msg); | |
69 | + break; | |
67 | 70 | case COMPONENT_LIFE_CYCLE_MSG: |
68 | 71 | onComponentLifecycleMsg((ComponentLifecycleMsg) msg); |
69 | 72 | break; |
70 | 73 | case SERVICE_TO_RULE_ENGINE_MSG: |
71 | 74 | onServiceToRuleEngineMsg((ServiceToRuleEngineMsg) msg); |
72 | 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 | 86 | default: |
74 | 87 | return false; |
75 | 88 | } |
76 | 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 | 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 | 110 | private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) { |
... | ... | @@ -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 | 119 | private ActorRef getOrCreateDeviceActor(DeviceId deviceId) { |
141 | 120 | return deviceActors.computeIfAbsent(deviceId, k -> context().actorOf(Props.create(new DeviceActor.ActorCreator(systemContext, tenantId, deviceId)) |
142 | 121 | .withDispatcher(DefaultActorService.CORE_DISPATCHER_NAME), deviceId.toString())); | ... | ... |
... | ... | @@ -131,8 +131,8 @@ public class ThingsboardInstallService { |
131 | 131 | systemDataLoaderService.createSysAdmin(); |
132 | 132 | systemDataLoaderService.createAdminSettings(); |
133 | 133 | systemDataLoaderService.loadSystemWidgets(); |
134 | - systemDataLoaderService.loadSystemPlugins(); | |
135 | - systemDataLoaderService.loadSystemRules(); | |
134 | +// systemDataLoaderService.loadSystemPlugins(); | |
135 | +// systemDataLoaderService.loadSystemRules(); | |
136 | 136 | |
137 | 137 | if (loadDemo) { |
138 | 138 | log.info("Loading demo data..."); | ... | ... |
... | ... | @@ -30,11 +30,10 @@ import org.thingsboard.server.common.data.id.EntityId; |
30 | 30 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
31 | 31 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
32 | 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 | 34 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
35 | 35 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
36 | 36 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
37 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | |
38 | 37 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; |
39 | 38 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
40 | 39 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
... | ... | @@ -119,7 +118,7 @@ public class ClusterGrpcService extends ClusterRpcServiceGrpc.ClusterRpcServiceI |
119 | 118 | } |
120 | 119 | |
121 | 120 | @Override |
122 | - public void tell(ServerAddress serverAddress, ToDeviceActorMsg toForward) { | |
121 | + public void tell(ServerAddress serverAddress, DeviceToDeviceActorMsg toForward) { | |
123 | 122 | ClusterAPIProtos.ToRpcServerMessage msg = ClusterAPIProtos.ToRpcServerMessage.newBuilder() |
124 | 123 | .setToDeviceActorRpcMsg(toProtoMsg(toForward)).build(); |
125 | 124 | tell(serverAddress, msg); |
... | ... | @@ -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 | 188 | return ClusterAPIProtos.ToDeviceActorRpcMessage.newBuilder().setData( |
190 | 189 | ByteString.copyFrom(SerializationUtils.serialize(msg)) |
191 | 190 | ).build(); | ... | ... |
... | ... | @@ -19,10 +19,8 @@ import io.grpc.stub.StreamObserver; |
19 | 19 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
20 | 20 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
21 | 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 | 23 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
25 | -import org.thingsboard.server.extensions.api.plugins.msg.ToDeviceRpcRequestPluginMsg; | |
26 | 24 | import org.thingsboard.server.extensions.api.plugins.msg.ToPluginRpcResponseDeviceMsg; |
27 | 25 | import org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg; |
28 | 26 | import org.thingsboard.server.gen.cluster.ClusterAPIProtos; |
... | ... | @@ -37,7 +35,7 @@ public interface ClusterRpcService { |
37 | 35 | |
38 | 36 | void init(RpcMsgListener listener); |
39 | 37 | |
40 | - void tell(ServerAddress serverAddress, ToDeviceActorMsg toForward); | |
38 | + void tell(ServerAddress serverAddress, DeviceToDeviceActorMsg toForward); | |
41 | 39 | |
42 | 40 | void tell(ServerAddress serverAddress, ToDeviceSessionActorMsg toForward); |
43 | 41 | ... | ... |
... | ... | @@ -20,18 +20,16 @@ import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg; |
20 | 20 | import org.thingsboard.server.actors.rpc.RpcSessionTellMsg; |
21 | 21 | import org.thingsboard.server.common.msg.cluster.ToAllNodesMsg; |
22 | 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 | 24 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
25 | 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 | 28 | * @author Andrew Shvayka |
31 | 29 | */ |
32 | 30 | public interface RpcMsgListener { |
33 | 31 | |
34 | - void onMsg(ToDeviceActorMsg msg); | |
32 | + void onMsg(DeviceToDeviceActorMsg msg); | |
35 | 33 | |
36 | 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 | 181 | |
182 | 182 | @Override |
183 | 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 | 227 | createDevice(demoTenant.getId(), null, DEFAULT_DEVICE_TYPE, "Raspberry Pi Demo Device", "RASPBERRY_PI_DEMO_TOKEN", "Demo device that is used in " + |
228 | 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 | 231 | // loadRules(Paths.get(dataDir, JSON_DIR, DEMO_DIR, RULES_DIR), demoTenant.getId()); |
232 | 232 | loadDashboards(Paths.get(dataDir, JSON_DIR, DEMO_DIR, DASHBOARDS_DIR), demoTenant.getId(), null); |
233 | 233 | } | ... | ... |
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.service.rpc; |
17 | 17 | |
18 | +import akka.actor.ActorRef; | |
18 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; |
19 | 20 | import lombok.extern.slf4j.Slf4j; |
20 | 21 | import org.springframework.beans.factory.annotation.Autowired; |
... | ... | @@ -105,7 +106,19 @@ public class DefaultDeviceRpcService implements DeviceRpcService { |
105 | 106 | } |
106 | 107 | |
107 | 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 | 120 | public void process(FromDeviceRpcResponse response) { |
121 | + //TODO: send to another server if needed. | |
109 | 122 | UUID requestId = response.getId(); |
110 | 123 | LocalRequestMetaData md = localRpcRequests.remove(requestId); |
111 | 124 | if (md != null) { | ... | ... |
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.rpc; |
17 | 17 | |
18 | 18 | import org.thingsboard.server.common.data.id.EntityId; |
19 | 19 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
20 | +import org.thingsboard.server.common.msg.cluster.ServerAddress; | |
20 | 21 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
21 | 22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
22 | 23 | import org.thingsboard.server.extensions.api.plugins.msg.RpcError; |
... | ... | @@ -31,6 +32,8 @@ public interface DeviceRpcService { |
31 | 32 | |
32 | 33 | void process(ToDeviceRpcRequest request, LocalRequestMetaData metaData); |
33 | 34 | |
35 | + void process(ToDeviceRpcRequest request, ServerAddress originator); | |
36 | + | |
34 | 37 | void process(FromDeviceRpcResponse response); |
35 | 38 | |
36 | 39 | void logRpcCall(SecurityUser user, EntityId entityId, ToDeviceRpcRequestBody body, boolean oneWay, Optional<RpcError> rpcError, Throwable e); | ... | ... |
... | ... | @@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; |
20 | 20 | import lombok.ToString; |
21 | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | +import org.thingsboard.server.common.msg.MsgType; | |
23 | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
24 | 25 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
25 | 26 | import org.thingsboard.server.extensions.api.device.ToDeviceActorNotificationMsg; |
... | ... | @@ -54,4 +55,9 @@ public class ToDeviceRpcRequestMsg implements ToDeviceActorNotificationMsg { |
54 | 55 | public TenantId getTenantId() { |
55 | 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 | 207 | sync: |
208 | 208 | # Default timeout for processing request using synchronous session (HTTP, CoAP) in milliseconds |
209 | 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 | 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 | 211 | # Specify thread pool size for database request callbacks executor service |
223 | 212 | db_callback_thread_pool_size: "${ACTORS_RULE_DB_CALLBACK_THREAD_POOL_SIZE:1}" |
224 | 213 | # Specify thread pool size for javascript executor service |
... | ... | @@ -235,6 +224,11 @@ actors: |
235 | 224 | # Enable/disable actor statistics |
236 | 225 | enabled: "${ACTORS_STATISTICS_ENABLED:true}" |
237 | 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 | 233 | cache: |
240 | 234 | # caffeine or redis | ... | ... |
... | ... | @@ -18,27 +18,30 @@ package org.thingsboard.server.common.msg; |
18 | 18 | /** |
19 | 19 | * Created by ashvayka on 15.03.18. |
20 | 20 | */ |
21 | +//TODO: add all "See" references | |
21 | 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 | 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 | 36 | COMPONENT_LIFE_CYCLE_MSG, |
29 | 37 | |
30 | 38 | /** |
31 | 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 | 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 | 46 | * Message that is sent by RuleChainActor to RuleActor with command to process TbMsg. |
44 | 47 | */ |
... | ... | @@ -59,4 +62,31 @@ public enum MsgType { |
59 | 62 | */ |
60 | 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 | 31 | @NoArgsConstructor |
32 | 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 | 36 | public TbMsgMetaData(Map<String, String> data) { |
37 | - this.data = data; | |
37 | + this.data.putAll(data); | |
38 | 38 | } |
39 | 39 | |
40 | 40 | public String getValue(String key) { | ... | ... |
... | ... | @@ -16,14 +16,20 @@ |
16 | 16 | package org.thingsboard.server.common.msg.cluster; |
17 | 17 | |
18 | 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 | 23 | * @author Andrew Shvayka |
22 | 24 | */ |
23 | 25 | @Data |
24 | -public final class ClusterEventMsg { | |
26 | +public final class ClusterEventMsg implements TbActorMsg { | |
25 | 27 | |
26 | 28 | private final ServerAddress serverAddress; |
27 | 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 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 22 | * @author Andrew Shvayka |
23 | 23 | */ |
24 | 24 | public class AttributesSubscribeMsg implements FromDeviceMsg { |
25 | 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 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 23 | * @author Andrew Shvayka |
23 | 24 | */ |
24 | 25 | public class AttributesUnsubscribeMsg implements FromDeviceMsg { |
25 | 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 | 17 | |
18 | 18 | import lombok.ToString; |
19 | 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 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
22 | 23 | |
23 | 24 | @ToString |
... | ... | @@ -36,9 +37,8 @@ public class AttributesUpdateNotification implements ToDeviceMsg { |
36 | 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 | 44 | public AttributesKVMsg getData() { | ... | ... |
... | ... | @@ -15,26 +15,27 @@ |
15 | 15 | */ |
16 | 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 | 21 | public class BasicCommandAckResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse { |
21 | 22 | |
22 | 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 | 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 | 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 | 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 | 41 | @Override | ... | ... |
... | ... | @@ -16,7 +16,8 @@ |
16 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 22 | import java.util.Collections; |
22 | 23 | import java.util.Optional; |
... | ... | @@ -41,8 +42,8 @@ public class BasicGetAttributesRequest extends BasicRequest implements GetAttrib |
41 | 42 | } |
42 | 43 | |
43 | 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 | 49 | @Override | ... | ... |
... | ... | @@ -17,23 +17,24 @@ package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 18 | import lombok.ToString; |
19 | 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 | 23 | @ToString |
23 | 24 | public class BasicGetAttributesResponse extends BasicResponseMsg<AttributesKVMsg> implements GetAttributesResponse { |
24 | 25 | |
25 | 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 | 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 | 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 | 18 | import java.io.Serializable; |
19 | 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 | 25 | public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> { |
25 | 26 | |
26 | 27 | private static final long serialVersionUID = 1L; |
27 | 28 | |
28 | - private final MsgType requestMsgType; | |
29 | + private final SessionMsgType requestMsgType; | |
29 | 30 | private final Integer requestId; |
30 | - private final MsgType msgType; | |
31 | + private final SessionMsgType sessionMsgType; | |
31 | 32 | private final boolean success; |
32 | 33 | private final T data; |
33 | 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 | 37 | super(); |
37 | 38 | this.requestMsgType = requestMsgType; |
38 | 39 | this.requestId = requestId; |
39 | - this.msgType = msgType; | |
40 | + this.sessionMsgType = sessionMsgType; | |
40 | 41 | this.success = success; |
41 | 42 | this.error = error; |
42 | 43 | this.data = data; |
43 | 44 | } |
44 | 45 | |
45 | 46 | @Override |
46 | - public MsgType getRequestMsgType() { | |
47 | + public SessionMsgType getRequestMsgType() { | |
47 | 48 | return requestMsgType; |
48 | 49 | } |
49 | 50 | |
... | ... | @@ -72,8 +73,7 @@ public class BasicResponseMsg<T extends Serializable> implements ResponseMsg<T> |
72 | 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 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 22 | @ToString |
22 | 23 | public class BasicStatusCodeResponse extends BasicResponseMsg<Integer> implements StatusCodeResponse { |
23 | 24 | |
24 | 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 | 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 | 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 | 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 | 21 | import java.util.Map; |
22 | 22 | |
23 | 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 | 27 | public class BasicTelemetryUploadRequest extends BasicRequest implements TelemetryUploadRequest { |
27 | 28 | |
... | ... | @@ -48,8 +49,8 @@ public class BasicTelemetryUploadRequest extends BasicRequest implements Telemet |
48 | 49 | } |
49 | 50 | |
50 | 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 | 56 | @Override | ... | ... |
... | ... | @@ -20,7 +20,8 @@ import java.util.LinkedHashSet; |
20 | 20 | import java.util.Set; |
21 | 21 | |
22 | 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 | 26 | public class BasicUpdateAttributesRequest extends BasicRequest implements UpdateAttributesRequest { |
26 | 27 | |
... | ... | @@ -46,8 +47,8 @@ public class BasicUpdateAttributesRequest extends BasicRequest implements Update |
46 | 47 | } |
47 | 48 | |
48 | 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 | 54 | @Override | ... | ... |
... | ... | @@ -18,12 +18,12 @@ package org.thingsboard.server.common.msg.core; |
18 | 18 | import java.io.Serializable; |
19 | 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 | 22 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
23 | 23 | |
24 | 24 | public interface ResponseMsg<T extends Serializable> extends ToDeviceMsg { |
25 | 25 | |
26 | - MsgType getRequestMsgType(); | |
26 | + SessionMsgType getRequestMsgType(); | |
27 | 27 | |
28 | 28 | Integer getRequestId(); |
29 | 29 | ... | ... |
... | ... | @@ -16,14 +16,15 @@ |
16 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 23 | * @author Andrew Shvayka |
23 | 24 | */ |
24 | 25 | public class RpcSubscribeMsg implements FromDeviceMsg { |
25 | 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 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 23 | * @author Andrew Shvayka |
23 | 24 | */ |
24 | 25 | public class RpcUnsubscribeMsg implements FromDeviceMsg { |
25 | 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 | 21 | |
22 | 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 | 26 | private final boolean critical; |
27 | 27 | ... | ... |
... | ... | @@ -16,7 +16,8 @@ |
16 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 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 | 26 | @Data |
26 | 27 | public class RuleEngineErrorMsg implements ToDeviceMsg { |
27 | 28 | |
28 | - private final MsgType inMsgType; | |
29 | + private final SessionMsgType inSessionMsgType; | |
29 | 30 | private final RuleEngineError error; |
30 | 31 | |
31 | 32 | @Override |
... | ... | @@ -33,9 +34,8 @@ public class RuleEngineErrorMsg implements ToDeviceMsg { |
33 | 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 | 41 | public String getErrorMsg() { |
... | ... | @@ -52,7 +52,7 @@ public class RuleEngineErrorMsg implements ToDeviceMsg { |
52 | 52 | return "Rule filters match, but no rule with two-way action configured!"; |
53 | 53 | case NO_RESPONSE_FROM_ACTIONS: |
54 | 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 | 56 | return "Timeout during processing of message by plugin!"; |
57 | 57 | default: |
58 | 58 | throw new RuntimeException("Error " + error + " is not supported!"); | ... | ... |
... | ... | @@ -16,14 +16,15 @@ |
16 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 23 | * @author Andrew Shvayka |
23 | 24 | */ |
24 | 25 | public class SessionCloseMsg implements FromDeviceMsg { |
25 | 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 | 17 | |
18 | 18 | import lombok.ToString; |
19 | 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 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
22 | 23 | |
23 | 24 | @ToString |
... | ... | @@ -30,9 +31,8 @@ public class SessionCloseNotification implements ToDeviceMsg { |
30 | 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 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 23 | * @author Andrew Shvayka |
23 | 24 | */ |
24 | 25 | public class SessionOpenMsg implements FromDeviceMsg { |
25 | 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 | 16 | package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 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 | 21 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
21 | 22 | |
22 | 23 | /** |
... | ... | @@ -29,9 +30,8 @@ public class ToDeviceRpcRequestMsg implements ToDeviceMsg { |
29 | 30 | private final String method; |
30 | 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 | 37 | @Override | ... | ... |
... | ... | @@ -17,7 +17,8 @@ package org.thingsboard.server.common.msg.core; |
17 | 17 | |
18 | 18 | import lombok.Data; |
19 | 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 | 24 | * @author Andrew Shvayka |
... | ... | @@ -29,7 +30,7 @@ public class ToDeviceRpcResponseMsg implements FromDeviceMsg { |
29 | 30 | private final String data; |
30 | 31 | |
31 | 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 | 17 | |
18 | 18 | import lombok.Data; |
19 | 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 | 23 | * @author Andrew Shvayka |
... | ... | @@ -30,7 +30,7 @@ public class ToServerRpcRequestMsg implements FromDeviceRequestMsg { |
30 | 30 | private final String params; |
31 | 31 | |
32 | 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 | 17 | |
18 | 18 | import lombok.Data; |
19 | 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 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
22 | 23 | |
23 | 24 | /** |
... | ... | @@ -29,9 +30,8 @@ public class ToServerRpcResponseMsg implements ToDeviceMsg { |
29 | 30 | private final int requestId; |
30 | 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 | 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 | 20 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | 21 | import org.thingsboard.server.common.data.id.SessionId; |
22 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | +import org.thingsboard.server.common.msg.MsgType; | |
23 | 24 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
24 | 25 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
25 | 26 | import org.thingsboard.server.common.msg.session.SessionType; |
... | ... | @@ -28,7 +29,7 @@ import org.thingsboard.server.common.msg.session.ToDeviceActorSessionMsg; |
28 | 29 | import java.util.Optional; |
29 | 30 | |
30 | 31 | @ToString |
31 | -public class BasicToDeviceActorMsg implements ToDeviceActorMsg { | |
32 | +public class BasicDeviceToDeviceActorMsg implements DeviceToDeviceActorMsg { | |
32 | 33 | |
33 | 34 | private static final long serialVersionUID = -1866795134993115408L; |
34 | 35 | |
... | ... | @@ -40,16 +41,16 @@ public class BasicToDeviceActorMsg implements ToDeviceActorMsg { |
40 | 41 | private final ServerAddress serverAddress; |
41 | 42 | private final FromDeviceMsg msg; |
42 | 43 | |
43 | - public BasicToDeviceActorMsg(ToDeviceActorMsg other, FromDeviceMsg msg) { | |
44 | + public BasicDeviceToDeviceActorMsg(DeviceToDeviceActorMsg other, FromDeviceMsg msg) { | |
44 | 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 | 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 | 54 | super(); |
54 | 55 | this.serverAddress = serverAddress; |
55 | 56 | this.tenantId = tenantId; |
... | ... | @@ -95,7 +96,12 @@ public class BasicToDeviceActorMsg implements ToDeviceActorMsg { |
95 | 96 | } |
96 | 97 | |
97 | 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 | 19 | import java.util.Optional; |
20 | 20 | |
21 | 21 | import org.thingsboard.server.common.data.id.SessionId; |
22 | +import org.thingsboard.server.common.msg.TbActorMsg; | |
22 | 23 | import org.thingsboard.server.common.msg.aware.CustomerAwareMsg; |
23 | 24 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
24 | 25 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; |
... | ... | @@ -26,7 +27,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; |
26 | 27 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
27 | 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 | 32 | SessionId getSessionId(); |
32 | 33 | |
... | ... | @@ -36,5 +37,5 @@ public interface ToDeviceActorMsg extends DeviceAwareMsg, CustomerAwareMsg, Tena |
36 | 37 | |
37 | 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 | 15 | */ |
16 | 16 | package org.thingsboard.server.common.msg.session; |
17 | 17 | |
18 | -public enum MsgType { | |
18 | +public enum SessionMsgType { | |
19 | 19 | GET_ATTRIBUTES_REQUEST(true), POST_ATTRIBUTES_REQUEST(true), GET_ATTRIBUTES_RESPONSE, |
20 | 20 | SUBSCRIBE_ATTRIBUTES_REQUEST, UNSUBSCRIBE_ATTRIBUTES_REQUEST, ATTRIBUTES_UPDATE_NOTIFICATION, |
21 | 21 | |
... | ... | @@ -32,11 +32,11 @@ public enum MsgType { |
32 | 32 | |
33 | 33 | private final boolean requiresRulesProcessing; |
34 | 34 | |
35 | - MsgType() { | |
35 | + SessionMsgType() { | |
36 | 36 | this(false); |
37 | 37 | } |
38 | 38 | |
39 | - MsgType(boolean requiresRulesProcessing) { | |
39 | + SessionMsgType(boolean requiresRulesProcessing) { | |
40 | 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 | 13 | * See the License for the specific language governing permissions and |
14 | 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 | 21 | import java.util.UUID; |
19 | 22 | |
20 | 23 | /** |
21 | 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 | 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 | 13 | * See the License for the specific language governing permissions and |
14 | 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 | 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 | 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 | 13 | * See the License for the specific language governing permissions and |
14 | 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 | 18 | import lombok.Data; |
19 | +import org.thingsboard.server.common.msg.TbActorMsg; | |
19 | 20 | |
20 | 21 | /** |
21 | 22 | * @author Andrew Shvayka |
22 | 23 | */ |
23 | 24 | @Data |
24 | -public class TimeoutMsg<T> { | |
25 | +public abstract class TimeoutMsg<T> implements TbActorMsg { | |
25 | 26 | private final T id; |
26 | 27 | private final long timeout; |
27 | 28 | } | ... | ... |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | package org.thingsboard.server.common.transport; |
17 | 17 | |
18 | 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 | 20 | import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg; |
21 | 21 | import org.thingsboard.server.common.msg.session.SessionContext; |
22 | 22 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
... | ... | @@ -25,7 +25,7 @@ import java.util.Optional; |
25 | 25 | |
26 | 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 | 30 | Optional<V> convertToAdaptorMsg(C ctx, SessionActorToAdaptorMsg msg) throws AdaptorException; |
31 | 31 | ... | ... |
... | ... | @@ -75,6 +75,8 @@ public class BaseRuleChainService extends AbstractEntityService implements RuleC |
75 | 75 | log.trace("Save system rule chain with predefined id {}", SYSTEM_TENANT); |
76 | 76 | ruleChain.setTenantId(SYSTEM_TENANT); |
77 | 77 | } |
78 | + //TODO: Temporary Hack to continue tests; | |
79 | + ruleChain.setRoot(true); | |
78 | 80 | RuleChain savedRuleChain = ruleChainDao.save(ruleChain); |
79 | 81 | if (ruleChain.isRoot() && ruleChain.getTenantId() != null && ruleChain.getId() == null) { |
80 | 82 | try { | ... | ... |
... | ... | @@ -22,6 +22,7 @@ import org.thingsboard.server.common.data.id.DeviceId; |
22 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | 23 | import org.thingsboard.server.common.data.kv.AttributeKey; |
24 | 24 | import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
25 | +import org.thingsboard.server.common.msg.MsgType; | |
25 | 26 | |
26 | 27 | import java.util.List; |
27 | 28 | import java.util.Set; |
... | ... | @@ -54,4 +55,8 @@ public class DeviceAttributesEventNotificationMsg implements ToDeviceActorNotifi |
54 | 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 | 21 | import org.thingsboard.server.common.data.id.DeviceId; |
22 | 22 | import org.thingsboard.server.common.data.id.TenantId; |
23 | 23 | import org.thingsboard.server.common.data.kv.AttributeKey; |
24 | +import org.thingsboard.server.common.msg.MsgType; | |
24 | 25 | |
25 | 26 | import java.util.Set; |
26 | 27 | |
... | ... | @@ -33,4 +34,8 @@ public class DeviceCredentialsUpdateNotificationMsg implements ToDeviceActorNoti |
33 | 34 | private final TenantId tenantId; |
34 | 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 | 19 | import lombok.Data; |
20 | 20 | import org.thingsboard.server.common.data.id.DeviceId; |
21 | 21 | import org.thingsboard.server.common.data.id.TenantId; |
22 | +import org.thingsboard.server.common.msg.MsgType; | |
22 | 23 | |
23 | 24 | @Data |
24 | 25 | @AllArgsConstructor |
... | ... | @@ -27,4 +28,9 @@ public class DeviceNameOrTypeUpdateMsg implements ToDeviceActorNotificationMsg { |
27 | 28 | private final DeviceId deviceId; |
28 | 29 | private final String deviceName; |
29 | 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 | 15 | */ |
16 | 16 | package org.thingsboard.server.extensions.api.device; |
17 | 17 | |
18 | +import org.thingsboard.server.common.msg.TbActorMsg; | |
18 | 19 | import org.thingsboard.server.common.msg.aware.DeviceAwareMsg; |
19 | 20 | import org.thingsboard.server.common.msg.aware.TenantAwareMsg; |
20 | 21 | |
... | ... | @@ -23,6 +24,6 @@ import java.io.Serializable; |
23 | 24 | /** |
24 | 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 | 21 | import org.thingsboard.server.extensions.api.plugins.handlers.*; |
22 | 22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
23 | 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 | 25 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
26 | 26 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
27 | 27 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ... | ... |
... | ... | @@ -21,7 +21,7 @@ import org.thingsboard.server.common.msg.cluster.ServerAddress; |
21 | 21 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
22 | 22 | import org.thingsboard.server.extensions.api.plugins.msg.FromDeviceRpcResponse; |
23 | 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 | 25 | import org.thingsboard.server.extensions.api.plugins.rest.PluginRestMsg; |
26 | 26 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
27 | 27 | import org.thingsboard.server.extensions.api.plugins.ws.msg.PluginWebsocketMsg; | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 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 | 19 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
20 | 20 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
21 | 21 | import org.thingsboard.server.extensions.api.plugins.msg.PluginToRuleMsg; |
... | ... | @@ -28,7 +28,7 @@ import java.util.Optional; |
28 | 28 | |
29 | 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 | 33 | Optional<ToDeviceMsg> convert(PluginToRuleMsg<?> response); |
34 | 34 | ... | ... |
... | ... | @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.relation.EntityRelation; |
25 | 25 | import org.thingsboard.server.common.data.rpc.ToDeviceRpcRequestBody; |
26 | 26 | import org.thingsboard.server.common.msg.cluster.ServerAddress; |
27 | 27 | import org.thingsboard.server.common.msg.rpc.ToDeviceRpcRequest; |
28 | +import org.thingsboard.server.common.msg.timeout.TimeoutMsg; | |
28 | 29 | import org.thingsboard.server.extensions.api.plugins.msg.*; |
29 | 30 | import org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg; |
30 | 31 | import org.thingsboard.server.extensions.api.plugins.ws.PluginWebsocketSessionRef; | ... | ... |
... | ... | @@ -18,7 +18,8 @@ package org.thingsboard.server.extensions.api.plugins.handlers; |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.thingsboard.server.common.data.id.RuleId; |
20 | 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 | 23 | import org.thingsboard.server.extensions.api.plugins.PluginContext; |
23 | 24 | import org.thingsboard.server.extensions.api.plugins.msg.GetAttributesRequestRuleToPluginMsg; |
24 | 25 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -56,8 +57,8 @@ public class DefaultRuleMsgHandler implements RuleMsgHandler { |
56 | 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 | 15 | */ |
16 | 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 | 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 | 23 | */ |
24 | 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 | */ |
16 | 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 | 19 | import org.thingsboard.server.extensions.api.component.ConfigurableComponent; |
20 | 20 | |
21 | -import javax.script.ScriptException; | |
22 | - | |
23 | 21 | /** |
24 | 22 | * @author Andrew Shvayka |
25 | 23 | */ |
26 | 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 | 20 | import org.apache.velocity.VelocityContext; |
21 | 21 | import org.apache.velocity.runtime.parser.ParseException; |
22 | 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 | 24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
25 | 25 | import org.thingsboard.server.extensions.api.component.Action; |
26 | 26 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
... | ... | @@ -74,7 +74,7 @@ public class SendMailAction extends SimpleRuleLifecycleComponent implements Plug |
74 | 74 | } |
75 | 75 | |
76 | 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 | 78 | String sendFlag = configuration.getSendFlag(); |
79 | 79 | if (StringUtils.isEmpty(sendFlag) || (Boolean) metadata.get(sendFlag).orElse(Boolean.FALSE)) { |
80 | 80 | VelocityContext context = VelocityUtils.createContext(metadata); |
... | ... | @@ -86,7 +86,7 @@ public class SendMailAction extends SimpleRuleLifecycleComponent implements Plug |
86 | 86 | bccTemplate.ifPresent(t -> builder.bcc(VelocityUtils.merge(t, context))); |
87 | 87 | subjectTemplate.ifPresent(t -> builder.subject(VelocityUtils.merge(t, context))); |
88 | 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 | 90 | builder.build())); |
91 | 91 | } else { |
92 | 92 | return Optional.empty(); | ... | ... |
extensions-core/src/main/java/org/thingsboard/server/extensions/core/action/rpc/RpcPluginAction.java
... | ... | @@ -16,9 +16,10 @@ |
16 | 16 | package org.thingsboard.server.extensions.core.action.rpc; |
17 | 17 | |
18 | 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 | 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 | 23 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
23 | 24 | import org.thingsboard.server.extensions.api.component.Action; |
24 | 25 | import org.thingsboard.server.extensions.api.component.EmptyComponentConfiguration; |
... | ... | @@ -41,12 +42,12 @@ public class RpcPluginAction extends SimpleRuleLifecycleComponent implements Plu |
41 | 42 | } |
42 | 43 | |
43 | 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 | 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 | 51 | } else { |
51 | 52 | return Optional.empty(); |
52 | 53 | } | ... | ... |
... | ... | @@ -20,7 +20,7 @@ import org.apache.velocity.Template; |
20 | 20 | import org.apache.velocity.VelocityContext; |
21 | 21 | import org.apache.velocity.runtime.parser.ParseException; |
22 | 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 | 24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
25 | 25 | import org.thingsboard.server.extensions.api.component.Action; |
26 | 26 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
... | ... | @@ -64,7 +64,7 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem |
64 | 64 | } |
65 | 65 | |
66 | 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 | 68 | String sendFlag = configuration.getSendFlag(); |
69 | 69 | if (StringUtils.isEmpty(sendFlag) || (Boolean) metadata.get(sendFlag).orElse(Boolean.FALSE)) { |
70 | 70 | VelocityContext context = VelocityUtils.createContext(metadata); |
... | ... | @@ -77,7 +77,7 @@ public class ServerSideRpcCallAction extends SimpleRuleLifecycleComponent implem |
77 | 77 | rpcCallMethodTemplate.ifPresent(t -> builder.rpcCallMethod(VelocityUtils.merge(t, context))); |
78 | 78 | rpcCallBodyTemplate.ifPresent(t -> builder.rpcCallBody(VelocityUtils.merge(t, context))); |
79 | 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 | 81 | builder.build())); |
82 | 82 | } else { |
83 | 83 | return Optional.empty(); | ... | ... |
... | ... | @@ -19,9 +19,10 @@ import org.springframework.util.StringUtils; |
19 | 19 | import org.thingsboard.server.common.msg.core.GetAttributesRequest; |
20 | 20 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
21 | 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 | 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 | 26 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
26 | 27 | import org.thingsboard.server.extensions.api.component.Action; |
27 | 28 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
... | ... | @@ -50,20 +51,20 @@ public class TelemetryPluginAction extends SimpleRuleLifecycleComponent implemen |
50 | 51 | } |
51 | 52 | |
52 | 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 | 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 | 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 | 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 | 68 | } else { |
68 | 69 | return Optional.empty(); |
69 | 70 | } | ... | ... |
... | ... | @@ -19,7 +19,7 @@ import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.apache.velocity.Template; |
20 | 20 | import org.apache.velocity.VelocityContext; |
21 | 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 | 23 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
24 | 24 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
25 | 25 | import org.thingsboard.server.extensions.api.plugins.PluginAction; |
... | ... | @@ -52,7 +52,7 @@ public abstract class AbstractTemplatePluginAction<T extends TemplateActionConfi |
52 | 52 | } |
53 | 53 | |
54 | 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 | 56 | FromDeviceRequestMsg payload; |
57 | 57 | if (msg.getPayload() instanceof FromDeviceRequestMsg) { |
58 | 58 | payload = (FromDeviceRequestMsg) msg.getPayload(); |
... | ... | @@ -70,14 +70,14 @@ public abstract class AbstractTemplatePluginAction<T extends TemplateActionConfi |
70 | 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 | 74 | log.trace("Creating context for: {} and payload {}", ctx.getDeviceMetaData(), msg.getPayload()); |
75 | 75 | VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg.getPayload()); |
76 | 76 | return VelocityUtils.merge(template, context); |
77 | 77 | } |
78 | 78 | |
79 | 79 | abstract protected Optional<RuleToPluginMsg> buildRuleToPluginMsg(RuleContext ctx, |
80 | - ToDeviceActorMsg msg, | |
80 | + DeviceToDeviceActorMsg msg, | |
81 | 81 | FromDeviceRequestMsg payload); |
82 | 82 | |
83 | 83 | @Override | ... | ... |
... | ... | @@ -16,8 +16,7 @@ |
16 | 16 | package org.thingsboard.server.extensions.core.filter; |
17 | 17 | |
18 | 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 | 20 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
22 | 21 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
23 | 22 | |
... | ... | @@ -39,7 +38,7 @@ public abstract class BasicJsFilter implements RuleFilter<JsFilterConfiguration> |
39 | 38 | } |
40 | 39 | |
41 | 40 | @Override |
42 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | |
41 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { | |
43 | 42 | try { |
44 | 43 | return doFilter(ctx, msg); |
45 | 44 | } catch (ScriptException e) { |
... | ... | @@ -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 | 52 | @Override |
54 | 53 | public void resume() { | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.core.filter; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 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 | 21 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
22 | 22 | import org.thingsboard.server.extensions.api.component.Filter; |
23 | 23 | import org.thingsboard.server.extensions.api.device.DeviceAttributes; |
... | ... | @@ -34,7 +34,7 @@ import javax.script.ScriptException; |
34 | 34 | public class DeviceAttributesFilter extends BasicJsFilter { |
35 | 35 | |
36 | 36 | @Override |
37 | - protected boolean doFilter(RuleContext ctx, ToDeviceActorMsg msg) throws ScriptException { | |
37 | + protected boolean doFilter(RuleContext ctx, DeviceToDeviceActorMsg msg) throws ScriptException { | |
38 | 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 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.thingsboard.server.common.data.kv.KvEntry; |
20 | 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 | 22 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
23 | 23 | import org.thingsboard.server.extensions.api.component.Filter; |
24 | 24 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
... | ... | @@ -34,7 +34,7 @@ import java.util.List; |
34 | 34 | public class DeviceTelemetryFilter extends BasicJsFilter { |
35 | 35 | |
36 | 36 | @Override |
37 | - protected boolean doFilter(RuleContext ctx, ToDeviceActorMsg msg) throws ScriptException { | |
37 | + protected boolean doFilter(RuleContext ctx, DeviceToDeviceActorMsg msg) throws ScriptException { | |
38 | 38 | FromDeviceMsg deviceMsg = msg.getPayload(); |
39 | 39 | if (deviceMsg instanceof TelemetryUploadRequest) { |
40 | 40 | TelemetryUploadRequest telemetryMsg = (TelemetryUploadRequest) deviceMsg; | ... | ... |
... | ... | @@ -16,8 +16,7 @@ |
16 | 16 | package org.thingsboard.server.extensions.core.filter; |
17 | 17 | |
18 | 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 | 20 | import org.thingsboard.server.extensions.api.component.Filter; |
22 | 21 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | 22 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
... | ... | @@ -27,8 +26,6 @@ import java.util.Arrays; |
27 | 26 | import java.util.Set; |
28 | 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 | 30 | * @author Andrew Shvayka |
34 | 31 | */ |
... | ... | @@ -46,7 +43,7 @@ public class DeviceTypeFilter extends SimpleRuleLifecycleComponent implements Ru |
46 | 43 | } |
47 | 44 | |
48 | 45 | @Override |
49 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | |
46 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { | |
50 | 47 | return deviceTypes.contains(ctx.getDeviceMetaData().getDeviceType()); |
51 | 48 | } |
52 | 49 | } | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.core.filter; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 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 | 21 | import org.thingsboard.server.extensions.api.component.Filter; |
22 | 22 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | 23 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
... | ... | @@ -27,7 +27,7 @@ import java.util.Arrays; |
27 | 27 | import java.util.Set; |
28 | 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 | 33 | * @author Andrew Shvayka |
... | ... | @@ -46,7 +46,7 @@ public class MethodNameFilter extends SimpleRuleLifecycleComponent implements Ru |
46 | 46 | } |
47 | 47 | |
48 | 48 | @Override |
49 | - public boolean filter(RuleContext ctx, ToDeviceActorMsg msg) { | |
49 | + public boolean filter(RuleContext ctx, DeviceToDeviceActorMsg msg) { | |
50 | 50 | if (msg.getPayload().getMsgType() == TO_SERVER_RPC_REQUEST) { |
51 | 51 | return methods.contains(((ToServerRpcRequestMsg) msg.getPayload()).getMethod()); |
52 | 52 | } else { | ... | ... |
... | ... | @@ -16,8 +16,9 @@ |
16 | 16 | package org.thingsboard.server.extensions.core.filter; |
17 | 17 | |
18 | 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 | 22 | import org.thingsboard.server.extensions.api.component.Filter; |
22 | 23 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | 24 | import org.thingsboard.server.extensions.api.rules.RuleFilter; |
... | ... | @@ -35,30 +36,30 @@ import java.util.stream.Collectors; |
35 | 36 | @Slf4j |
36 | 37 | public class MsgTypeFilter extends SimpleRuleLifecycleComponent implements RuleFilter<MsgTypeFilterConfiguration> { |
37 | 38 | |
38 | - private List<MsgType> msgTypes; | |
39 | + private List<SessionMsgType> sessionMsgTypes; | |
39 | 40 | |
40 | 41 | @Override |
41 | 42 | public void init(MsgTypeFilterConfiguration configuration) { |
42 | - msgTypes = Arrays.stream(configuration.getMessageTypes()).map(type -> { | |
43 | + sessionMsgTypes = Arrays.stream(configuration.getMessageTypes()).map(type -> { | |
43 | 44 | switch (type) { |
44 | 45 | case "GET_ATTRIBUTES": |
45 | - return MsgType.GET_ATTRIBUTES_REQUEST; | |
46 | + return SessionMsgType.GET_ATTRIBUTES_REQUEST; | |
46 | 47 | case "POST_ATTRIBUTES": |
47 | - return MsgType.POST_ATTRIBUTES_REQUEST; | |
48 | + return SessionMsgType.POST_ATTRIBUTES_REQUEST; | |
48 | 49 | case "POST_TELEMETRY": |
49 | - return MsgType.POST_TELEMETRY_REQUEST; | |
50 | + return SessionMsgType.POST_TELEMETRY_REQUEST; | |
50 | 51 | case "RPC_REQUEST": |
51 | - return MsgType.TO_SERVER_RPC_REQUEST; | |
52 | + return SessionMsgType.TO_SERVER_RPC_REQUEST; | |
52 | 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 | 56 | }).collect(Collectors.toList()); |
56 | 57 | } |
57 | 58 | |
58 | 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 | 63 | return true; |
63 | 64 | } |
64 | 65 | } | ... | ... |
... | ... | @@ -22,7 +22,7 @@ import org.apache.velocity.VelocityContext; |
22 | 22 | import org.apache.velocity.runtime.parser.ParseException; |
23 | 23 | import org.thingsboard.server.common.data.DataConstants; |
24 | 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 | 26 | import org.thingsboard.server.extensions.api.component.Processor; |
27 | 27 | import org.thingsboard.server.extensions.api.rules.*; |
28 | 28 | import org.thingsboard.server.extensions.core.utils.VelocityUtils; |
... | ... | @@ -57,7 +57,7 @@ public class AlarmDeduplicationProcessor extends SimpleRuleLifecycleComponent |
57 | 57 | } |
58 | 58 | |
59 | 59 | @Override |
60 | - public RuleProcessingMetaData process(RuleContext ctx, ToDeviceActorMsg msg) throws RuleException { | |
60 | + public RuleProcessingMetaData process(RuleContext ctx, DeviceToDeviceActorMsg msg) throws RuleException { | |
61 | 61 | RuleProcessingMetaData md = new RuleProcessingMetaData(); |
62 | 62 | VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg.getPayload()); |
63 | 63 | String alarmId = VelocityUtils.merge(alarmIdTemplate, context); | ... | ... |
... | ... | @@ -27,7 +27,7 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus; |
27 | 27 | import org.thingsboard.server.common.data.kv.KvEntry; |
28 | 28 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
29 | 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 | 31 | import org.thingsboard.server.common.msg.session.FromDeviceMsg; |
32 | 32 | import org.thingsboard.server.extensions.api.component.Processor; |
33 | 33 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
... | ... | @@ -102,7 +102,7 @@ public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration |
102 | 102 | } |
103 | 103 | |
104 | 104 | @Override |
105 | - public RuleProcessingMetaData process(RuleContext ctx, ToDeviceActorMsg wrapper) throws RuleException { | |
105 | + public RuleProcessingMetaData process(RuleContext ctx, DeviceToDeviceActorMsg wrapper) throws RuleException { | |
106 | 106 | RuleProcessingMetaData md = new RuleProcessingMetaData(); |
107 | 107 | |
108 | 108 | FromDeviceMsg msg = wrapper.getPayload(); | ... | ... |
... | ... | @@ -17,7 +17,8 @@ package org.thingsboard.server.extensions.kafka.action; |
17 | 17 | |
18 | 18 | import lombok.Builder; |
19 | 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 | 23 | import java.io.Serializable; |
23 | 24 | |
... | ... | @@ -30,5 +31,5 @@ public class KafkaActionPayload implements Serializable { |
30 | 31 | private final boolean sync; |
31 | 32 | |
32 | 33 | private final Integer requestId; |
33 | - private final MsgType msgType; | |
34 | + private final SessionMsgType sessionMsgType; | |
34 | 35 | } | ... | ... |
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | package org.thingsboard.server.extensions.kafka.action; |
17 | 17 | |
18 | 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 | 20 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
21 | 21 | import org.thingsboard.server.extensions.api.component.Action; |
22 | 22 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -30,7 +30,7 @@ import java.util.Optional; |
30 | 30 | public class KafkaPluginAction extends AbstractTemplatePluginAction<KafkaPluginActionConfiguration> { |
31 | 31 | |
32 | 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 | 34 | KafkaActionPayload.KafkaActionPayloadBuilder builder = KafkaActionPayload.builder(); |
35 | 35 | builder.msgType(payload.getMsgType()); |
36 | 36 | builder.requestId(payload.getRequestId()); | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.mqtt.action; |
17 | 17 | |
18 | 18 | import lombok.Builder; |
19 | 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 | 22 | import java.io.Serializable; |
23 | 23 | |
... | ... | @@ -30,5 +30,5 @@ public class MqttActionPayload implements Serializable { |
30 | 30 | private final String msgBody; |
31 | 31 | |
32 | 32 | private final Integer requestId; |
33 | - private final MsgType msgType; | |
33 | + private final SessionMsgType sessionMsgType; | |
34 | 34 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 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 | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -28,7 +28,7 @@ import java.util.Optional; |
28 | 28 | public class MqttPluginAction extends AbstractTemplatePluginAction<MqttPluginActionConfiguration> { |
29 | 29 | |
30 | 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 | 32 | MqttActionPayload.MqttActionPayloadBuilder builder = MqttActionPayload.builder(); |
33 | 33 | builder.sync(configuration.isSync()); |
34 | 34 | builder.msgType(payload.getMsgType()); | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.rabbitmq.action; |
17 | 17 | |
18 | 18 | import lombok.Builder; |
19 | 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 | 22 | import java.io.Serializable; |
23 | 23 | |
... | ... | @@ -35,5 +35,5 @@ public class RabbitMqActionPayload implements Serializable { |
35 | 35 | |
36 | 36 | private final boolean sync; |
37 | 37 | private final Integer requestId; |
38 | - private final MsgType msgType; | |
38 | + private final SessionMsgType sessionMsgType; | |
39 | 39 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 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 | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -32,7 +32,7 @@ import java.util.Optional; |
32 | 32 | public class RabbitMqPluginAction extends AbstractTemplatePluginAction<RabbitMqPluginActionConfiguration> { |
33 | 33 | |
34 | 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 | 36 | RabbitMqActionPayload.RabbitMqActionPayloadBuilder builder = RabbitMqActionPayload.builder(); |
37 | 37 | builder.sync(configuration.isSync()); |
38 | 38 | builder.exchange(configuration.getExchange()); | ... | ... |
... | ... | @@ -19,7 +19,8 @@ import lombok.Builder; |
19 | 19 | import lombok.Data; |
20 | 20 | import org.springframework.http.HttpMethod; |
21 | 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 | 25 | import java.io.Serializable; |
25 | 26 | |
... | ... | @@ -33,5 +34,5 @@ public class RestApiCallActionPayload implements Serializable { |
33 | 34 | private final boolean sync; |
34 | 35 | |
35 | 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 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | 19 | import org.springframework.http.HttpMethod; |
20 | 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 | 22 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
23 | 23 | import org.thingsboard.server.extensions.api.component.Action; |
24 | 24 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -33,7 +33,7 @@ import java.util.Optional; |
33 | 33 | public class RestApiCallPluginAction extends AbstractTemplatePluginAction<RestApiCallPluginActionConfiguration> { |
34 | 34 | |
35 | 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 | 37 | RestApiCallActionPayload.RestApiCallActionPayloadBuilder builder = RestApiCallActionPayload.builder(); |
38 | 38 | builder.msgType(payload.getMsgType()); |
39 | 39 | builder.requestId(payload.getRequestId()); | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.sns.action; |
17 | 17 | |
18 | 18 | import lombok.Builder; |
19 | 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 | 22 | import java.io.Serializable; |
23 | 23 | |
... | ... | @@ -32,6 +32,6 @@ public class SnsTopicActionPayload implements Serializable { |
32 | 32 | private final String msgBody; |
33 | 33 | |
34 | 34 | private final Integer requestId; |
35 | - private final MsgType msgType; | |
35 | + private final SessionMsgType sessionMsgType; | |
36 | 36 | private final boolean sync; |
37 | 37 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 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 | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -31,7 +31,7 @@ import java.util.Optional; |
31 | 31 | public class SnsTopicPluginAction extends AbstractTemplatePluginAction<SnsTopicPluginActionConfiguration> { |
32 | 32 | |
33 | 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 | 35 | SnsTopicActionPayload.SnsTopicActionPayloadBuilder builder = SnsTopicActionPayload.builder(); |
36 | 36 | builder.msgType(payload.getMsgType()); |
37 | 37 | builder.requestId(payload.getRequestId()); | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.extensions.sqs.action.fifo; |
17 | 17 | |
18 | 18 | import lombok.Builder; |
19 | 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 | 22 | import java.io.Serializable; |
23 | 23 | |
... | ... | @@ -33,7 +33,7 @@ public class SqsFifoQueueActionPayload implements Serializable { |
33 | 33 | private final String deviceId; |
34 | 34 | |
35 | 35 | private final Integer requestId; |
36 | - private final MsgType msgType; | |
36 | + private final SessionMsgType sessionMsgType; | |
37 | 37 | private final boolean sync; |
38 | 38 | |
39 | 39 | } | ... | ... |
... | ... | @@ -15,15 +15,12 @@ |
15 | 15 | */ |
16 | 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 | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
22 | 22 | import org.thingsboard.server.extensions.api.rules.RuleContext; |
23 | 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 | 25 | import java.util.Optional; |
29 | 26 | |
... | ... | @@ -34,7 +31,7 @@ import java.util.Optional; |
34 | 31 | public class SqsFifoQueuePluginAction extends AbstractTemplatePluginAction<SqsFifoQueuePluginActionConfiguration> { |
35 | 32 | |
36 | 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 | 35 | SqsFifoQueueActionPayload.SqsFifoQueueActionPayloadBuilder builder = SqsFifoQueueActionPayload.builder(); |
39 | 36 | builder.msgType(payload.getMsgType()); |
40 | 37 | builder.requestId(payload.getRequestId()); | ... | ... |
... | ... | @@ -17,7 +17,8 @@ package org.thingsboard.server.extensions.sqs.action.standard; |
17 | 17 | |
18 | 18 | import lombok.Builder; |
19 | 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 | 23 | import java.io.Serializable; |
23 | 24 | |
... | ... | @@ -33,7 +34,7 @@ public class SqsStandardQueueActionPayload implements Serializable { |
33 | 34 | private final int delaySeconds; |
34 | 35 | |
35 | 36 | private final Integer requestId; |
36 | - private final MsgType msgType; | |
37 | + private final SessionMsgType sessionMsgType; | |
37 | 38 | private final boolean sync; |
38 | 39 | |
39 | 40 | } | ... | ... |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | */ |
16 | 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 | 19 | import org.thingsboard.server.common.msg.session.FromDeviceRequestMsg; |
20 | 20 | import org.thingsboard.server.extensions.api.component.Action; |
21 | 21 | import org.thingsboard.server.extensions.api.plugins.msg.RuleToPluginMsg; |
... | ... | @@ -31,7 +31,7 @@ import java.util.Optional; |
31 | 31 | public class SqsStandardQueuePluginAction extends AbstractTemplatePluginAction<SqsStandardQueuePluginActionConfiguration> { |
32 | 32 | |
33 | 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 | 35 | SqsStandardQueueActionPayload.SqsStandardQueueActionPayloadBuilder builder = SqsStandardQueueActionPayload.builder(); |
36 | 36 | builder.msgType(payload.getMsgType()); |
37 | 37 | builder.requestId(payload.getRequestId()); | ... | ... |
... | ... | @@ -65,7 +65,7 @@ public class SqsMessageHandler implements RuleMsgHandler { |
65 | 65 | sqs.sendMessage(sendMsgRequest); |
66 | 66 | if (payload.isSync()) { |
67 | 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 | 28 | import org.thingsboard.server.common.data.kv.KvEntry; |
29 | 29 | import org.thingsboard.server.common.data.kv.TsKvEntry; |
30 | 30 | import org.thingsboard.server.common.data.plugin.ComponentType; |
31 | +import org.thingsboard.server.common.msg.MsgType; | |
31 | 32 | import org.thingsboard.server.common.msg.TbMsg; |
32 | 33 | import org.thingsboard.server.common.msg.core.TelemetryUploadRequest; |
34 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | |
33 | 35 | import org.thingsboard.server.common.transport.adaptor.JsonConverter; |
34 | 36 | |
35 | 37 | import java.nio.charset.StandardCharsets; |
... | ... | @@ -59,7 +61,7 @@ public class TbMsgTelemetryNode implements TbNode { |
59 | 61 | |
60 | 62 | @Override |
61 | 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 | 65 | ctx.tellError(msg, new IllegalArgumentException("Unsupported msg type: " + msg.getType())); |
64 | 66 | return; |
65 | 67 | } | ... | ... |
... | ... | @@ -90,7 +90,7 @@ public class CoapTransportResource extends CoapResource { |
90 | 90 | } else if (exchange.getRequestOptions().hasObserve()) { |
91 | 91 | processExchangeGetRequest(exchange, featureType.get()); |
92 | 92 | } else if (featureType.get() == FeatureType.ATTRIBUTES) { |
93 | - processRequest(exchange, MsgType.GET_ATTRIBUTES_REQUEST); | |
93 | + processRequest(exchange, SessionMsgType.GET_ATTRIBUTES_REQUEST); | |
94 | 94 | } else { |
95 | 95 | log.trace("Invalid feature type parameter"); |
96 | 96 | exchange.respond(ResponseCode.BAD_REQUEST); |
... | ... | @@ -99,13 +99,13 @@ public class CoapTransportResource extends CoapResource { |
99 | 99 | |
100 | 100 | private void processExchangeGetRequest(CoapExchange exchange, FeatureType featureType) { |
101 | 101 | boolean unsubscribe = exchange.getRequestOptions().getObserve() == 1; |
102 | - MsgType msgType; | |
102 | + SessionMsgType sessionMsgType; | |
103 | 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 | 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 | 109 | if (sessionId.isPresent()) { |
110 | 110 | if (exchange.getRequestOptions().getObserve() == 1) { |
111 | 111 | exchange.respond(ResponseCode.VALID); |
... | ... | @@ -122,24 +122,24 @@ public class CoapTransportResource extends CoapResource { |
122 | 122 | } else { |
123 | 123 | switch (featureType.get()) { |
124 | 124 | case ATTRIBUTES: |
125 | - processRequest(exchange, MsgType.POST_ATTRIBUTES_REQUEST); | |
125 | + processRequest(exchange, SessionMsgType.POST_ATTRIBUTES_REQUEST); | |
126 | 126 | break; |
127 | 127 | case TELEMETRY: |
128 | - processRequest(exchange, MsgType.POST_TELEMETRY_REQUEST); | |
128 | + processRequest(exchange, SessionMsgType.POST_TELEMETRY_REQUEST); | |
129 | 129 | break; |
130 | 130 | case RPC: |
131 | 131 | Optional<Integer> requestId = getRequestId(exchange.advanced().getRequest()); |
132 | 132 | if (requestId.isPresent()) { |
133 | - processRequest(exchange, MsgType.TO_DEVICE_RPC_RESPONSE); | |
133 | + processRequest(exchange, SessionMsgType.TO_DEVICE_RPC_RESPONSE); | |
134 | 134 | } else { |
135 | - processRequest(exchange, MsgType.TO_SERVER_RPC_REQUEST); | |
135 | + processRequest(exchange, SessionMsgType.TO_SERVER_RPC_REQUEST); | |
136 | 136 | } |
137 | 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 | 143 | log.trace("Processing {}", exchange.advanced().getRequest()); |
144 | 144 | exchange.accept(); |
145 | 145 | Exchange advanced = exchange.advanced(); | ... | ... |
... | ... | @@ -28,9 +28,10 @@ import org.thingsboard.server.common.msg.kv.AttributesKVMsg; |
28 | 28 | import org.thingsboard.server.common.msg.session.AdaptorToSessionActorMsg; |
29 | 29 | import org.thingsboard.server.common.msg.session.BasicAdaptorToSessionActorMsg; |
30 | 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 | 32 | import org.thingsboard.server.common.msg.session.SessionActorToAdaptorMsg; |
33 | 33 | import org.thingsboard.server.common.msg.session.SessionContext; |
34 | +import org.thingsboard.server.common.msg.session.SessionMsgType; | |
34 | 35 | import org.thingsboard.server.common.msg.session.ToDeviceMsg; |
35 | 36 | import org.thingsboard.server.common.msg.session.ex.ProcessingTimeoutException; |
36 | 37 | import org.thingsboard.server.common.transport.adaptor.AdaptorException; |
... | ... | @@ -48,7 +49,7 @@ import org.thingsboard.server.transport.coap.session.CoapSessionCtx; |
48 | 49 | public class JsonCoapAdaptor implements CoapTransportAdaptor { |
49 | 50 | |
50 | 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 | 53 | FromDeviceMsg msg = null; |
53 | 54 | switch (type) { |
54 | 55 | case POST_TELEMETRY_REQUEST: |
... | ... | @@ -104,7 +105,7 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { |
104 | 105 | @Override |
105 | 106 | public Optional<Response> convertToAdaptorMsg(CoapSessionCtx ctx, SessionActorToAdaptorMsg source) throws AdaptorException { |
106 | 107 | ToDeviceMsg msg = source.getMsg(); |
107 | - switch (msg.getMsgType()) { | |
108 | + switch (msg.getSessionMsgType()) { | |
108 | 109 | case STATUS_CODE_RESPONSE: |
109 | 110 | case TO_DEVICE_RPC_RESPONSE_ACK: |
110 | 111 | return Optional.of(convertStatusCodeResponse((StatusCodeResponse) msg)); |
... | ... | @@ -119,19 +120,19 @@ public class JsonCoapAdaptor implements CoapTransportAdaptor { |
119 | 120 | case RULE_ENGINE_ERROR: |
120 | 121 | return Optional.of(convertToRuleEngineErrorResponse(ctx, (RuleEngineErrorMsg) msg)); |
121 | 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 | 128 | private Response convertToRuleEngineErrorResponse(CoapSessionCtx ctx, RuleEngineErrorMsg msg) { |
128 | 129 | ResponseCode status = ResponseCode.INTERNAL_SERVER_ERROR; |
129 | 130 | switch (msg.getError()) { |
130 | - case PLUGIN_TIMEOUT: | |
131 | + case QUEUE_PUT_TIMEOUT: | |
131 | 132 | status = ResponseCode.GATEWAY_TIMEOUT; |
132 | 133 | break; |
133 | 134 | default: |
134 | - if (msg.getInMsgType() == MsgType.TO_SERVER_RPC_REQUEST) { | |
135 | + if (msg.getInSessionMsgType() == SessionMsgType.TO_SERVER_RPC_REQUEST) { | |
135 | 136 | status = ResponseCode.BAD_REQUEST; |
136 | 137 | } |
137 | 138 | break; | ... | ... |
... | ... | @@ -113,9 +113,9 @@ public class CoapServerTest { |
113 | 113 | try { |
114 | 114 | FromDeviceMsg deviceMsg = sessionMsg.getMsg(); |
115 | 115 | ToDeviceMsg toDeviceMsg = null; |
116 | - if (deviceMsg.getMsgType() == MsgType.POST_TELEMETRY_REQUEST) { | |
116 | + if (deviceMsg.getMsgType() == SessionMsgType.POST_TELEMETRY_REQUEST) { | |
117 | 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 | 119 | List<AttributeKvEntry> data = new ArrayList<>(); |
120 | 120 | data.add(new BaseAttributeKvEntry(new StringDataEntry("key1", "value1"), System.currentTimeMillis())); |
121 | 121 | data.add(new BaseAttributeKvEntry(new LongDataEntry("key2", 42L), System.currentTimeMillis())); | ... | ... |
... | ... | @@ -57,7 +57,7 @@ public class HttpSessionCtx extends DeviceAwareSessionContext { |
57 | 57 | @Override |
58 | 58 | public void onMsg(SessionActorToAdaptorMsg source) throws SessionException { |
59 | 59 | ToDeviceMsg msg = source.getMsg(); |
60 | - switch (msg.getMsgType()) { | |
60 | + switch (msg.getSessionMsgType()) { | |
61 | 61 | case GET_ATTRIBUTES_RESPONSE: |
62 | 62 | reply((GetAttributesResponse) msg); |
63 | 63 | return; |
... | ... | @@ -84,11 +84,11 @@ public class HttpSessionCtx extends DeviceAwareSessionContext { |
84 | 84 | private void reply(RuleEngineErrorMsg msg) { |
85 | 85 | HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR; |
86 | 86 | switch (msg.getError()) { |
87 | - case PLUGIN_TIMEOUT: | |
87 | + case QUEUE_PUT_TIMEOUT: | |
88 | 88 | status = HttpStatus.REQUEST_TIMEOUT; |
89 | 89 | break; |
90 | 90 | default: |
91 | - if (msg.getInMsgType() == MsgType.TO_SERVER_RPC_REQUEST) { | |
91 | + if (msg.getInSessionMsgType() == SessionMsgType.TO_SERVER_RPC_REQUEST) { | |
92 | 92 | status = HttpStatus.BAD_REQUEST; |
93 | 93 | } |
94 | 94 | break; | ... | ... |
... | ... | @@ -53,7 +53,7 @@ import java.util.List; |
53 | 53 | import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*; |
54 | 54 | import static io.netty.handler.codec.mqtt.MqttMessageType.*; |
55 | 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 | 57 | import static org.thingsboard.server.transport.mqtt.MqttTopics.*; |
58 | 58 | |
59 | 59 | /** | ... | ... |
... | ... | @@ -53,7 +53,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { |
53 | 53 | private static final ByteBufAllocator ALLOCATOR = new UnpooledByteBufAllocator(false); |
54 | 54 | |
55 | 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 | 57 | FromDeviceMsg msg; |
58 | 58 | switch (type) { |
59 | 59 | case POST_TELEMETRY_REQUEST: |
... | ... | @@ -94,7 +94,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { |
94 | 94 | public Optional<MqttMessage> convertToAdaptorMsg(DeviceSessionCtx ctx, SessionActorToAdaptorMsg sessionMsg) throws AdaptorException { |
95 | 95 | MqttMessage result = null; |
96 | 96 | ToDeviceMsg msg = sessionMsg.getMsg(); |
97 | - switch (msg.getMsgType()) { | |
97 | + switch (msg.getSessionMsgType()) { | |
98 | 98 | case STATUS_CODE_RESPONSE: |
99 | 99 | case GET_ATTRIBUTES_RESPONSE: |
100 | 100 | ResponseMsg<?> responseMsg = (ResponseMsg) msg; |
... | ... | @@ -134,12 +134,12 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { |
134 | 134 | private MqttMessage convertResponseMsg(DeviceSessionCtx ctx, ToDeviceMsg msg, |
135 | 135 | ResponseMsg<?> responseMsg, Optional<Exception> responseError) throws AdaptorException { |
136 | 136 | MqttMessage result = null; |
137 | - MsgType requestMsgType = responseMsg.getRequestMsgType(); | |
137 | + SessionMsgType requestMsgType = responseMsg.getRequestMsgType(); | |
138 | 138 | Integer requestId = responseMsg.getRequestId(); |
139 | 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 | 141 | result = MqttTransportHandler.createMqttPubAckMsg(requestId); |
142 | - } else if (requestMsgType == MsgType.GET_ATTRIBUTES_REQUEST) { | |
142 | + } else if (requestMsgType == SessionMsgType.GET_ATTRIBUTES_REQUEST) { | |
143 | 143 | GetAttributesResponse response = (GetAttributesResponse) msg; |
144 | 144 | Optional<AttributesKVMsg> responseData = response.getData(); |
145 | 145 | if (response.isSuccess() && responseData.isPresent()) { | ... | ... |
... | ... | @@ -80,13 +80,13 @@ public class GatewayDeviceSessionCtx extends DeviceAwareSessionContext { |
80 | 80 | |
81 | 81 | private Optional<MqttMessage> getToDeviceMsg(SessionActorToAdaptorMsg sessionMsg) { |
82 | 82 | ToDeviceMsg msg = sessionMsg.getMsg(); |
83 | - switch (msg.getMsgType()) { | |
83 | + switch (msg.getSessionMsgType()) { | |
84 | 84 | case STATUS_CODE_RESPONSE: |
85 | 85 | ResponseMsg<?> responseMsg = (ResponseMsg) msg; |
86 | 86 | if (responseMsg.isSuccess()) { |
87 | - MsgType requestMsgType = responseMsg.getRequestMsgType(); | |
87 | + SessionMsgType requestMsgType = responseMsg.getRequestMsgType(); | |
88 | 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 | 90 | return Optional.of(MqttTransportHandler.createMqttPubAckMsg(requestId)); |
91 | 91 | } |
92 | 92 | } | ... | ... |