Commit e991c0ef23b96b7bc86967d108984391ef1fa925

Authored by Andrii Shvaika
1 parent 63bac58a

No more Synchronization nodes

@@ -36,7 +36,6 @@ import org.springframework.data.redis.core.RedisTemplate; @@ -36,7 +36,6 @@ import org.springframework.data.redis.core.RedisTemplate;
36 import org.springframework.scheduling.annotation.Scheduled; 36 import org.springframework.scheduling.annotation.Scheduled;
37 import org.springframework.stereotype.Component; 37 import org.springframework.stereotype.Component;
38 import org.thingsboard.rule.engine.api.MailService; 38 import org.thingsboard.rule.engine.api.MailService;
39 -import org.thingsboard.rule.engine.api.RuleChainTransactionService;  
40 import org.thingsboard.server.actors.service.ActorService; 39 import org.thingsboard.server.actors.service.ActorService;
41 import org.thingsboard.server.actors.tenant.DebugTbRateLimits; 40 import org.thingsboard.server.actors.tenant.DebugTbRateLimits;
42 import org.thingsboard.server.common.data.DataConstants; 41 import org.thingsboard.server.common.data.DataConstants;
@@ -67,7 +66,6 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService; @@ -67,7 +66,6 @@ import org.thingsboard.server.dao.timeseries.TimeseriesService;
67 import org.thingsboard.server.dao.user.UserService; 66 import org.thingsboard.server.dao.user.UserService;
68 import org.thingsboard.server.queue.discovery.PartitionService; 67 import org.thingsboard.server.queue.discovery.PartitionService;
69 import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; 68 import org.thingsboard.server.queue.discovery.TbServiceInfoProvider;
70 -import org.thingsboard.server.queue.provider.TbQueueProducerProvider;  
71 import org.thingsboard.server.service.component.ComponentDiscoveryService; 69 import org.thingsboard.server.service.component.ComponentDiscoveryService;
72 import org.thingsboard.server.service.encoding.DataDecodingEncodingService; 70 import org.thingsboard.server.service.encoding.DataDecodingEncodingService;
73 import org.thingsboard.server.service.executors.DbCallbackExecutorService; 71 import org.thingsboard.server.service.executors.DbCallbackExecutorService;
@@ -246,10 +244,6 @@ public class ActorSystemContext { @@ -246,10 +244,6 @@ public class ActorSystemContext {
246 @Getter 244 @Getter
247 private TbCoreDeviceRpcService tbCoreDeviceRpcService; 245 private TbCoreDeviceRpcService tbCoreDeviceRpcService;
248 246
249 - @Autowired(required = false)  
250 - @Getter  
251 - private RuleChainTransactionService ruleChainTransactionService;  
252 -  
253 @Value("${actors.session.max_concurrent_sessions_per_device:1}") 247 @Value("${actors.session.max_concurrent_sessions_per_device:1}")
254 @Getter 248 @Getter
255 private long maxConcurrentSessionsPerDevice; 249 private long maxConcurrentSessionsPerDevice;
@@ -24,7 +24,6 @@ import lombok.extern.slf4j.Slf4j; @@ -24,7 +24,6 @@ import lombok.extern.slf4j.Slf4j;
24 import org.springframework.data.redis.core.RedisTemplate; 24 import org.springframework.data.redis.core.RedisTemplate;
25 import org.thingsboard.common.util.ListeningExecutor; 25 import org.thingsboard.common.util.ListeningExecutor;
26 import org.thingsboard.rule.engine.api.MailService; 26 import org.thingsboard.rule.engine.api.MailService;
27 -import org.thingsboard.rule.engine.api.RuleChainTransactionService;  
28 import org.thingsboard.rule.engine.api.RuleEngineRpcService; 27 import org.thingsboard.rule.engine.api.RuleEngineRpcService;
29 import org.thingsboard.rule.engine.api.RuleEngineTelemetryService; 28 import org.thingsboard.rule.engine.api.RuleEngineTelemetryService;
30 import org.thingsboard.rule.engine.api.ScriptEngine; 29 import org.thingsboard.rule.engine.api.ScriptEngine;
@@ -379,11 +378,6 @@ class DefaultTbContext implements TbContext { @@ -379,11 +378,6 @@ class DefaultTbContext implements TbContext {
379 } 378 }
380 379
381 @Override 380 @Override
382 - public RuleChainTransactionService getRuleChainTransactionService() {  
383 - return mainCtx.getRuleChainTransactionService();  
384 - }  
385 -  
386 - @Override  
387 public EventLoopGroup getSharedEventLoop() { 381 public EventLoopGroup getSharedEventLoop() {
388 return mainCtx.getSharedEventLoopGroupService().getSharedEventLoopGroup(); 382 return mainCtx.getSharedEventLoopGroupService().getSharedEventLoopGroup();
389 } 383 }
1 -/**  
2 - * Copyright © 2016-2020 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.service.transaction;  
17 -  
18 -import lombok.extern.slf4j.Slf4j;  
19 -import org.springframework.beans.factory.annotation.Value;  
20 -import org.springframework.stereotype.Service;  
21 -import org.thingsboard.common.util.ThingsBoardThreadFactory;  
22 -import org.thingsboard.rule.engine.api.RuleChainTransactionService;  
23 -import org.thingsboard.server.common.data.id.EntityId;  
24 -import org.thingsboard.server.common.msg.TbMsg;  
25 -import org.thingsboard.server.queue.util.TbRuleEngineComponent;  
26 -import org.thingsboard.server.service.executors.DbCallbackExecutorService;  
27 -  
28 -import javax.annotation.PostConstruct;  
29 -import javax.annotation.PreDestroy;  
30 -import java.util.Queue;  
31 -import java.util.concurrent.BlockingQueue;  
32 -import java.util.concurrent.Callable;  
33 -import java.util.concurrent.ConcurrentHashMap;  
34 -import java.util.concurrent.ConcurrentLinkedQueue;  
35 -import java.util.concurrent.ConcurrentMap;  
36 -import java.util.concurrent.ExecutorService;  
37 -import java.util.concurrent.Executors;  
38 -import java.util.concurrent.LinkedBlockingQueue;  
39 -import java.util.concurrent.TimeUnit;  
40 -import java.util.concurrent.locks.Lock;  
41 -import java.util.concurrent.locks.ReentrantLock;  
42 -import java.util.function.Consumer;  
43 -  
44 -@Service  
45 -@TbRuleEngineComponent  
46 -@Slf4j  
47 -public class BaseRuleChainTransactionService implements RuleChainTransactionService {  
48 -  
49 - private final DbCallbackExecutorService callbackExecutor;  
50 -  
51 - @Value("${actors.rule.transaction.queue_size}")  
52 - private int finalQueueSize;  
53 - @Value("${actors.rule.transaction.duration}")  
54 - private long duration;  
55 -  
56 - private final Lock transactionLock = new ReentrantLock();  
57 - private final ConcurrentMap<EntityId, BlockingQueue<TbTransactionTask>> transactionMap = new ConcurrentHashMap<>();  
58 - private final Queue<TbTransactionTask> timeoutQueue = new ConcurrentLinkedQueue<>();  
59 -  
60 - private ExecutorService timeoutExecutor;  
61 -  
62 - public BaseRuleChainTransactionService(DbCallbackExecutorService callbackExecutor) {  
63 - this.callbackExecutor = callbackExecutor;  
64 - }  
65 -  
66 - @PostConstruct  
67 - public void init() {  
68 - timeoutExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("rule-chain-transaction"));  
69 - executeOnTimeout();  
70 - }  
71 -  
72 - @PreDestroy  
73 - public void destroy() {  
74 - if (timeoutExecutor != null) {  
75 - timeoutExecutor.shutdownNow();  
76 - }  
77 - }  
78 -  
79 - @Override  
80 - public void beginTransaction(TbMsg msg, Consumer<TbMsg> onStart, Consumer<TbMsg> onEnd, Consumer<Throwable> onFailure) {  
81 - transactionLock.lock();  
82 - try {  
83 - BlockingQueue<TbTransactionTask> queue = transactionMap.computeIfAbsent(msg.getTransactionData().getOriginatorId(), id ->  
84 - new LinkedBlockingQueue<>(finalQueueSize));  
85 -  
86 - TbTransactionTask transactionTask = new TbTransactionTask(msg, onStart, onEnd, onFailure, System.currentTimeMillis() + duration);  
87 - int queueSize = queue.size();  
88 - if (queueSize >= finalQueueSize) {  
89 - log.trace("Queue has no space: {}", transactionTask);  
90 - executeOnFailure(transactionTask.getOnFailure(), "Queue has no space!");  
91 - } else {  
92 - addMsgToQueues(queue, transactionTask);  
93 - if (queueSize == 0) {  
94 - executeOnSuccess(transactionTask.getOnStart(), transactionTask.getMsg());  
95 - } else {  
96 - log.trace("Msg [{}][{}] is waiting to start transaction!", msg.getId(), msg.getType());  
97 - }  
98 - }  
99 - } finally {  
100 - transactionLock.unlock();  
101 - }  
102 - }  
103 -  
104 - @Override  
105 - public void endTransaction(TbMsg msg, Consumer<TbMsg> onSuccess, Consumer<Throwable> onFailure) {  
106 - //TODO 2.5  
107 -// Optional<ServerAddress> address = routingService.resolveById(msg.getTransactionData().getOriginatorId());  
108 -// if (address.isPresent()) {  
109 -// sendTransactionEventToRemoteServer(msg, address.get());  
110 -// executeOnSuccess(onSuccess, msg);  
111 -// } else {  
112 - endLocalTransaction(msg, onSuccess, onFailure);  
113 -// }  
114 - }  
115 -  
116 - private void addMsgToQueues(BlockingQueue<TbTransactionTask> queue, TbTransactionTask transactionTask) {  
117 - queue.offer(transactionTask);  
118 - timeoutQueue.offer(transactionTask);  
119 - log.trace("Added msg to queue, size: [{}]", queue.size());  
120 - }  
121 -  
122 - private void endLocalTransaction(TbMsg msg, Consumer<TbMsg> onSuccess, Consumer<Throwable> onFailure) {  
123 - transactionLock.lock();  
124 - try {  
125 - BlockingQueue<TbTransactionTask> queue = transactionMap.computeIfAbsent(msg.getTransactionData().getOriginatorId(), id ->  
126 - new LinkedBlockingQueue<>(finalQueueSize));  
127 -  
128 - TbTransactionTask currentTransactionTask = queue.peek();  
129 - if (currentTransactionTask != null) {  
130 - if (currentTransactionTask.getMsg().getTransactionData().getTransactionId().equals(msg.getTransactionData().getTransactionId())) {  
131 - currentTransactionTask.setCompleted(true);  
132 - queue.poll();  
133 - log.trace("Removed msg from queue, size [{}]", queue.size());  
134 -  
135 - executeOnSuccess(currentTransactionTask.getOnEnd(), currentTransactionTask.getMsg());  
136 - executeOnSuccess(onSuccess, msg);  
137 -  
138 - TbTransactionTask nextTransactionTask = queue.peek();  
139 - if (nextTransactionTask != null) {  
140 - executeOnSuccess(nextTransactionTask.getOnStart(), nextTransactionTask.getMsg());  
141 - }  
142 - } else {  
143 - log.trace("Task has expired!");  
144 - executeOnFailure(onFailure, "Task has expired!");  
145 - }  
146 - } else {  
147 - log.trace("Queue is empty, previous task has expired!");  
148 - executeOnFailure(onFailure, "Queue is empty, previous task has expired!");  
149 - }  
150 - } finally {  
151 - transactionLock.unlock();  
152 - }  
153 - }  
154 -  
155 - private void executeOnTimeout() {  
156 - timeoutExecutor.submit(() -> {  
157 - while (true) {  
158 - TbTransactionTask transactionTask = timeoutQueue.peek();  
159 - if (transactionTask != null) {  
160 - long sleepDuration = 0L;  
161 - transactionLock.lock();  
162 - try {  
163 - if (transactionTask.isCompleted()) {  
164 - timeoutQueue.poll();  
165 - } else {  
166 - long expIn = transactionTask.getExpirationTime() - System.currentTimeMillis();  
167 - if (expIn < 0) {  
168 - log.trace("Task has expired! Deleting it...[{}][{}]", transactionTask.getMsg().getId(), transactionTask.getMsg().getType());  
169 - timeoutQueue.poll();  
170 - executeOnFailure(transactionTask.getOnFailure(), "Task has expired!");  
171 -  
172 - BlockingQueue<TbTransactionTask> queue = transactionMap.get(transactionTask.getMsg().getTransactionData().getOriginatorId());  
173 - if (queue != null) {  
174 - queue.poll();  
175 - TbTransactionTask nextTransactionTask = queue.peek();  
176 - if (nextTransactionTask != null) {  
177 - executeOnSuccess(nextTransactionTask.getOnStart(), nextTransactionTask.getMsg());  
178 - }  
179 - }  
180 - } else {  
181 - sleepDuration = Math.min(expIn, duration);  
182 - }  
183 - }  
184 - } finally {  
185 - transactionLock.unlock();  
186 - }  
187 - if (sleepDuration > 0L) {  
188 - try {  
189 - log.trace("Task has not expired! Continue executing...[{}][{}]", transactionTask.getMsg().getId(), transactionTask.getMsg().getType());  
190 - TimeUnit.MILLISECONDS.sleep(sleepDuration);  
191 - } catch (InterruptedException e) {  
192 - throw new IllegalStateException("Thread interrupted", e);  
193 - }  
194 - }  
195 - } else {  
196 - try {  
197 - log.trace("Queue is empty, waiting for tasks!");  
198 - TimeUnit.SECONDS.sleep(1);  
199 - } catch (InterruptedException e) {  
200 - throw new IllegalStateException("Thread interrupted", e);  
201 - }  
202 - }  
203 - }  
204 - });  
205 - }  
206 -  
207 - private void executeOnFailure(Consumer<Throwable> onFailure, String exception) {  
208 - executeCallback(() -> {  
209 - onFailure.accept(new RuntimeException(exception));  
210 - return null;  
211 - });  
212 - }  
213 -  
214 - private void executeOnSuccess(Consumer<TbMsg> onSuccess, TbMsg tbMsg) {  
215 - executeCallback(() -> {  
216 - onSuccess.accept(tbMsg);  
217 - return null;  
218 - });  
219 - }  
220 -  
221 - private void executeCallback(Callable<Void> task) {  
222 - callbackExecutor.executeAsync(task);  
223 - }  
224 -  
225 -}  
1 -/**  
2 - * Copyright © 2016-2020 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.service.transaction;  
17 -  
18 -import lombok.AllArgsConstructor;  
19 -import lombok.Data;  
20 -import org.thingsboard.server.common.msg.TbMsg;  
21 -  
22 -import java.util.function.Consumer;  
23 -  
24 -@Data  
25 -@AllArgsConstructor  
26 -public final class TbTransactionTask {  
27 -  
28 - private final TbMsg msg;  
29 - private final Consumer<TbMsg> onStart;  
30 - private final Consumer<TbMsg> onEnd;  
31 - private final Consumer<Throwable> onFailure;  
32 - private final long expirationTime;  
33 -  
34 - private boolean isCompleted;  
35 -  
36 - public TbTransactionTask(TbMsg msg, Consumer<TbMsg> onStart, Consumer<TbMsg> onEnd, Consumer<Throwable> onFailure, long expirationTime) {  
37 - this.msg = msg;  
38 - this.onStart = onStart;  
39 - this.onEnd = onEnd;  
40 - this.onFailure = onFailure;  
41 - this.expirationTime = expirationTime;  
42 - this.isCompleted = false;  
43 - }  
44 -}  
@@ -44,7 +44,6 @@ public final class TbMsg implements Serializable { @@ -44,7 +44,6 @@ public final class TbMsg implements Serializable {
44 private final TbMsgMetaData metaData; 44 private final TbMsgMetaData metaData;
45 private final TbMsgDataType dataType; 45 private final TbMsgDataType dataType;
46 private final String data; 46 private final String data;
47 - private final TbMsgTransactionData transactionData;  
48 private final RuleChainId ruleChainId; 47 private final RuleChainId ruleChainId;
49 private final RuleNodeId ruleNodeId; 48 private final RuleNodeId ruleNodeId;
50 //This field is not serialized because we use queues and there is no need to do it 49 //This field is not serialized because we use queues and there is no need to do it
@@ -68,27 +67,22 @@ public final class TbMsg implements Serializable { @@ -68,27 +67,22 @@ public final class TbMsg implements Serializable {
68 67
69 public static TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) { 68 public static TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data) {
70 return new TbMsg(origMsg.getId(), type, originator, metaData.copy(), origMsg.getDataType(), 69 return new TbMsg(origMsg.getId(), type, originator, metaData.copy(), origMsg.getDataType(),
71 - data, origMsg.getTransactionData(), origMsg.getRuleChainId(), origMsg.getRuleNodeId(), origMsg.getCallback()); 70 + data, origMsg.getRuleChainId(), origMsg.getRuleNodeId(), origMsg.getCallback());
72 } 71 }
73 72
74 public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) { 73 public static TbMsg newMsg(TbMsg tbMsg, RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
75 - return new TbMsg(UUID.randomUUID(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(), tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, TbMsgCallback.EMPTY); 74 + return new TbMsg(UUID.randomUUID(), tbMsg.getType(), tbMsg.getOriginator(), tbMsg.getMetaData().copy(),
  75 + tbMsg.getDataType(), tbMsg.getData(), ruleChainId, ruleNodeId, TbMsgCallback.EMPTY);
76 } 76 }
77 77
78 private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data, 78 private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data,
79 RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) { 79 RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) {
80 - this(id, type, originator, metaData, dataType, data, new TbMsgTransactionData(id, originator), ruleChainId, ruleNodeId, callback);  
81 - }  
82 -  
83 - private TbMsg(UUID id, String type, EntityId originator, TbMsgMetaData metaData, TbMsgDataType dataType, String data,  
84 - TbMsgTransactionData transactionData, RuleChainId ruleChainId, RuleNodeId ruleNodeId, TbMsgCallback callback) {  
85 this.id = id; 80 this.id = id;
86 this.type = type; 81 this.type = type;
87 this.originator = originator; 82 this.originator = originator;
88 this.metaData = metaData; 83 this.metaData = metaData;
89 this.dataType = dataType; 84 this.dataType = dataType;
90 this.data = data; 85 this.data = data;
91 - this.transactionData = transactionData;  
92 this.ruleChainId = ruleChainId; 86 this.ruleChainId = ruleChainId;
93 this.ruleNodeId = ruleNodeId; 87 this.ruleNodeId = ruleNodeId;
94 if (callback != null) { 88 if (callback != null) {
@@ -125,15 +119,6 @@ public final class TbMsg implements Serializable { @@ -125,15 +119,6 @@ public final class TbMsg implements Serializable {
125 builder.setMetaData(MsgProtos.TbMsgMetaDataProto.newBuilder().putAllData(msg.getMetaData().getData()).build()); 119 builder.setMetaData(MsgProtos.TbMsgMetaDataProto.newBuilder().putAllData(msg.getMetaData().getData()).build());
126 } 120 }
127 121
128 - TbMsgTransactionData transactionData = msg.getTransactionData();  
129 - if (transactionData != null) {  
130 - MsgProtos.TbMsgTransactionDataProto.Builder transactionBuilder = MsgProtos.TbMsgTransactionDataProto.newBuilder();  
131 - transactionBuilder.setId(transactionData.getTransactionId().toString());  
132 - transactionBuilder.setEntityType(transactionData.getOriginatorId().getEntityType().name());  
133 - transactionBuilder.setEntityIdMSB(transactionData.getOriginatorId().getId().getMostSignificantBits());  
134 - transactionBuilder.setEntityIdLSB(transactionData.getOriginatorId().getId().getLeastSignificantBits());  
135 - builder.setTransactionData(transactionBuilder.build());  
136 - }  
137 122
138 builder.setDataType(msg.getDataType().ordinal()); 123 builder.setDataType(msg.getDataType().ordinal());
139 builder.setData(msg.getData()); 124 builder.setData(msg.getData());
@@ -144,9 +129,6 @@ public final class TbMsg implements Serializable { @@ -144,9 +129,6 @@ public final class TbMsg implements Serializable {
144 try { 129 try {
145 MsgProtos.TbMsgProto proto = MsgProtos.TbMsgProto.parseFrom(data); 130 MsgProtos.TbMsgProto proto = MsgProtos.TbMsgProto.parseFrom(data);
146 TbMsgMetaData metaData = new TbMsgMetaData(proto.getMetaData().getDataMap()); 131 TbMsgMetaData metaData = new TbMsgMetaData(proto.getMetaData().getDataMap());
147 - EntityId transactionEntityId = EntityIdFactory.getByTypeAndUuid(proto.getTransactionData().getEntityType(),  
148 - new UUID(proto.getTransactionData().getEntityIdMSB(), proto.getTransactionData().getEntityIdLSB()));  
149 - TbMsgTransactionData transactionData = new TbMsgTransactionData(UUID.fromString(proto.getTransactionData().getId()), transactionEntityId);  
150 EntityId entityId = EntityIdFactory.getByTypeAndUuid(proto.getEntityType(), new UUID(proto.getEntityIdMSB(), proto.getEntityIdLSB())); 132 EntityId entityId = EntityIdFactory.getByTypeAndUuid(proto.getEntityType(), new UUID(proto.getEntityIdMSB(), proto.getEntityIdLSB()));
151 RuleChainId ruleChainId = null; 133 RuleChainId ruleChainId = null;
152 RuleNodeId ruleNodeId = null; 134 RuleNodeId ruleNodeId = null;
@@ -157,17 +139,17 @@ public final class TbMsg implements Serializable { @@ -157,17 +139,17 @@ public final class TbMsg implements Serializable {
157 ruleNodeId = new RuleNodeId(new UUID(proto.getRuleNodeIdMSB(), proto.getRuleNodeIdLSB())); 139 ruleNodeId = new RuleNodeId(new UUID(proto.getRuleNodeIdMSB(), proto.getRuleNodeIdLSB()));
158 } 140 }
159 TbMsgDataType dataType = TbMsgDataType.values()[proto.getDataType()]; 141 TbMsgDataType dataType = TbMsgDataType.values()[proto.getDataType()];
160 - return new TbMsg(UUID.fromString(proto.getId()), proto.getType(), entityId, metaData, dataType, proto.getData(), transactionData, ruleChainId, ruleNodeId, callback); 142 + return new TbMsg(UUID.fromString(proto.getId()), proto.getType(), entityId, metaData, dataType, proto.getData(), ruleChainId, ruleNodeId, callback);
161 } catch (InvalidProtocolBufferException e) { 143 } catch (InvalidProtocolBufferException e) {
162 throw new IllegalStateException("Could not parse protobuf for TbMsg", e); 144 throw new IllegalStateException("Could not parse protobuf for TbMsg", e);
163 } 145 }
164 } 146 }
165 147
166 public TbMsg copyWithRuleChainId(RuleChainId ruleChainId) { 148 public TbMsg copyWithRuleChainId(RuleChainId ruleChainId) {
167 - return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, this.transactionData, ruleChainId, null, callback); 149 + return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, ruleChainId, null, callback);
168 } 150 }
169 151
170 public TbMsg copyWithRuleNodeId(RuleChainId ruleChainId, RuleNodeId ruleNodeId) { 152 public TbMsg copyWithRuleNodeId(RuleChainId ruleChainId, RuleNodeId ruleNodeId) {
171 - return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, this.transactionData, ruleChainId, ruleNodeId, callback); 153 + return new TbMsg(this.id, this.type, this.originator, this.metaData, this.dataType, this.data, ruleChainId, ruleNodeId, callback);
172 } 154 }
173 } 155 }
1 -/**  
2 - * Copyright © 2016-2020 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.common.msg;  
17 -  
18 -import lombok.Data;  
19 -import org.thingsboard.server.common.data.id.EntityId;  
20 -  
21 -import java.io.Serializable;  
22 -import java.util.UUID;  
23 -  
24 -@Data  
25 -public final class TbMsgTransactionData implements Serializable {  
26 -  
27 - private final UUID transactionId;  
28 - private final EntityId originatorId;  
29 -  
30 -}  
@@ -23,13 +23,6 @@ message TbMsgMetaDataProto { @@ -23,13 +23,6 @@ message TbMsgMetaDataProto {
23 map<string, string> data = 1; 23 map<string, string> data = 1;
24 } 24 }
25 25
26 -message TbMsgTransactionDataProto {  
27 - string id = 1;  
28 - string entityType = 2;  
29 - int64 entityIdMSB = 3;  
30 - int64 entityIdLSB = 4;  
31 -}  
32 -  
33 message TbMsgProto { 26 message TbMsgProto {
34 string id = 1; 27 string id = 1;
35 string type = 2; 28 string type = 2;
@@ -46,7 +39,7 @@ message TbMsgProto { @@ -46,7 +39,7 @@ message TbMsgProto {
46 39
47 TbMsgMetaDataProto metaData = 11; 40 TbMsgMetaDataProto metaData = 11;
48 41
49 - TbMsgTransactionDataProto transactionData = 12; 42 + //Transaction Data (12) was removed in 2.5
50 43
51 int32 dataType = 13; 44 int32 dataType = 13;
52 string data = 14; 45 string data = 14;
1 -/**  
2 - * Copyright © 2016-2020 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.rule.engine.api;  
17 -  
18 -import org.thingsboard.server.common.msg.TbMsg;  
19 -  
20 -import java.util.function.Consumer;  
21 -  
22 -public interface RuleChainTransactionService {  
23 -  
24 - void beginTransaction(TbMsg msg, Consumer<TbMsg> onStart, Consumer<TbMsg> onEnd, Consumer<Throwable> onFailure);  
25 -  
26 - void endTransaction(TbMsg msg, Consumer<TbMsg> onSuccess, Consumer<Throwable> onFailure);  
27 -  
28 -}  
@@ -203,8 +203,6 @@ public interface TbContext { @@ -203,8 +203,6 @@ public interface TbContext {
203 203
204 String getServiceId(); 204 String getServiceId();
205 205
206 - RuleChainTransactionService getRuleChainTransactionService();  
207 -  
208 EventLoopGroup getSharedEventLoop(); 206 EventLoopGroup getSharedEventLoop();
209 207
210 CassandraCluster getCassandraCluster(); 208 CassandraCluster getCassandraCluster();
@@ -25,10 +25,6 @@ import org.thingsboard.rule.engine.api.TbNodeException; @@ -25,10 +25,6 @@ import org.thingsboard.rule.engine.api.TbNodeException;
25 import org.thingsboard.rule.engine.api.util.TbNodeUtils; 25 import org.thingsboard.rule.engine.api.util.TbNodeUtils;
26 import org.thingsboard.server.common.data.plugin.ComponentType; 26 import org.thingsboard.server.common.data.plugin.ComponentType;
27 import org.thingsboard.server.common.msg.TbMsg; 27 import org.thingsboard.server.common.msg.TbMsg;
28 -import org.thingsboard.server.common.msg.TbMsgDataType;  
29 -import org.thingsboard.server.common.msg.TbMsgTransactionData;  
30 -  
31 -import java.util.concurrent.ExecutionException;  
32 28
33 import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; 29 import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
34 30
@@ -43,31 +39,17 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -43,31 +39,17 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
43 "Size of the queue per originator and timeout values are configurable on a system level", 39 "Size of the queue per originator and timeout values are configurable on a system level",
44 uiResources = {"static/rulenode/rulenode-core-config.js"}, 40 uiResources = {"static/rulenode/rulenode-core-config.js"},
45 configDirective = "tbNodeEmptyConfig") 41 configDirective = "tbNodeEmptyConfig")
  42 +@Deprecated
46 public class TbSynchronizationBeginNode implements TbNode { 43 public class TbSynchronizationBeginNode implements TbNode {
47 44
48 - private EmptyNodeConfiguration config;  
49 -  
50 @Override 45 @Override
51 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { 46 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
52 - this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);  
53 } 47 }
54 48
55 @Override 49 @Override
56 public void onMsg(TbContext ctx, TbMsg msg) { 50 public void onMsg(TbContext ctx, TbMsg msg) {
57 - log.trace("Msg enters transaction - [{}][{}]", msg.getId(), msg.getType());  
58 -  
59 - TbMsgTransactionData transactionData = new TbMsgTransactionData(msg.getId(), msg.getOriginator());  
60 - //TODO 2.5: Callback?  
61 - TbMsg tbMsg = TbMsg.transformMsg(msg, msg.getType(), msg.getOriginator(), msg.getMetaData(), msg.getData());  
62 -  
63 - ctx.getRuleChainTransactionService().beginTransaction(tbMsg, startMsg -> {  
64 - log.trace("Transaction starting...[{}][{}]", startMsg.getId(), startMsg.getType());  
65 - ctx.tellNext(startMsg, SUCCESS);  
66 - }, endMsg -> log.trace("Transaction ended successfully...[{}][{}]", endMsg.getId(), endMsg.getType()),  
67 - throwable -> {  
68 - log.trace("Transaction failed! [{}][{}]", tbMsg.getId(), tbMsg.getType(), throwable);  
69 - ctx.tellFailure(tbMsg, throwable);  
70 - }); 51 + log.warn("Synchronization Start/End nodes are deprecated since TB 2.5. Use queue with submit strategy SEQUENTIAL_WITHIN_ORIGINATOR instead.");
  52 + ctx.tellSuccess(msg);
71 } 53 }
72 54
73 @Override 55 @Override
@@ -40,25 +40,20 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; @@ -40,25 +40,20 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
40 uiResources = {"static/rulenode/rulenode-core-config.js"}, 40 uiResources = {"static/rulenode/rulenode-core-config.js"},
41 configDirective = ("tbNodeEmptyConfig") 41 configDirective = ("tbNodeEmptyConfig")
42 ) 42 )
  43 +@Deprecated
43 public class TbSynchronizationEndNode implements TbNode { 44 public class TbSynchronizationEndNode implements TbNode {
44 45
45 - private EmptyNodeConfiguration config;  
46 -  
47 @Override 46 @Override
48 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { 47 public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
49 - this.config = TbNodeUtils.convert(configuration, EmptyNodeConfiguration.class);  
50 } 48 }
51 49
52 @Override 50 @Override
53 public void onMsg(TbContext ctx, TbMsg msg) { 51 public void onMsg(TbContext ctx, TbMsg msg) {
54 - ctx.getRuleChainTransactionService().endTransaction(msg,  
55 - successMsg -> ctx.tellNext(successMsg, SUCCESS),  
56 - throwable -> ctx.tellFailure(msg, throwable));  
57 - log.trace("Msg left transaction - [{}][{}]", msg.getId(), msg.getType()); 52 + log.warn("Synchronization Start/End nodes are deprecated since TB 2.5. Use queue with submit strategy SEQUENTIAL_WITHIN_ORIGINATOR instead.");
  53 + ctx.tellSuccess(msg);
58 } 54 }
59 55
60 @Override 56 @Override
61 public void destroy() { 57 public void destroy() {
62 -  
63 } 58 }
64 } 59 }