Commit d68ef2333ab8a1063ac027e5c5682edfa07e07bc

Authored by YevhenBondarenko
Committed by Andrew Shvayka
1 parent f3a01f21

updated guava and protobuf versions

Showing 56 changed files with 308 additions and 233 deletions
... ... @@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
24 24 import com.google.common.util.concurrent.FutureCallback;
25 25 import com.google.common.util.concurrent.Futures;
26 26 import com.google.common.util.concurrent.ListenableFuture;
  27 +import com.google.common.util.concurrent.MoreExecutors;
27 28 import com.typesafe.config.Config;
28 29 import com.typesafe.config.ConfigFactory;
29 30 import lombok.Getter;
... ... @@ -469,7 +470,7 @@ public class ActorSystemContext {
469 470 public void onFailure(Throwable th) {
470 471 log.error("Could not save debug Event for Node", th);
471 472 }
472   - });
  473 + }, MoreExecutors.directExecutor());
473 474 } catch (IOException ex) {
474 475 log.warn("Failed to persist rule node debug message", ex);
475 476 }
... ... @@ -522,7 +523,7 @@ public class ActorSystemContext {
522 523 public void onFailure(Throwable th) {
523 524 log.error("Could not save debug Event for Rule Chain", th);
524 525 }
525   - });
  526 + }, MoreExecutors.directExecutor());
526 527 }
527 528
528 529 public static Exception toException(Throwable error) {
... ...
... ... @@ -20,9 +20,9 @@ import com.datastax.driver.core.utils.UUIDs;
20 20 import com.google.common.util.concurrent.FutureCallback;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.MoreExecutors;
23 24 import com.google.gson.Gson;
24 25 import com.google.gson.JsonObject;
25   -import com.google.gson.JsonParser;
26 26 import com.google.protobuf.InvalidProtocolBufferException;
27 27 import lombok.extern.slf4j.Slf4j;
28 28 import org.apache.commons.collections.CollectionUtils;
... ... @@ -292,7 +292,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
292 292 .build();
293 293 sendToTransport(responseMsg, sessionInfo);
294 294 }
295   - });
  295 + }, MoreExecutors.directExecutor());
296 296 }
297 297
298 298 private ListenableFuture<List<List<AttributeKvEntry>>> getAttributesKvEntries(GetAttributeRequestMsg request) {
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.controller;
18 18 import com.google.common.util.concurrent.FutureCallback;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import org.springframework.http.HttpStatus;
22 23 import org.springframework.http.ResponseEntity;
23 24 import org.springframework.security.access.prepost.PreAuthorize;
... ... @@ -30,6 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
30 31 import org.springframework.web.bind.annotation.ResponseStatus;
31 32 import org.springframework.web.bind.annotation.RestController;
32 33 import org.springframework.web.context.request.async.DeferredResult;
  34 +import org.thingsboard.server.common.data.ClaimRequest;
33 35 import org.thingsboard.server.common.data.Customer;
34 36 import org.thingsboard.server.common.data.DataConstants;
35 37 import org.thingsboard.server.common.data.Device;
... ... @@ -44,7 +46,6 @@ import org.thingsboard.server.common.data.id.TenantId;
44 46 import org.thingsboard.server.common.data.page.TextPageData;
45 47 import org.thingsboard.server.common.data.page.TextPageLink;
46 48 import org.thingsboard.server.common.data.security.DeviceCredentials;
47   -import org.thingsboard.server.common.data.ClaimRequest;
48 49 import org.thingsboard.server.dao.device.claim.ClaimResponse;
49 50 import org.thingsboard.server.dao.device.claim.ClaimResult;
50 51 import org.thingsboard.server.dao.exception.IncorrectParameterException;
... ... @@ -425,11 +426,12 @@ public class DeviceController extends BaseController {
425 426 deferredResult.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
426 427 }
427 428 }
  429 +
428 430 @Override
429 431 public void onFailure(Throwable t) {
430 432 deferredResult.setErrorResult(t);
431 433 }
432   - });
  434 + }, MoreExecutors.directExecutor());
433 435 return deferredResult;
434 436 } catch (Exception e) {
435 437 throw handleException(e);
... ... @@ -466,7 +468,7 @@ public class DeviceController extends BaseController {
466 468 public void onFailure(Throwable t) {
467 469 deferredResult.setErrorResult(t);
468 470 }
469   - });
  471 + }, MoreExecutors.directExecutor());
470 472 return deferredResult;
471 473 } catch (Exception e) {
472 474 throw handleException(e);
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.controller;
18 18 import com.google.common.util.concurrent.FutureCallback;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.springframework.http.HttpStatus;
23 24 import org.springframework.security.access.prepost.PreAuthorize;
... ... @@ -158,7 +159,7 @@ public class EntityViewController extends BaseController {
158 159 });
159 160 }
160 161 return null;
161   - });
  162 + }, MoreExecutors.directExecutor());
162 163 } else {
163 164 return Futures.immediateFuture(null);
164 165 }
... ...
... ... @@ -22,6 +22,7 @@ import com.google.common.base.Function;
22 22 import com.google.common.util.concurrent.FutureCallback;
23 23 import com.google.common.util.concurrent.Futures;
24 24 import com.google.common.util.concurrent.ListenableFuture;
  25 +import com.google.common.util.concurrent.MoreExecutors;
25 26 import com.google.gson.JsonElement;
26 27 import com.google.gson.JsonParseException;
27 28 import com.google.gson.JsonParser;
... ... @@ -174,7 +175,7 @@ public class TelemetryController extends BaseController {
174 175 public DeferredResult<ResponseEntity> getTimeseriesKeys(
175 176 @PathVariable("entityType") String entityType, @PathVariable("entityId") String entityIdStr) throws ThingsboardException {
176 177 return accessValidator.validateEntityAndCallback(getCurrentUser(), Operation.READ_TELEMETRY, entityType, entityIdStr,
177   - (result, tenantId, entityId) -> Futures.addCallback(tsService.findAllLatest(tenantId, entityId), getTsKeysToResponseCallback(result)));
  178 + (result, tenantId, entityId) -> Futures.addCallback(tsService.findAllLatest(tenantId, entityId), getTsKeysToResponseCallback(result), MoreExecutors.directExecutor()));
178 179 }
179 180
180 181 @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
... ... @@ -210,7 +211,7 @@ public class TelemetryController extends BaseController {
210 211 List<ReadTsKvQuery> queries = toKeysList(keys).stream().map(key -> new BaseReadTsKvQuery(key, startTs, endTs, interval, limit, agg))
211 212 .collect(Collectors.toList());
212 213
213   - Futures.addCallback(tsService.findAll(tenantId, entityId, queries), getTsKvListCallback(result, useStrictDataTypes));
  214 + Futures.addCallback(tsService.findAll(tenantId, entityId, queries), getTsKvListCallback(result, useStrictDataTypes), MoreExecutors.directExecutor());
214 215 });
215 216 }
216 217
... ... @@ -462,7 +463,7 @@ public class TelemetryController extends BaseController {
462 463 } else {
463 464 future = tsService.findLatest(user.getTenantId(), entityId, toKeysList(keys));
464 465 }
465   - Futures.addCallback(future, getTsKvListCallback(result, useStrictDataTypes));
  466 + Futures.addCallback(future, getTsKvListCallback(result, useStrictDataTypes), MoreExecutors.directExecutor());
466 467 }
467 468
468 469 private void getAttributeValuesCallback(@Nullable DeferredResult<ResponseEntity> result, SecurityUser user, EntityId entityId, String scope, String keys) {
... ... @@ -470,9 +471,9 @@ public class TelemetryController extends BaseController {
470 471 FutureCallback<List<AttributeKvEntry>> callback = getAttributeValuesToResponseCallback(result, user, scope, entityId, keyList);
471 472 if (!StringUtils.isEmpty(scope)) {
472 473 if (keyList != null && !keyList.isEmpty()) {
473   - Futures.addCallback(attributesService.find(user.getTenantId(), entityId, scope, keyList), callback);
  474 + Futures.addCallback(attributesService.find(user.getTenantId(), entityId, scope, keyList), callback, MoreExecutors.directExecutor());
474 475 } else {
475   - Futures.addCallback(attributesService.findAll(user.getTenantId(), entityId, scope), callback);
  476 + Futures.addCallback(attributesService.findAll(user.getTenantId(), entityId, scope), callback, MoreExecutors.directExecutor());
476 477 }
477 478 } else {
478 479 List<ListenableFuture<List<AttributeKvEntry>>> futures = new ArrayList<>();
... ... @@ -486,12 +487,12 @@ public class TelemetryController extends BaseController {
486 487
487 488 ListenableFuture<List<AttributeKvEntry>> future = mergeAllAttributesFutures(futures);
488 489
489   - Futures.addCallback(future, callback);
  490 + Futures.addCallback(future, callback, MoreExecutors.directExecutor());
490 491 }
491 492 }
492 493
493 494 private void getAttributeKeysCallback(@Nullable DeferredResult<ResponseEntity> result, TenantId tenantId, EntityId entityId, String scope) {
494   - Futures.addCallback(attributesService.findAll(tenantId, entityId, scope), getAttributeKeysToResponseCallback(result));
  495 + Futures.addCallback(attributesService.findAll(tenantId, entityId, scope), getAttributeKeysToResponseCallback(result), MoreExecutors.directExecutor());
495 496 }
496 497
497 498 private void getAttributeKeysCallback(@Nullable DeferredResult<ResponseEntity> result, TenantId tenantId, EntityId entityId) {
... ... @@ -502,7 +503,7 @@ public class TelemetryController extends BaseController {
502 503
503 504 ListenableFuture<List<AttributeKvEntry>> future = mergeAllAttributesFutures(futures);
504 505
505   - Futures.addCallback(future, getAttributeKeysToResponseCallback(result));
  506 + Futures.addCallback(future, getAttributeKeysToResponseCallback(result), MoreExecutors.directExecutor());
506 507 }
507 508
508 509 private FutureCallback<List<TsKvEntry>> getTsKeysToResponseCallback(final DeferredResult<ResponseEntity> response) {
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.service.script;
18 18 import com.google.common.util.concurrent.FutureCallback;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import delight.nashornsandbox.NashornSandbox;
22 23 import delight.nashornsandbox.NashornSandboxes;
23 24 import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
... ... @@ -28,20 +29,17 @@ import org.springframework.beans.factory.annotation.Value;
28 29 import org.springframework.scheduling.annotation.Scheduled;
29 30 import org.thingsboard.common.util.ThingsBoardThreadFactory;
30 31
31   -import javax.annotation.Nullable;
32 32 import javax.annotation.PostConstruct;
33 33 import javax.annotation.PreDestroy;
34 34 import javax.script.Invocable;
35 35 import javax.script.ScriptEngine;
36 36 import javax.script.ScriptException;
37 37 import java.util.UUID;
38   -import java.util.concurrent.Callable;
39 38 import java.util.concurrent.ExecutionException;
40 39 import java.util.concurrent.ExecutorService;
41 40 import java.util.concurrent.Executors;
42 41 import java.util.concurrent.ScheduledExecutorService;
43 42 import java.util.concurrent.TimeUnit;
44   -import java.util.concurrent.TimeoutException;
45 43 import java.util.concurrent.atomic.AtomicInteger;
46 44
47 45 @Slf4j
... ... @@ -140,7 +138,7 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
140 138 if (maxRequestsTimeout > 0) {
141 139 result = Futures.withTimeout(result, maxRequestsTimeout, TimeUnit.MILLISECONDS, timeoutExecutorService);
142 140 }
143   - Futures.addCallback(result, evalCallback);
  141 + Futures.addCallback(result, evalCallback, MoreExecutors.directExecutor());
144 142 return result;
145 143 }
146 144
... ... @@ -163,7 +161,7 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
163 161 if (maxRequestsTimeout > 0) {
164 162 result = Futures.withTimeout(result, maxRequestsTimeout, TimeUnit.MILLISECONDS, timeoutExecutorService);
165 163 }
166   - Futures.addCallback(result, invokeCallback);
  164 + Futures.addCallback(result, invokeCallback, MoreExecutors.directExecutor());
167 165 return result;
168 166 }
169 167
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.service.script;
18 18 import com.google.common.util.concurrent.FutureCallback;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.Getter;
22 23 import lombok.extern.slf4j.Slf4j;
23 24 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -40,7 +41,6 @@ import java.util.UUID;
40 41 import java.util.concurrent.ConcurrentHashMap;
41 42 import java.util.concurrent.TimeoutException;
42 43 import java.util.concurrent.atomic.AtomicInteger;
43   -import java.util.concurrent.atomic.AtomicLong;
44 44
45 45 @Slf4j
46 46 @ConditionalOnProperty(prefix = "js", value = "evaluator", havingValue = "remote", matchIfMissing = true)
... ... @@ -166,7 +166,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
166 166 }
167 167 kafkaFailedMsgs.incrementAndGet();
168 168 }
169   - });
  169 + }, MoreExecutors.directExecutor());
170 170 return Futures.transform(future, response -> {
171 171 JsInvokeProtos.JsCompileResponse compilationResult = response.getCompileResponse();
172 172 UUID compiledScriptId = new UUID(compilationResult.getScriptIdMSB(), compilationResult.getScriptIdLSB());
... ... @@ -178,7 +178,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
178 178 log.debug("[{}] Failed to compile script due to [{}]: {}", compiledScriptId, compilationResult.getErrorCode().name(), compilationResult.getErrorDetails());
179 179 throw new RuntimeException(compilationResult.getErrorDetails());
180 180 }
181   - });
  181 + }, MoreExecutors.directExecutor());
182 182 }
183 183
184 184 @Override
... ... @@ -217,7 +217,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
217 217 }
218 218 kafkaFailedMsgs.incrementAndGet();
219 219 }
220   - });
  220 + }, MoreExecutors.directExecutor());
221 221 return Futures.transform(future, response -> {
222 222 JsInvokeProtos.JsInvokeResponse invokeResult = response.getInvokeResponse();
223 223 if (invokeResult.getSuccess()) {
... ... @@ -226,7 +226,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
226 226 log.debug("[{}] Failed to compile script due to [{}]: {}", scriptId, invokeResult.getErrorCode().name(), invokeResult.getErrorDetails());
227 227 throw new RuntimeException(invokeResult.getErrorDetails());
228 228 }
229   - });
  229 + }, MoreExecutors.directExecutor());
230 230 }
231 231
232 232 @Override
... ...
... ... @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import com.google.common.collect.Sets;
22 22 import com.google.common.util.concurrent.Futures;
23 23 import com.google.common.util.concurrent.ListenableFuture;
  24 +import com.google.common.util.concurrent.MoreExecutors;
24 25 import lombok.extern.slf4j.Slf4j;
25 26 import org.apache.commons.lang3.StringUtils;
26 27 import org.thingsboard.server.common.data.id.EntityId;
... ... @@ -121,7 +122,7 @@ public class RuleNodeJsScriptEngine implements org.thingsboard.rule.engine.api.S
121 122 } else {
122 123 return Futures.immediateFuture(unbindMsg(json, msg));
123 124 }
124   - });
  125 + }, MoreExecutors.directExecutor());
125 126 }
126 127
127 128 @Override
... ... @@ -174,7 +175,7 @@ public class RuleNodeJsScriptEngine implements org.thingsboard.rule.engine.api.S
174 175 } else {
175 176 return Futures.immediateFuture(json.asBoolean());
176 177 }
177   - });
  178 + }, MoreExecutors.directExecutor());
178 179 }
179 180
180 181 @Override
... ... @@ -232,7 +233,7 @@ public class RuleNodeJsScriptEngine implements org.thingsboard.rule.engine.api.S
232 233 return Futures.immediateFailedFuture(new ScriptException(e));
233 234 }
234 235 }
235   - });
  236 + }, MoreExecutors.directExecutor());
236 237 }
237 238
238 239 public void destroy() {
... ...
... ... @@ -64,14 +64,26 @@ import org.thingsboard.server.service.telemetry.TelemetrySubscriptionService;
64 64 import javax.annotation.Nullable;
65 65 import javax.annotation.PostConstruct;
66 66 import javax.annotation.PreDestroy;
67   -import java.util.*;
  67 +import java.util.ArrayList;
  68 +import java.util.Arrays;
  69 +import java.util.Collections;
  70 +import java.util.HashSet;
  71 +import java.util.List;
  72 +import java.util.Optional;
  73 +import java.util.Random;
  74 +import java.util.Set;
  75 +import java.util.UUID;
68 76 import java.util.concurrent.ConcurrentHashMap;
69 77 import java.util.concurrent.ConcurrentMap;
70 78 import java.util.concurrent.ExecutionException;
71 79 import java.util.concurrent.Executors;
72 80 import java.util.concurrent.TimeUnit;
73 81
74   -import static org.thingsboard.server.common.data.DataConstants.*;
  82 +import static org.thingsboard.server.common.data.DataConstants.ACTIVITY_EVENT;
  83 +import static org.thingsboard.server.common.data.DataConstants.CONNECT_EVENT;
  84 +import static org.thingsboard.server.common.data.DataConstants.DISCONNECT_EVENT;
  85 +import static org.thingsboard.server.common.data.DataConstants.INACTIVITY_EVENT;
  86 +import static org.thingsboard.server.common.data.DataConstants.SERVER_SCOPE;
75 87
76 88 /**
77 89 * Created by ashvayka on 01.05.18.
... ... @@ -401,7 +413,7 @@ public class DefaultDeviceStateService implements DeviceStateService {
401 413 public void onFailure(Throwable t) {
402 414 log.warn("Failed to register device to the state service", t);
403 415 }
404   - });
  416 + }, MoreExecutors.directExecutor());
405 417 } else {
406 418 sendDeviceEvent(device.getTenantId(), device.getId(), address.get(), true, false, false);
407 419 }
... ... @@ -456,10 +468,10 @@ public class DefaultDeviceStateService implements DeviceStateService {
456 468 private ListenableFuture<DeviceStateData> fetchDeviceState(Device device) {
457 469 if (persistToTelemetry) {
458 470 ListenableFuture<List<TsKvEntry>> tsData = tsService.findLatest(TenantId.SYS_TENANT_ID, device.getId(), PERSISTENT_ATTRIBUTES);
459   - return Futures.transform(tsData, extractDeviceStateData(device));
  471 + return Futures.transform(tsData, extractDeviceStateData(device), MoreExecutors.directExecutor());
460 472 } else {
461 473 ListenableFuture<List<AttributeKvEntry>> attrData = attributesService.find(TenantId.SYS_TENANT_ID, device.getId(), DataConstants.SERVER_SCOPE, PERSISTENT_ATTRIBUTES);
462   - return Futures.transform(attrData, extractDeviceStateData(device));
  474 + return Futures.transform(attrData, extractDeviceStateData(device), MoreExecutors.directExecutor());
463 475 }
464 476 }
465 477
... ...
... ... @@ -21,6 +21,7 @@ import com.google.common.base.Function;
21 21 import com.google.common.util.concurrent.FutureCallback;
22 22 import com.google.common.util.concurrent.Futures;
23 23 import com.google.common.util.concurrent.ListenableFuture;
  24 +import com.google.common.util.concurrent.MoreExecutors;
24 25 import lombok.extern.slf4j.Slf4j;
25 26 import org.springframework.beans.factory.annotation.Autowired;
26 27 import org.springframework.beans.factory.annotation.Value;
... ... @@ -54,9 +55,6 @@ import org.thingsboard.server.service.telemetry.cmd.SubscriptionCmd;
54 55 import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmd;
55 56 import org.thingsboard.server.service.telemetry.cmd.TelemetryPluginCmdsWrapper;
56 57 import org.thingsboard.server.service.telemetry.cmd.TimeseriesSubscriptionCmd;
57   -import org.thingsboard.server.service.telemetry.exception.AccessDeniedException;
58   -import org.thingsboard.server.service.telemetry.exception.EntityNotFoundException;
59   -import org.thingsboard.server.service.telemetry.exception.InternalErrorException;
60 58 import org.thingsboard.server.service.telemetry.exception.UnauthorizedException;
61 59 import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode;
62 60 import org.thingsboard.server.service.telemetry.sub.SubscriptionState;
... ... @@ -70,12 +68,14 @@ import java.util.ArrayList;
70 68 import java.util.Collections;
71 69 import java.util.HashMap;
72 70 import java.util.HashSet;
73   -import java.util.Iterator;
74 71 import java.util.List;
75 72 import java.util.Map;
76 73 import java.util.Optional;
77 74 import java.util.Set;
78   -import java.util.concurrent.*;
  75 +import java.util.concurrent.ConcurrentHashMap;
  76 +import java.util.concurrent.ConcurrentMap;
  77 +import java.util.concurrent.ExecutorService;
  78 +import java.util.concurrent.Executors;
79 79 import java.util.function.Consumer;
80 80 import java.util.stream.Collectors;
81 81
... ... @@ -616,7 +616,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
616 616 }
617 617
618 618 ListenableFuture<List<AttributeKvEntry>> future = mergeAllAttributesFutures(futures);
619   - Futures.addCallback(future, callback);
  619 + Futures.addCallback(future, callback, MoreExecutors.directExecutor());
620 620 }
621 621
622 622 @Override
... ... @@ -630,7 +630,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
630 630 return new FutureCallback<ValidationResult>() {
631 631 @Override
632 632 public void onSuccess(@Nullable ValidationResult result) {
633   - Futures.addCallback(attributesService.find(tenantId, entityId, scope, keys), callback);
  633 + Futures.addCallback(attributesService.find(tenantId, entityId, scope, keys), callback, MoreExecutors.directExecutor());
634 634 }
635 635
636 636 @Override
... ... @@ -650,7 +650,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
650 650 }
651 651
652 652 ListenableFuture<List<AttributeKvEntry>> future = mergeAllAttributesFutures(futures);
653   - Futures.addCallback(future, callback);
  653 + Futures.addCallback(future, callback, MoreExecutors.directExecutor());
654 654 }
655 655
656 656 @Override
... ... @@ -664,7 +664,7 @@ public class DefaultTelemetryWebSocketService implements TelemetryWebSocketServi
664 664 return new FutureCallback<ValidationResult>() {
665 665 @Override
666 666 public void onSuccess(@Nullable ValidationResult result) {
667   - Futures.addCallback(attributesService.findAll(tenantId, entityId, scope), callback);
  667 + Futures.addCallback(attributesService.findAll(tenantId, entityId, scope), callback, MoreExecutors.directExecutor());
668 668 }
669 669
670 670 @Override
... ...
... ... @@ -19,10 +19,9 @@ import com.fasterxml.jackson.core.JsonProcessingException;
19 19 import com.fasterxml.jackson.databind.ObjectMapper;
20 20 import com.google.common.util.concurrent.Futures;
21 21 import com.google.common.util.concurrent.ListenableFuture;
  22 +import com.google.common.util.concurrent.MoreExecutors;
22 23 import lombok.extern.slf4j.Slf4j;
23 24 import org.springframework.beans.factory.annotation.Autowired;
24   -import org.springframework.beans.factory.annotation.Value;
25   -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
26 25 import org.springframework.stereotype.Service;
27 26 import org.springframework.util.StringUtils;
28 27 import org.thingsboard.server.common.data.Device;
... ... @@ -42,19 +41,10 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponse
42 41 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCredentialsResponseMsg;
43 42 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
44 43 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
45   -import org.thingsboard.server.kafka.TBKafkaConsumerTemplate;
46   -import org.thingsboard.server.kafka.TBKafkaProducerTemplate;
47   -import org.thingsboard.server.kafka.TbKafkaResponseTemplate;
48   -import org.thingsboard.server.kafka.TbKafkaSettings;
49   -import org.thingsboard.server.service.cluster.discovery.DiscoveryService;
50 44 import org.thingsboard.server.service.executors.DbCallbackExecutorService;
51 45 import org.thingsboard.server.service.state.DeviceStateService;
52 46
53   -import javax.annotation.PostConstruct;
54   -import javax.annotation.PreDestroy;
55 47 import java.util.UUID;
56   -import java.util.concurrent.ExecutorService;
57   -import java.util.concurrent.Executors;
58 48 import java.util.concurrent.locks.ReentrantLock;
59 49
60 50 /**
... ... @@ -145,7 +135,7 @@ public class LocalTransportApiService implements TransportApiService {
145 135 try {
146 136 ValidateDeviceCredentialsResponseMsg.Builder builder = ValidateDeviceCredentialsResponseMsg.newBuilder();
147 137 builder.setDeviceInfo(getDeviceInfoProto(device));
148   - if(!StringUtils.isEmpty(credentials.getCredentialsValue())){
  138 + if (!StringUtils.isEmpty(credentials.getCredentialsValue())) {
149 139 builder.setCredentialsBody(credentials.getCredentialsValue());
150 140 }
151 141 return TransportApiResponseMsg.newBuilder()
... ... @@ -154,7 +144,7 @@ public class LocalTransportApiService implements TransportApiService {
154 144 log.warn("[{}] Failed to lookup device by id", deviceId, e);
155 145 return getEmptyTransportApiResponse();
156 146 }
157   - });
  147 + }, MoreExecutors.directExecutor());
158 148 }
159 149
160 150 private DeviceInfoProto getDeviceInfoProto(Device device) throws JsonProcessingException {
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.kafka;
18 18 import com.google.common.util.concurrent.FutureCallback;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22
22 23 import java.util.concurrent.Executor;
23 24 import java.util.concurrent.ScheduledExecutorService;
... ... @@ -59,7 +60,7 @@ public class AsyncCallbackTemplate {
59 60 if (executor != null) {
60 61 Futures.addCallback(future, callback, executor);
61 62 } else {
62   - Futures.addCallback(future, callback);
  63 + Futures.addCallback(future, callback, MoreExecutors.directExecutor());
63 64 }
64 65 }
65 66
... ...
... ... @@ -18,19 +18,20 @@ package org.thingsboard.common.util;
18 18 import com.google.common.util.concurrent.FutureCallback;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22
22 23 import java.util.concurrent.Executor;
23 24 import java.util.function.Consumer;
24 25
25 26 public class DonAsynchron {
26 27
27   - public static <T> void withCallback(ListenableFuture<T> future, Consumer<T> onSuccess,
28   - Consumer<Throwable> onFailure) {
  28 + public static <T> void withCallback(ListenableFuture<T> future, Consumer<T> onSuccess,
  29 + Consumer<Throwable> onFailure) {
29 30 withCallback(future, onSuccess, onFailure, null);
30 31 }
31 32
32   - public static <T> void withCallback(ListenableFuture<T> future, Consumer<T> onSuccess,
33   - Consumer<Throwable> onFailure, Executor executor) {
  33 + public static <T> void withCallback(ListenableFuture<T> future, Consumer<T> onSuccess,
  34 + Consumer<Throwable> onFailure, Executor executor) {
34 35 FutureCallback<T> callback = new FutureCallback<T>() {
35 36 @Override
36 37 public void onSuccess(T result) {
... ... @@ -49,7 +50,7 @@ public class DonAsynchron {
49 50 if (executor != null) {
50 51 Futures.addCallback(future, callback, executor);
51 52 } else {
52   - Futures.addCallback(future, callback);
  53 + Futures.addCallback(future, callback, MoreExecutors.directExecutor());
53 54 }
54 55 }
55 56 }
... ...
... ... @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.JsonNode;
20 20 import com.google.common.base.Function;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.MoreExecutors;
23 24 import lombok.extern.slf4j.Slf4j;
24 25 import org.springframework.beans.factory.annotation.Autowired;
25 26 import org.springframework.stereotype.Service;
... ... @@ -53,7 +54,6 @@ import javax.annotation.Nullable;
53 54 import javax.annotation.PostConstruct;
54 55 import javax.annotation.PreDestroy;
55 56 import java.util.ArrayList;
56   -import java.util.Collections;
57 57 import java.util.Comparator;
58 58 import java.util.List;
59 59 import java.util.Set;
... ... @@ -264,9 +264,8 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
264 264 entityService.fetchEntityNameAsync(tenantId, alarmInfo.getOriginator()), originatorName -> {
265 265 alarmInfo.setOriginatorName(originatorName);
266 266 return alarmInfo;
267   - }
268   - );
269   - });
  267 + }, MoreExecutors.directExecutor());
  268 + }, MoreExecutors.directExecutor());
270 269 }
271 270
272 271 @Override
... ... @@ -283,11 +282,11 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
283 282 }
284 283 alarmInfo.setOriginatorName(originatorName);
285 284 return alarmInfo;
286   - }
  285 + }, MoreExecutors.directExecutor()
287 286 ));
288 287 }
289 288 return Futures.successfulAsList(alarmFutures);
290   - });
  289 + }, MoreExecutors.directExecutor());
291 290 }
292 291 return Futures.transform(alarms, new Function<List<AlarmInfo>, TimePageData<AlarmInfo>>() {
293 292 @Nullable
... ... @@ -295,7 +294,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
295 294 public TimePageData<AlarmInfo> apply(@Nullable List<AlarmInfo> alarms) {
296 295 return new TimePageData<>(alarms, query.getPageLink());
297 296 }
298   - });
  297 + }, MoreExecutors.directExecutor());
299 298 }
300 299
301 300 @Override
... ...
... ... @@ -20,6 +20,7 @@ import com.datastax.driver.core.querybuilder.QueryBuilder;
20 20 import com.datastax.driver.core.querybuilder.Select;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.MoreExecutors;
23 24 import lombok.extern.slf4j.Slf4j;
24 25 import org.springframework.beans.factory.annotation.Autowired;
25 26 import org.springframework.stereotype.Component;
... ... @@ -82,10 +83,10 @@ public class CassandraAlarmDao extends CassandraAbstractModelDao<AlarmEntity, Al
82 83 @Override
83 84 public Boolean deleteAlarm(TenantId tenantId, Alarm alarm) {
84 85 Statement delete = QueryBuilder.delete().all().from(getColumnFamilyName()).where(eq(ModelConstants.ID_PROPERTY, alarm.getId().getId()))
85   - .and(eq(ALARM_TENANT_ID_PROPERTY, tenantId.getId()))
86   - .and(eq(ALARM_ORIGINATOR_ID_PROPERTY, alarm.getOriginator().getId()))
87   - .and(eq(ALARM_ORIGINATOR_TYPE_PROPERTY, alarm.getOriginator().getEntityType()))
88   - .and(eq(ALARM_TYPE_PROPERTY, alarm.getType()));
  86 + .and(eq(ALARM_TENANT_ID_PROPERTY, tenantId.getId()))
  87 + .and(eq(ALARM_ORIGINATOR_ID_PROPERTY, alarm.getOriginator().getId()))
  88 + .and(eq(ALARM_ORIGINATOR_TYPE_PROPERTY, alarm.getOriginator().getEntityType()))
  89 + .and(eq(ALARM_TYPE_PROPERTY, alarm.getType()));
89 90 log.debug("Remove request: {}", delete.toString());
90 91 return executeWrite(tenantId, delete).wasApplied();
91 92 }
... ... @@ -122,10 +123,10 @@ public class CassandraAlarmDao extends CassandraAbstractModelDao<AlarmEntity, Al
122 123 for (EntityRelation relation : input) {
123 124 alarmFutures.add(Futures.transform(
124 125 findAlarmByIdAsync(tenantId, relation.getTo().getId()),
125   - AlarmInfo::new));
  126 + AlarmInfo::new, MoreExecutors.directExecutor()));
126 127 }
127 128 return Futures.successfulAsList(alarmFutures);
128   - });
  129 + }, MoreExecutors.directExecutor());
129 130 }
130 131
131 132 @Override
... ...
... ... @@ -16,9 +16,9 @@
16 16 package org.thingsboard.server.dao.asset;
17 17
18 18
19   -import com.google.common.base.Function;
20 19 import com.google.common.util.concurrent.Futures;
21 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
22 22 import lombok.extern.slf4j.Slf4j;
23 23 import org.hibernate.exception.ConstraintViolationException;
24 24 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -29,7 +29,6 @@ import org.springframework.cache.annotation.Cacheable;
29 29 import org.springframework.stereotype.Service;
30 30 import org.springframework.util.StringUtils;
31 31 import org.thingsboard.server.common.data.Customer;
32   -import org.thingsboard.server.common.data.Device;
33 32 import org.thingsboard.server.common.data.EntitySubtype;
34 33 import org.thingsboard.server.common.data.EntityType;
35 34 import org.thingsboard.server.common.data.EntityView;
... ... @@ -62,7 +61,10 @@ import java.util.stream.Collectors;
62 61 import static org.thingsboard.server.common.data.CacheConstants.ASSET_CACHE;
63 62 import static org.thingsboard.server.dao.DaoUtil.toUUIDs;
64 63 import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
65   -import static org.thingsboard.server.dao.service.Validator.*;
  64 +import static org.thingsboard.server.dao.service.Validator.validateId;
  65 +import static org.thingsboard.server.dao.service.Validator.validateIds;
  66 +import static org.thingsboard.server.dao.service.Validator.validatePageLink;
  67 +import static org.thingsboard.server.dao.service.Validator.validateString;
66 68
67 69 @Service
68 70 @Slf4j
... ... @@ -258,9 +260,9 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
258 260 }
259 261 }
260 262 return Futures.successfulAsList(futures);
261   - });
  263 + }, MoreExecutors.directExecutor());
262 264 assets = Futures.transform(assets, assetList ->
263   - assetList == null ? Collections.emptyList() : assetList.stream().filter(asset -> query.getAssetTypes().contains(asset.getType())).collect(Collectors.toList())
  265 + assetList == null ? Collections.emptyList() : assetList.stream().filter(asset -> query.getAssetTypes().contains(asset.getType())).collect(Collectors.toList()), MoreExecutors.directExecutor()
264 266 );
265 267 return assets;
266 268 }
... ... @@ -274,7 +276,7 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
274 276 assetTypes -> {
275 277 assetTypes.sort(Comparator.comparing(EntitySubtype::getType));
276 278 return assetTypes;
277   - });
  279 + }, MoreExecutors.directExecutor());
278 280 }
279 281
280 282 private DataValidator<Asset> assetValidator =
... ... @@ -335,18 +337,18 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
335 337 };
336 338
337 339 private PaginatedRemover<TenantId, Asset> tenantAssetsRemover =
338   - new PaginatedRemover<TenantId, Asset>() {
  340 + new PaginatedRemover<TenantId, Asset>() {
339 341
340   - @Override
341   - protected List<Asset> findEntities(TenantId tenantId, TenantId id, TextPageLink pageLink) {
342   - return assetDao.findAssetsByTenantId(id.getId(), pageLink);
343   - }
  342 + @Override
  343 + protected List<Asset> findEntities(TenantId tenantId, TenantId id, TextPageLink pageLink) {
  344 + return assetDao.findAssetsByTenantId(id.getId(), pageLink);
  345 + }
344 346
345   - @Override
346   - protected void removeEntity(TenantId tenantId, Asset entity) {
347   - deleteAsset(tenantId, new AssetId(entity.getId().getId()));
348   - }
349   - };
  347 + @Override
  348 + protected void removeEntity(TenantId tenantId, Asset entity) {
  349 + deleteAsset(tenantId, new AssetId(entity.getId().getId()));
  350 + }
  351 + };
350 352
351 353 private PaginatedRemover<CustomerId, Asset> customerAssetsUnasigner = new PaginatedRemover<CustomerId, Asset>() {
352 354
... ...
... ... @@ -23,6 +23,7 @@ import com.datastax.driver.mapping.Result;
23 23 import com.google.common.base.Function;
24 24 import com.google.common.util.concurrent.Futures;
25 25 import com.google.common.util.concurrent.ListenableFuture;
  26 +import com.google.common.util.concurrent.MoreExecutors;
26 27 import lombok.extern.slf4j.Slf4j;
27 28 import org.springframework.stereotype.Component;
28 29 import org.thingsboard.server.common.data.EntitySubtype;
... ... @@ -185,7 +186,7 @@ public class CassandraAssetDao extends CassandraAbstractSearchTextDao<AssetEntit
185 186 return Collections.emptyList();
186 187 }
187 188 }
188   - });
  189 + }, MoreExecutors.directExecutor());
189 190 }
190 191
191 192 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.dashboard;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.springframework.beans.factory.annotation.Autowired;
22 23 import org.springframework.stereotype.Component;
... ... @@ -85,7 +86,7 @@ public class CassandraDashboardInfoDao extends CassandraAbstractSearchTextDao<Da
85 86 dashboardFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId()));
86 87 }
87 88 return Futures.successfulAsList(dashboardFutures);
88   - });
  89 + }, MoreExecutors.directExecutor());
89 90 }
90 91
91 92 }
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.dashboard;
18 18 import com.google.common.base.Function;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.apache.commons.lang3.StringUtils;
23 24 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -64,7 +65,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
64 65
65 66 @Autowired
66 67 private TenantDao tenantDao;
67   -
  68 +
68 69 @Autowired
69 70 private CustomerDao customerDao;
70 71
... ... @@ -102,7 +103,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
102 103 dashboardValidator.validate(dashboard, DashboardInfo::getTenantId);
103 104 return dashboardDao.save(dashboard.getTenantId(), dashboard);
104 105 }
105   -
  106 +
106 107 @Override
107 108 public Dashboard assignDashboardToCustomer(TenantId tenantId, DashboardId dashboardId, CustomerId customerId) {
108 109 Dashboard dashboard = findDashboardById(tenantId, dashboardId);
... ... @@ -203,7 +204,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
203 204 public TimePageData<DashboardInfo> apply(@Nullable List<DashboardInfo> dashboards) {
204 205 return new TimePageData<>(dashboards, pageLink);
205 206 }
206   - });
  207 + }, MoreExecutors.directExecutor());
207 208 }
208 209
209 210 @Override
... ... @@ -244,24 +245,24 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
244 245 }
245 246 }
246 247 }
247   - };
248   -
  248 + };
  249 +
249 250 private PaginatedRemover<TenantId, DashboardInfo> tenantDashboardsRemover =
250 251 new PaginatedRemover<TenantId, DashboardInfo>() {
251   -
252   - @Override
253   - protected List<DashboardInfo> findEntities(TenantId tenantId, TenantId id, TextPageLink pageLink) {
254   - return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink);
255   - }
256 252
257   - @Override
258   - protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
259   - deleteDashboard(tenantId, new DashboardId(entity.getUuidId()));
260   - }
261   - };
262   -
  253 + @Override
  254 + protected List<DashboardInfo> findEntities(TenantId tenantId, TenantId id, TextPageLink pageLink) {
  255 + return dashboardInfoDao.findDashboardsByTenantId(id.getId(), pageLink);
  256 + }
  257 +
  258 + @Override
  259 + protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
  260 + deleteDashboard(tenantId, new DashboardId(entity.getUuidId()));
  261 + }
  262 + };
  263 +
263 264 private class CustomerDashboardsUnassigner extends TimePaginatedRemover<Customer, DashboardInfo> {
264   -
  265 +
265 266 private Customer customer;
266 267
267 268 CustomerDashboardsUnassigner(Customer customer) {
... ... @@ -282,7 +283,7 @@ public class DashboardServiceImpl extends AbstractEntityService implements Dashb
282 283 protected void removeEntity(TenantId tenantId, DashboardInfo entity) {
283 284 unassignDashboardFromCustomer(customer.getTenantId(), new DashboardId(entity.getUuidId()), this.customer.getId());
284 285 }
285   -
  286 +
286 287 }
287 288
288 289 private class CustomerDashboardsUpdater extends TimePaginatedRemover<Customer, DashboardInfo> {
... ...
... ... @@ -23,6 +23,7 @@ import com.datastax.driver.mapping.Result;
23 23 import com.google.common.base.Function;
24 24 import com.google.common.util.concurrent.Futures;
25 25 import com.google.common.util.concurrent.ListenableFuture;
  26 +import com.google.common.util.concurrent.MoreExecutors;
26 27 import lombok.extern.slf4j.Slf4j;
27 28 import org.springframework.stereotype.Component;
28 29 import org.thingsboard.server.common.data.Device;
... ... @@ -178,14 +179,14 @@ public class CassandraDeviceDao extends CassandraAbstractSearchTextDao<DeviceEnt
178 179 if (result != null) {
179 180 List<EntitySubtype> entitySubtypes = new ArrayList<>();
180 181 result.all().forEach((entitySubtypeEntity) ->
181   - entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())
  182 + entitySubtypes.add(entitySubtypeEntity.toEntitySubtype())
182 183 );
183 184 return entitySubtypes;
184 185 } else {
185 186 return Collections.emptyList();
186 187 }
187 188 }
188   - });
  189 + }, MoreExecutors.directExecutor());
189 190 }
190 191
191 192 }
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.device;
18 18 import com.fasterxml.jackson.databind.ObjectMapper;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.springframework.beans.factory.annotation.Autowired;
23 24 import org.springframework.beans.factory.annotation.Value;
... ... @@ -97,9 +98,9 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService {
97 98 }
98 99 log.warn("Failed to find claimingAllowed attribute for device or it is already claimed![{}]", device.getName());
99 100 throw new IllegalArgumentException();
100   - });
  101 + }, MoreExecutors.directExecutor());
101 102 }
102   - });
  103 + }, MoreExecutors.directExecutor());
103 104 }
104 105
105 106 private ClaimDataInfo getClaimData(Cache cache, Device device) throws ExecutionException, InterruptedException {
... ... @@ -138,9 +139,9 @@ public class ClaimDevicesServiceImpl implements ClaimDevicesService {
138 139 if (device.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) {
139 140 device.setCustomerId(customerId);
140 141 Device savedDevice = deviceService.saveDevice(device);
141   - return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(savedDevice, ClaimResponse.SUCCESS));
  142 + return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(savedDevice, ClaimResponse.SUCCESS), MoreExecutors.directExecutor());
142 143 }
143   - return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(null, ClaimResponse.CLAIMED));
  144 + return Futures.transform(removeClaimingSavedData(cache, claimData, device), result -> new ClaimResult(null, ClaimResponse.CLAIMED), MoreExecutors.directExecutor());
144 145 }
145 146 } else {
146 147 log.warn("Failed to find the device's claiming message![{}]", device.getName());
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.device;
18 18 import com.google.common.base.Function;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.apache.commons.lang3.RandomStringUtils;
23 24 import org.hibernate.exception.ConstraintViolationException;
... ... @@ -291,7 +292,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
291 292 }
292 293 }
293 294 return Futures.successfulAsList(futures);
294   - });
  295 + }, MoreExecutors.directExecutor());
295 296
296 297 devices = Futures.transform(devices, new Function<List<Device>, List<Device>>() {
297 298 @Nullable
... ... @@ -299,7 +300,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
299 300 public List<Device> apply(@Nullable List<Device> deviceList) {
300 301 return deviceList == null ? Collections.emptyList() : deviceList.stream().filter(device -> query.getDeviceTypes().contains(device.getType())).collect(Collectors.toList());
301 302 }
302   - });
  303 + }, MoreExecutors.directExecutor());
303 304
304 305 return devices;
305 306 }
... ... @@ -313,7 +314,7 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
313 314 deviceTypes -> {
314 315 deviceTypes.sort(Comparator.comparing(EntitySubtype::getType));
315 316 return deviceTypes;
316   - });
  317 + }, MoreExecutors.directExecutor());
317 318 }
318 319
319 320 private DataValidator<Device> deviceValidator =
... ... @@ -374,18 +375,18 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
374 375 };
375 376
376 377 private PaginatedRemover<TenantId, Device> tenantDevicesRemover =
377   - new PaginatedRemover<TenantId, Device>() {
  378 + new PaginatedRemover<TenantId, Device>() {
378 379
379   - @Override
380   - protected List<Device> findEntities(TenantId tenantId, TenantId id, TextPageLink pageLink) {
381   - return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
382   - }
  380 + @Override
  381 + protected List<Device> findEntities(TenantId tenantId, TenantId id, TextPageLink pageLink) {
  382 + return deviceDao.findDevicesByTenantId(id.getId(), pageLink);
  383 + }
383 384
384   - @Override
385   - protected void removeEntity(TenantId tenantId, Device entity) {
386   - deleteDevice(tenantId, new DeviceId(entity.getUuidId()));
387   - }
388   - };
  385 + @Override
  386 + protected void removeEntity(TenantId tenantId, Device entity) {
  387 + deleteDevice(tenantId, new DeviceId(entity.getUuidId()));
  388 + }
  389 + };
389 390
390 391 private PaginatedRemover<CustomerId, Device> customerDeviceUnasigner = new PaginatedRemover<CustomerId, Device>() {
391 392
... ...
... ... @@ -18,12 +18,21 @@ package org.thingsboard.server.dao.entity;
18 18 import com.google.common.base.Function;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.springframework.beans.factory.annotation.Autowired;
23 24 import org.springframework.stereotype.Service;
24 25 import org.thingsboard.server.common.data.HasName;
25 26 import org.thingsboard.server.common.data.alarm.AlarmId;
26   -import org.thingsboard.server.common.data.id.*;
  27 +import org.thingsboard.server.common.data.id.AssetId;
  28 +import org.thingsboard.server.common.data.id.CustomerId;
  29 +import org.thingsboard.server.common.data.id.DashboardId;
  30 +import org.thingsboard.server.common.data.id.DeviceId;
  31 +import org.thingsboard.server.common.data.id.EntityId;
  32 +import org.thingsboard.server.common.data.id.EntityViewId;
  33 +import org.thingsboard.server.common.data.id.RuleChainId;
  34 +import org.thingsboard.server.common.data.id.TenantId;
  35 +import org.thingsboard.server.common.data.id.UserId;
27 36 import org.thingsboard.server.dao.alarm.AlarmService;
28 37 import org.thingsboard.server.dao.asset.AssetService;
29 38 import org.thingsboard.server.dao.customer.CustomerService;
... ... @@ -109,7 +118,7 @@ public class BaseEntityService extends AbstractEntityService implements EntitySe
109 118 default:
110 119 throw new IllegalStateException("Not Implemented!");
111 120 }
112   - entityName = Futures.transform(hasName, (Function<HasName, String>) hasName1 -> hasName1 != null ? hasName1.getName() : null );
  121 + entityName = Futures.transform(hasName, (Function<HasName, String>) hasName1 -> hasName1 != null ? hasName1.getName() : null, MoreExecutors.directExecutor());
113 122 return entityName;
114 123 }
115 124
... ...
... ... @@ -23,6 +23,7 @@ import com.datastax.driver.mapping.Result;
23 23 import com.google.common.base.Function;
24 24 import com.google.common.util.concurrent.Futures;
25 25 import com.google.common.util.concurrent.ListenableFuture;
  26 +import com.google.common.util.concurrent.MoreExecutors;
26 27 import lombok.extern.slf4j.Slf4j;
27 28 import org.springframework.stereotype.Component;
28 29 import org.thingsboard.server.common.data.EntitySubtype;
... ... @@ -97,7 +98,7 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit
97 98 log.debug("Try to find entity views by tenantId [{}] and pageLink [{}]", tenantId, pageLink);
98 99 List<EntityViewEntity> entityViewEntities =
99 100 findPageWithTextSearch(new TenantId(tenantId), ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_CF,
100   - Collections.singletonList(eq(TENANT_ID_PROPERTY, tenantId)), pageLink);
  101 + Collections.singletonList(eq(TENANT_ID_PROPERTY, tenantId)), pageLink);
101 102 log.trace("Found entity views [{}] by tenantId [{}] and pageLink [{}]",
102 103 entityViewEntities, tenantId, pageLink);
103 104 return DaoUtil.convertDataList(entityViewEntities);
... ... @@ -181,6 +182,6 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit
181 182 return Collections.emptyList();
182 183 }
183 184 }
184   - });
  185 + }, MoreExecutors.directExecutor());
185 186 }
186 187 }
... ...
... ... @@ -19,6 +19,7 @@ import com.google.common.base.Function;
19 19 import com.google.common.util.concurrent.FutureCallback;
20 20 import com.google.common.util.concurrent.Futures;
21 21 import com.google.common.util.concurrent.ListenableFuture;
  22 +import com.google.common.util.concurrent.MoreExecutors;
22 23 import lombok.extern.slf4j.Slf4j;
23 24 import org.apache.commons.lang3.StringUtils;
24 25 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -199,7 +200,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
199 200 }
200 201 }
201 202 return Futures.successfulAsList(futures);
202   - });
  203 + }, MoreExecutors.directExecutor());
203 204
204 205 entityViews = Futures.transform(entityViews, new Function<List<EntityView>, List<EntityView>>() {
205 206 @Nullable
... ... @@ -207,7 +208,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
207 208 public List<EntityView> apply(@Nullable List<EntityView> entityViewList) {
208 209 return entityViewList == null ? Collections.emptyList() : entityViewList.stream().filter(entityView -> query.getEntityViewTypes().contains(entityView.getType())).collect(Collectors.toList());
209 210 }
210   - });
  211 + }, MoreExecutors.directExecutor());
211 212
212 213 return entityViews;
213 214 }
... ... @@ -246,7 +247,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
246 247 public void onFailure(Throwable t) {
247 248 log.error("Error while finding entity views by tenantId and entityId", t);
248 249 }
249   - });
  250 + }, MoreExecutors.directExecutor());
250 251 return entityViewsFuture;
251 252 }
252 253 }
... ... @@ -279,7 +280,7 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
279 280 entityViewTypes -> {
280 281 entityViewTypes.sort(Comparator.comparing(EntitySubtype::getType));
281 282 return entityViewTypes;
282   - });
  283 + }, MoreExecutors.directExecutor());
283 284 }
284 285
285 286 private DataValidator<EntityView> entityViewValidator =
... ...
... ... @@ -22,6 +22,7 @@ import com.datastax.driver.core.querybuilder.Select;
22 22 import com.datastax.driver.core.utils.UUIDs;
23 23 import com.google.common.util.concurrent.Futures;
24 24 import com.google.common.util.concurrent.ListenableFuture;
  25 +import com.google.common.util.concurrent.MoreExecutors;
25 26 import lombok.extern.slf4j.Slf4j;
26 27 import org.apache.commons.lang3.StringUtils;
27 28 import org.springframework.beans.factory.annotation.Value;
... ... @@ -45,10 +46,12 @@ import java.util.UUID;
45 46 import java.util.concurrent.ExecutionException;
46 47
47 48 import static com.datastax.driver.core.querybuilder.QueryBuilder.eq;
48   -import static com.datastax.driver.core.querybuilder.QueryBuilder.in;
49 49 import static com.datastax.driver.core.querybuilder.QueryBuilder.select;
50 50 import static com.datastax.driver.core.querybuilder.QueryBuilder.ttl;
51   -import static org.thingsboard.server.dao.model.ModelConstants.*;
  51 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_BY_ID_VIEW_NAME;
  52 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_BY_TYPE_AND_ID_VIEW_NAME;
  53 +import static org.thingsboard.server.dao.model.ModelConstants.EVENT_COLUMN_FAMILY_NAME;
  54 +import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
52 55
53 56 @Component
54 57 @Slf4j
... ... @@ -96,7 +99,7 @@ public class CassandraBaseEventDao extends CassandraAbstractSearchTimeDao<EventE
96 99 event.setUid(event.getId().toString());
97 100 }
98 101 ListenableFuture<Optional<Event>> optionalSave = saveAsync(event.getTenantId(), new EventEntity(event), false, eventsTtl);
99   - return Futures.transform(optionalSave, opt -> opt.orElse(null));
  102 + return Futures.transform(optionalSave, opt -> opt.orElse(null), MoreExecutors.directExecutor());
100 103 }
101 104
102 105 @Override
... ... @@ -210,6 +213,6 @@ public class CassandraBaseEventDao extends CassandraAbstractSearchTimeDao<EventE
210 213 } else {
211 214 return Optional.empty();
212 215 }
213   - });
  216 + }, MoreExecutors.directExecutor());
214 217 }
215 218 }
... ...
... ... @@ -26,6 +26,7 @@ import com.datastax.driver.mapping.Result;
26 26 import com.google.common.base.Function;
27 27 import com.google.common.util.concurrent.Futures;
28 28 import com.google.common.util.concurrent.ListenableFuture;
  29 +import com.google.common.util.concurrent.MoreExecutors;
29 30 import lombok.extern.slf4j.Slf4j;
30 31 import org.thingsboard.server.common.data.id.TenantId;
31 32 import org.thingsboard.server.dao.Dao;
... ... @@ -86,7 +87,7 @@ public abstract class CassandraAbstractModelDao<E extends BaseEntity<D>, D> exte
86 87 return Collections.emptyList();
87 88 }
88 89 }
89   - });
  90 + }, MoreExecutors.directExecutor());
90 91 }
91 92 return Futures.immediateFuture(Collections.emptyList());
92 93 }
... ... @@ -120,7 +121,7 @@ public abstract class CassandraAbstractModelDao<E extends BaseEntity<D>, D> exte
120 121 return null;
121 122 }
122 123 }
123   - });
  124 + }, MoreExecutors.directExecutor());
124 125 }
125 126 return Futures.immediateFuture(null);
126 127 }
... ... @@ -191,5 +192,5 @@ public abstract class CassandraAbstractModelDao<E extends BaseEntity<D>, D> exte
191 192 List<E> entities = findListByStatement(tenantId, QueryBuilder.select().all().from(getColumnFamilyName()).setConsistencyLevel(cluster.getDefaultReadConsistencyLevel()));
192 193 return DaoUtil.convertDataList(entities);
193 194 }
194   -
  195 +
195 196 }
... ...
... ... @@ -22,6 +22,7 @@ import com.datastax.driver.core.Statement;
22 22 import com.google.common.util.concurrent.FutureCallback;
23 23 import com.google.common.util.concurrent.Futures;
24 24 import com.google.common.util.concurrent.ListenableFuture;
  25 +import com.google.common.util.concurrent.MoreExecutors;
25 26 import com.google.common.util.concurrent.Uninterruptibles;
26 27 import org.thingsboard.server.dao.exception.BufferLimitException;
27 28 import org.thingsboard.server.dao.util.AsyncRateLimiter;
... ... @@ -44,9 +45,9 @@ public class RateLimitedResultSetFuture implements ResultSetFuture {
44 45 rateLimiter.release();
45 46 }
46 47 return Futures.immediateFailedFuture(t);
47   - });
  48 + }, MoreExecutors.directExecutor());
48 49 this.originalFuture = Futures.transform(rateLimitFuture,
49   - i -> executeAsyncWithRelease(rateLimiter, session, statement));
  50 + i -> executeAsyncWithRelease(rateLimiter, session, statement), MoreExecutors.directExecutor());
50 51
51 52 }
52 53
... ... @@ -145,7 +146,7 @@ public class RateLimitedResultSetFuture implements ResultSetFuture {
145 146 public void onFailure(Throwable t) {
146 147 rateLimiter.release();
147 148 }
148   - });
  149 + }, MoreExecutors.directExecutor());
149 150 return resultSetFuture;
150 151 } catch (RuntimeException re) {
151 152 rateLimiter.release();
... ...
... ... @@ -16,7 +16,10 @@
16 16 package org.thingsboard.server.dao.relation;
17 17
18 18 import com.google.common.base.Function;
19   -import com.google.common.util.concurrent.*;
  19 +import com.google.common.util.concurrent.FutureCallback;
  20 +import com.google.common.util.concurrent.Futures;
  21 +import com.google.common.util.concurrent.ListenableFuture;
  22 +import com.google.common.util.concurrent.MoreExecutors;
20 23 import lombok.extern.slf4j.Slf4j;
21 24 import org.springframework.beans.factory.annotation.Autowired;
22 25 import org.springframework.cache.Cache;
... ... @@ -206,17 +209,20 @@ public class BaseRelationService implements RelationService {
206 209 relations -> {
207 210 List<ListenableFuture<Boolean>> results = deleteRelationGroupsAsync(tenantId, relations, cache, true);
208 211 return Futures.allAsList(results);
209   - });
  212 + }, MoreExecutors.directExecutor());
210 213
211 214 ListenableFuture<List<Boolean>> outboundDeletions = Futures.transformAsync(outboundRelations,
212 215 relations -> {
213 216 List<ListenableFuture<Boolean>> results = deleteRelationGroupsAsync(tenantId, relations, cache, false);
214 217 return Futures.allAsList(results);
215   - });
  218 + }, MoreExecutors.directExecutor());
216 219
217 220 ListenableFuture<List<List<Boolean>>> deletionsFuture = Futures.allAsList(inboundDeletions, outboundDeletions);
218 221
219   - return Futures.transform(Futures.transformAsync(deletionsFuture, (deletions) -> relationDao.deleteOutboundRelationsAsync(tenantId, entityId)), result -> null);
  222 + return Futures.transform(Futures.transformAsync(deletionsFuture,
  223 + (deletions) -> relationDao.deleteOutboundRelationsAsync(tenantId, entityId),
  224 + MoreExecutors.directExecutor()),
  225 + result -> null, MoreExecutors.directExecutor());
220 226 }
221 227
222 228 private List<ListenableFuture<Boolean>> deleteRelationGroupsAsync(TenantId tenantId, List<List<EntityRelation>> relations, Cache cache, boolean deleteFromDb) {
... ... @@ -306,9 +312,11 @@ public class BaseRelationService implements RelationService {
306 312 public void onSuccess(@Nullable List<EntityRelation> result) {
307 313 cache.putIfAbsent(fromAndTypeGroup, result);
308 314 }
  315 +
309 316 @Override
310   - public void onFailure(Throwable t) {}
311   - });
  317 + public void onFailure(Throwable t) {
  318 + }
  319 + }, MoreExecutors.directExecutor());
312 320 return relationsFuture;
313 321 }
314 322 }
... ... @@ -328,7 +336,7 @@ public class BaseRelationService implements RelationService {
328 336 EntityRelationInfo::setToName))
329 337 );
330 338 return Futures.successfulAsList(futures);
331   - });
  339 + }, MoreExecutors.directExecutor());
332 340 }
333 341
334 342 @Cacheable(cacheNames = RELATIONS_CACHE, key = "{#from, #relationType, #typeGroup, 'FROM'}")
... ... @@ -385,9 +393,11 @@ public class BaseRelationService implements RelationService {
385 393 public void onSuccess(@Nullable List<EntityRelation> result) {
386 394 cache.putIfAbsent(toAndTypeGroup, result);
387 395 }
  396 +
388 397 @Override
389   - public void onFailure(Throwable t) {}
390   - });
  398 + public void onFailure(Throwable t) {
  399 + }
  400 + }, MoreExecutors.directExecutor());
391 401 return relationsFuture;
392 402 }
393 403 }
... ... @@ -407,7 +417,7 @@ public class BaseRelationService implements RelationService {
407 417 EntityRelationInfo::setFromName))
408 418 );
409 419 return Futures.successfulAsList(futures);
410   - });
  420 + }, MoreExecutors.directExecutor());
411 421 }
412 422
413 423 private ListenableFuture<EntityRelationInfo> fetchRelationInfoAsync(TenantId tenantId, EntityRelation relation,
... ... @@ -418,7 +428,7 @@ public class BaseRelationService implements RelationService {
418 428 EntityRelationInfo entityRelationInfo1 = new EntityRelationInfo(relation);
419 429 entityNameSetter.accept(entityRelationInfo1, entityName1);
420 430 return entityRelationInfo1;
421   - });
  431 + }, MoreExecutors.directExecutor());
422 432 }
423 433
424 434 @Cacheable(cacheNames = RELATIONS_CACHE, key = "{#to, #relationType, #typeGroup, 'TO'}")
... ... @@ -466,7 +476,7 @@ public class BaseRelationService implements RelationService {
466 476 }
467 477 }
468 478 return relations;
469   - });
  479 + }, MoreExecutors.directExecutor());
470 480 } catch (Exception e) {
471 481 log.warn("Failed to query relations: [{}]", query, e);
472 482 throw new RuntimeException(e);
... ... @@ -493,7 +503,7 @@ public class BaseRelationService implements RelationService {
493 503 }))
494 504 );
495 505 return Futures.successfulAsList(futures);
496   - });
  506 + }, MoreExecutors.directExecutor());
497 507 }
498 508
499 509 protected void validate(EntityRelation relation) {
... ... @@ -600,7 +610,7 @@ public class BaseRelationService implements RelationService {
600 610 }
601 611 //TODO: try to remove this blocking operation
602 612 List<Set<EntityRelation>> relations = Futures.successfulAsList(futures).get();
603   - if (fetchLastLevelOnly && lvl > 0){
  613 + if (fetchLastLevelOnly && lvl > 0) {
604 614 children.clear();
605 615 }
606 616 relations.forEach(r -> r.forEach(children::add));
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.alarm;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.springframework.beans.factory.annotation.Autowired;
22 23 import org.springframework.data.domain.PageRequest;
... ... @@ -108,9 +109,9 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
108 109 for (EntityRelation relation : input) {
109 110 alarmFutures.add(Futures.transform(
110 111 findAlarmByIdAsync(tenantId, relation.getTo().getId()),
111   - AlarmInfo::new));
  112 + AlarmInfo::new, MoreExecutors.directExecutor()));
112 113 }
113 114 return Futures.successfulAsList(alarmFutures);
114   - });
  115 + }, MoreExecutors.directExecutor());
115 116 }
116 117 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sql.dashboard;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.springframework.beans.factory.annotation.Autowired;
22 23 import org.springframework.data.domain.PageRequest;
... ... @@ -91,6 +92,6 @@ public class JpaDashboardInfoDao extends JpaAbstractSearchTextDao<DashboardInfoE
91 92 dashboardFutures.add(findByIdAsync(new TenantId(tenantId), relation.getTo().getId()));
92 93 }
93 94 return Futures.successfulAsList(dashboardFutures);
94   - });
  95 + }, MoreExecutors.directExecutor());
95 96 }
96 97 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sqlts;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import com.google.common.util.concurrent.SettableFuture;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -168,7 +169,7 @@ public abstract class AbstractChunkedAggregationTimeseriesDao extends AbstractSq
168 169 } else {
169 170 return Optional.empty();
170 171 }
171   - });
  172 + }, MoreExecutors.directExecutor());
172 173 }
173 174
174 175 protected void switchAggregation(TenantId tenantId, EntityId entityId, String key, long startTs, long endTs, Aggregation aggregation, List<CompletableFuture<TsKvEntity>> entitiesFutures) {
... ...
... ... @@ -20,6 +20,7 @@ import com.google.common.collect.Lists;
20 20 import com.google.common.util.concurrent.FutureCallback;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.MoreExecutors;
23 24 import lombok.extern.slf4j.Slf4j;
24 25 import org.hibernate.exception.ConstraintViolationException;
25 26 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -235,7 +236,7 @@ public abstract class AbstractSqlTimeseriesDao extends JpaAbstractDaoListeningEx
235 236 public void onFailure(Throwable t) {
236 237 log.warn("[{}] Failed to process remove of the latest value", entityId, t);
237 238 }
238   - });
  239 + }, MoreExecutors.directExecutor());
239 240 return resultFuture;
240 241 }
241 242
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.sqlts.timescale;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import com.google.common.util.concurrent.SettableFuture;
21 22 import lombok.extern.slf4j.Slf4j;
22 23 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -143,7 +144,7 @@ public class TimescaleTimeseriesDao extends AbstractSqlTimeseriesDao implements
143 144 } else {
144 145 return Collections.emptyList();
145 146 }
146   - });
  147 + }, MoreExecutors.directExecutor());
147 148 }
148 149
149 150 @Override
... ...
... ... @@ -28,6 +28,7 @@ import com.google.common.util.concurrent.AsyncFunction;
28 28 import com.google.common.util.concurrent.FutureCallback;
29 29 import com.google.common.util.concurrent.Futures;
30 30 import com.google.common.util.concurrent.ListenableFuture;
  31 +import com.google.common.util.concurrent.MoreExecutors;
31 32 import lombok.extern.slf4j.Slf4j;
32 33 import org.apache.commons.lang3.StringUtils;
33 34 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -330,7 +331,7 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
330 331 stmt.setInt(6, (int) ttl);
331 332 }
332 333 futures.add(getFuture(executeAsyncWrite(tenantId, stmt), rs -> null));
333   - return Futures.transform(Futures.allAsList(futures), result -> null);
  334 + return Futures.transform(Futures.allAsList(futures), result -> null, MoreExecutors.directExecutor());
334 335 }
335 336
336 337 private void processSetNullValues(TenantId tenantId, EntityId entityId, TsKvEntry tsKvEntry, long ttl, List<ListenableFuture<Void>> futures, long partition, DataType type) {
... ... @@ -545,7 +546,7 @@ public class CassandraBaseTimeseriesDao extends CassandraAbstractAsyncDao implem
545 546 public void onFailure(Throwable t) {
546 547 log.warn("[{}] Failed to process remove of the latest value", entityId, t);
547 548 }
548   - });
  549 + }, MoreExecutors.directExecutor());
549 550 return resultFuture;
550 551 }
551 552
... ...
... ... @@ -119,7 +119,7 @@ public class RateLimitedResultSetFutureTest {
119 119
120 120 resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
121 121
122   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one);
  122 + ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
123 123 Row actualRow = transform.get();
124 124
125 125 assertSame(row, actualRow);
... ... @@ -132,7 +132,7 @@ public class RateLimitedResultSetFutureTest {
132 132 when(rateLimiter.acquireAsync()).thenReturn(Futures.immediateFuture(null));
133 133 when(session.executeAsync(statement)).thenThrow(new UnsupportedFeatureException(ProtocolVersion.V3, "hjg"));
134 134 resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
135   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one);
  135 + ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
136 136 try {
137 137 transform.get();
138 138 fail();
... ... @@ -156,7 +156,7 @@ public class RateLimitedResultSetFutureTest {
156 156
157 157 when(realFuture.get()).thenThrow(new ExecutionException("Fail", new TimeoutException("timeout")));
158 158 resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
159   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one);
  159 + ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
160 160 try {
161 161 transform.get();
162 162 fail();
... ... @@ -177,7 +177,7 @@ public class RateLimitedResultSetFutureTest {
177 177 when(rateLimiter.acquireAsync()).thenReturn(future);
178 178 resultSetFuture = new RateLimitedResultSetFuture(session, rateLimiter, statement);
179 179
180   - ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one);
  180 + ListenableFuture<Row> transform = Futures.transform(resultSetFuture, ResultSet::one, MoreExecutors.directExecutor());
181 181 // TimeUnit.MILLISECONDS.sleep(200);
182 182 future.cancel(false);
183 183 latch.countDown();
... ...
... ... @@ -44,7 +44,7 @@
44 44 <cassandra.version>3.6.0</cassandra.version>
45 45 <cassandra-unit.version>3.5.0.1</cassandra-unit.version>
46 46 <takari-cpsuite.version>1.2.7</takari-cpsuite.version>
47   - <guava.version>21.0</guava.version>
  47 + <guava.version>28.2-jre</guava.version>
48 48 <caffeine.version>2.6.1</caffeine.version>
49 49 <commons-lang3.version>3.4</commons-lang3.version>
50 50 <commons-validator.version>1.6</commons-validator.version>
... ... @@ -63,7 +63,7 @@
63 63 <mail.version>1.4.3</mail.version>
64 64 <curator.version>4.2.0</curator.version>
65 65 <zookeeper.version>3.5.5</zookeeper.version>
66   - <protobuf.version>3.6.1</protobuf.version>
  66 + <protobuf.version>3.11.4</protobuf.version>
67 67 <grpc.version>1.22.1</grpc.version>
68 68 <lombok.version>1.16.18</lombok.version>
69 69 <paho.client.version>1.1.0</paho.client.version>
... ...
... ... @@ -20,6 +20,7 @@ import com.google.common.cache.CacheLoader;
20 20 import com.google.common.cache.LoadingCache;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.MoreExecutors;
23 24 import lombok.AllArgsConstructor;
24 25 import lombok.Data;
25 26 import lombok.NoArgsConstructor;
... ... @@ -54,9 +55,9 @@ import java.util.List;
54 55 import java.util.Optional;
55 56 import java.util.concurrent.TimeUnit;
56 57
  58 +import static org.thingsboard.common.util.DonAsynchron.withCallback;
57 59 import static org.thingsboard.rule.engine.api.TbRelationTypes.FAILURE;
58 60 import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
59   -import static org.thingsboard.common.util.DonAsynchron.withCallback;
60 61
61 62 @Slf4j
62 63 public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationActionNodeConfiguration> implements TbNode {
... ... @@ -86,7 +87,7 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
86 87 }
87 88
88 89 protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg) {
89   - return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer));
  90 + return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer), MoreExecutors.directExecutor());
90 91 }
91 92
92 93 protected abstract boolean createEntityIfNotExists();
... ...
... ... @@ -18,12 +18,13 @@ package org.thingsboard.rule.engine.action;
18 18 import com.fasterxml.jackson.databind.JsonNode;
19 19 import com.google.common.util.concurrent.Futures;
20 20 import com.google.common.util.concurrent.ListenableFuture;
  21 +import com.google.common.util.concurrent.MoreExecutors;
21 22 import lombok.extern.slf4j.Slf4j;
22   -import org.thingsboard.rule.engine.api.util.TbNodeUtils;
23 23 import org.thingsboard.rule.engine.api.RuleNode;
24 24 import org.thingsboard.rule.engine.api.TbContext;
25 25 import org.thingsboard.rule.engine.api.TbNodeConfiguration;
26 26 import org.thingsboard.rule.engine.api.TbNodeException;
  27 +import org.thingsboard.rule.engine.api.util.TbNodeUtils;
27 28 import org.thingsboard.server.common.data.alarm.Alarm;
28 29 import org.thingsboard.server.common.data.alarm.AlarmStatus;
29 30 import org.thingsboard.server.common.data.plugin.ComponentType;
... ... @@ -80,8 +81,8 @@ public class TbClearAlarmNode extends TbAbstractAlarmNode<TbClearAlarmNodeConfig
80 81 }
81 82 alarm.setStatus(alarm.getStatus().isAck() ? AlarmStatus.CLEARED_ACK : AlarmStatus.CLEARED_UNACK);
82 83 return Futures.immediateFuture(new AlarmResult(false, false, true, alarm));
83   - });
84   - });
  84 + }, MoreExecutors.directExecutor());
  85 + }, MoreExecutors.directExecutor());
85 86 }, ctx.getDbCallbackExecutor());
86 87 }
87 88 }
... ...
... ... @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
20 20 import com.google.common.base.Function;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
  23 +import com.google.common.util.concurrent.MoreExecutors;
23 24 import lombok.extern.slf4j.Slf4j;
24 25 import org.thingsboard.rule.engine.api.RuleNode;
25 26 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -108,18 +109,18 @@ public class TbCreateAlarmNode extends TbAbstractAlarmNode<TbCreateAlarmNodeConf
108 109 private ListenableFuture<AlarmResult> createNewAlarm(TbContext ctx, TbMsg msg, Alarm msgAlarm) {
109 110 ListenableFuture<Alarm> asyncAlarm;
110 111 if (msgAlarm != null) {
111   - asyncAlarm = Futures.immediateCheckedFuture(msgAlarm);
  112 + asyncAlarm = Futures.immediateFuture(msgAlarm);
112 113 } else {
113 114 ctx.logJsEvalRequest();
114 115 asyncAlarm = Futures.transform(buildAlarmDetails(ctx, msg, null),
115 116 details -> {
116 117 ctx.logJsEvalResponse();
117 118 return buildAlarm(msg, details, ctx.getTenantId());
118   - });
  119 + }, MoreExecutors.directExecutor());
119 120 }
120 121 ListenableFuture<Alarm> asyncCreated = Futures.transform(asyncAlarm,
121 122 alarm -> ctx.getAlarmService().createOrUpdateAlarm(alarm), ctx.getDbCallbackExecutor());
122   - return Futures.transform(asyncCreated, alarm -> new AlarmResult(true, false, false, alarm));
  123 + return Futures.transform(asyncCreated, alarm -> new AlarmResult(true, false, false, alarm), MoreExecutors.directExecutor());
123 124 }
124 125
125 126 private ListenableFuture<AlarmResult> updateAlarm(TbContext ctx, TbMsg msg, Alarm existingAlarm, Alarm msgAlarm) {
... ... @@ -140,7 +141,7 @@ public class TbCreateAlarmNode extends TbAbstractAlarmNode<TbCreateAlarmNodeConf
140 141 return ctx.getAlarmService().createOrUpdateAlarm(existingAlarm);
141 142 }, ctx.getDbCallbackExecutor());
142 143
143   - return Futures.transform(asyncUpdated, a -> new AlarmResult(false, true, false, a));
  144 + return Futures.transform(asyncUpdated, a -> new AlarmResult(false, true, false, a), MoreExecutors.directExecutor());
144 145 }
145 146
146 147 private Alarm buildAlarm(TbMsg msg, JsonNode details, TenantId tenantId) {
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.action;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.thingsboard.rule.engine.api.RuleNode;
22 23 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -81,7 +82,7 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
81 82 }
82 83 container.setResult(result);
83 84 return container;
84   - });
  85 + }, MoreExecutors.directExecutor());
85 86 }
86 87
87 88 private ListenableFuture<Boolean> createIfAbsent(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
... ... @@ -120,7 +121,7 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
120 121 for (EntityRelation relation : entityRelations) {
121 122 list.add(ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), relation));
122 123 }
123   - return Futures.transform(Futures.allAsList(list), result -> false);
  124 + return Futures.transform(Futures.allAsList(list), result -> false, MoreExecutors.directExecutor());
124 125 }
125 126 return Futures.immediateFuture(false);
126 127 }, ctx.getDbCallbackExecutor());
... ... @@ -161,7 +162,7 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
161 162 } else {
162 163 return Futures.immediateFuture(true);
163 164 }
164   - });
  165 + }, MoreExecutors.directExecutor());
165 166 }
166 167
167 168 private ListenableFuture<Boolean> processAsset(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.action;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.thingsboard.rule.engine.api.RuleNode;
22 23 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -66,17 +67,18 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
66 67
67 68 @Override
68 69 protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
69   - return Futures.transform(processSingle(ctx, msg, entityContainer), result -> new RelationContainer(msg, result));
  70 + return Futures.transform(processSingle(ctx, msg, entityContainer), result -> new RelationContainer(msg, result), MoreExecutors.directExecutor());
70 71 }
71 72
72 73 private ListenableFuture<RelationContainer> getRelationContainerListenableFuture(TbContext ctx, TbMsg msg) {
73 74 relationType = processPattern(msg, config.getRelationType());
74 75 if (config.isDeleteForSingleEntity()) {
75   - return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer));
  76 + return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer), MoreExecutors.directExecutor());
76 77 } else {
77   - return Futures.transform(processList(ctx, msg), result -> new RelationContainer(msg, result));
  78 + return Futures.transform(processList(ctx, msg), result -> new RelationContainer(msg, result), MoreExecutors.directExecutor());
78 79 }
79 80 }
  81 +
80 82 private ListenableFuture<Boolean> processList(TbContext ctx, TbMsg msg) {
81 83 return Futures.transformAsync(processListSearchDirection(ctx, msg), entityRelations -> {
82 84 if (entityRelations.isEmpty()) {
... ... @@ -93,9 +95,9 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
93 95 }
94 96 }
95 97 return Futures.immediateFuture(true);
96   - });
  98 + }, MoreExecutors.directExecutor());
97 99 }
98   - });
  100 + }, MoreExecutors.directExecutor());
99 101 }
100 102
101 103 private ListenableFuture<Boolean> processSingle(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
... ... @@ -106,7 +108,7 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
106 108 return processSingleDeleteRelation(ctx, sdId);
107 109 }
108 110 return Futures.immediateFuture(true);
109   - });
  111 + }, MoreExecutors.directExecutor());
110 112 }
111 113
112 114 private ListenableFuture<Boolean> processSingleDeleteRelation(TbContext ctx, SearchDirectionIds sdId) {
... ...
... ... @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
19 19 import com.google.common.util.concurrent.FutureCallback;
20 20 import com.google.common.util.concurrent.Futures;
21 21 import com.google.common.util.concurrent.ListenableFuture;
  22 +import com.google.common.util.concurrent.MoreExecutors;
22 23 import lombok.extern.slf4j.Slf4j;
23 24 import org.thingsboard.rule.engine.api.RuleNode;
24 25 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -27,17 +28,12 @@ import org.thingsboard.rule.engine.api.TbNodeConfiguration;
27 28 import org.thingsboard.rule.engine.api.TbNodeException;
28 29 import org.thingsboard.rule.engine.api.util.TbNodeUtils;
29 30 import org.thingsboard.server.common.data.alarm.Alarm;
30   -import org.thingsboard.server.common.data.alarm.AlarmId;
31 31 import org.thingsboard.server.common.data.alarm.AlarmStatus;
32 32 import org.thingsboard.server.common.data.plugin.ComponentType;
33 33 import org.thingsboard.server.common.msg.TbMsg;
34 34
35 35 import javax.annotation.Nullable;
36 36 import java.io.IOException;
37   -import java.util.UUID;
38   -
39   -import static org.thingsboard.rule.engine.api.TbRelationTypes.FAILURE;
40   -import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
41 37
42 38 @Slf4j
43 39 @RuleNode(
... ... @@ -91,7 +87,7 @@ public class TbCheckAlarmStatusNode implements TbNode {
91 87 public void onFailure(Throwable t) {
92 88 ctx.tellFailure(msg, t);
93 89 }
94   - });
  90 + }, MoreExecutors.directExecutor());
95 91 } catch (IOException e) {
96 92 log.error("Failed to parse alarm: [{}]", msg.getData());
97 93 throw new TbNodeException(e);
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.filter;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.thingsboard.rule.engine.api.RuleNode;
22 23 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -87,10 +88,10 @@ public class TbCheckRelationNode implements TbNode {
87 88 private ListenableFuture<Boolean> processList(TbContext ctx, TbMsg msg) {
88 89 if (EntitySearchDirection.FROM.name().equals(config.getDirection())) {
89 90 return Futures.transformAsync(ctx.getRelationService()
90   - .findByToAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), config.getRelationType(), RelationTypeGroup.COMMON), this::isEmptyList);
  91 + .findByToAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), config.getRelationType(), RelationTypeGroup.COMMON), this::isEmptyList, MoreExecutors.directExecutor());
91 92 } else {
92 93 return Futures.transformAsync(ctx.getRelationService()
93   - .findByFromAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), config.getRelationType(), RelationTypeGroup.COMMON), this::isEmptyList);
  94 + .findByFromAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), config.getRelationType(), RelationTypeGroup.COMMON), this::isEmptyList, MoreExecutors.directExecutor());
94 95 }
95 96 }
96 97
... ...
... ... @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
21 21 import com.fasterxml.jackson.databind.node.ObjectNode;
22 22 import com.google.common.util.concurrent.Futures;
23 23 import com.google.common.util.concurrent.ListenableFuture;
  24 +import com.google.common.util.concurrent.MoreExecutors;
24 25 import com.google.gson.JsonParseException;
25 26 import org.apache.commons.collections.CollectionUtils;
26 27 import org.apache.commons.lang3.BooleanUtils;
... ... @@ -122,7 +123,7 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
122 123 }
123 124 }
124 125 return null;
125   - });
  126 + }, MoreExecutors.directExecutor());
126 127 }
127 128
128 129 private ListenableFuture<Void> putLatestTelemetry(TbContext ctx, EntityId entityId, TbMsg msg, String scope, List<String> keys, ConcurrentHashMap<String, List<String>> failuresMap) {
... ... @@ -152,7 +153,7 @@ public abstract class TbAbstractGetAttributesNode<C extends TbGetAttributesNodeC
152 153 }
153 154 });
154 155 return null;
155   - });
  156 + }, MoreExecutors.directExecutor());
156 157 }
157 158
158 159 private void putValueWithTs(TbMsg msg, TsKvEntry r) {
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.metadata;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import com.google.gson.Gson;
21 22 import com.google.gson.JsonElement;
22 23 import com.google.gson.JsonObject;
... ... @@ -37,15 +38,16 @@ import org.thingsboard.server.common.msg.TbMsgMetaData;
37 38 import java.lang.reflect.Type;
38 39 import java.util.Map;
39 40
40   -import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
41 41 import static org.thingsboard.common.util.DonAsynchron.withCallback;
  42 +import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
42 43
43 44 @Slf4j
44 45 public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEntityDetailsNodeConfiguration> implements TbNode {
45 46
46 47 private static final Gson gson = new Gson();
47 48 private static final JsonParser jsonParser = new JsonParser();
48   - private static final Type TYPE = new TypeToken<Map<String, String>>() {}.getType();
  49 + private static final Type TYPE = new TypeToken<Map<String, String>>() {
  50 + }.getType();
49 51
50 52 protected C config;
51 53
... ... @@ -104,7 +106,7 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti
104 106 } else {
105 107 return Futures.immediateFuture(null);
106 108 }
107   - });
  109 + }, MoreExecutors.directExecutor());
108 110 }
109 111
110 112 private ListenableFuture<JsonElement> addContactProperties(JsonElement data, ListenableFuture<ContactBased> entityFuture, EntityDetails entityDetails, String prefix) {
... ... @@ -114,7 +116,7 @@ public abstract class TbAbstractGetEntityDetailsNode<C extends TbAbstractGetEnti
114 116 } else {
115 117 return Futures.immediateFuture(null);
116 118 }
117   - });
  119 + }, MoreExecutors.directExecutor());
118 120 }
119 121
120 122 private JsonElement setProperties(ContactBased entity, JsonElement data, EntityDetails entityDetails, String prefix) {
... ...
... ... @@ -17,12 +17,13 @@ package org.thingsboard.rule.engine.metadata;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21   -import org.thingsboard.rule.engine.api.util.TbNodeUtils;
22 22 import org.thingsboard.rule.engine.api.TbContext;
23 23 import org.thingsboard.rule.engine.api.TbNode;
24 24 import org.thingsboard.rule.engine.api.TbNodeConfiguration;
25 25 import org.thingsboard.rule.engine.api.TbNodeException;
  26 +import org.thingsboard.rule.engine.api.util.TbNodeUtils;
26 27 import org.thingsboard.server.common.data.id.EntityId;
27 28 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
28 29 import org.thingsboard.server.common.data.kv.KvEntry;
... ... @@ -60,7 +61,7 @@ public abstract class TbEntityGetAttrNode<T extends EntityId> implements TbNode
60 61 }
61 62
62 63 private void safeGetAttributes(TbContext ctx, TbMsg msg, T entityId) {
63   - if(entityId == null || entityId.isNullUid()) {
  64 + if (entityId == null || entityId.isNullUid()) {
64 65 ctx.tellNext(msg, FAILURE);
65 66 return;
66 67 }
... ... @@ -73,13 +74,13 @@ public abstract class TbEntityGetAttrNode<T extends EntityId> implements TbNode
73 74 private ListenableFuture<List<KvEntry>> getAttributesAsync(TbContext ctx, EntityId entityId) {
74 75 ListenableFuture<List<AttributeKvEntry>> latest = ctx.getAttributesService().find(ctx.getTenantId(), entityId, SERVER_SCOPE, config.getAttrMapping().keySet());
75 76 return Futures.transform(latest, l ->
76   - l.stream().map(i -> (KvEntry) i).collect(Collectors.toList()));
  77 + l.stream().map(i -> (KvEntry) i).collect(Collectors.toList()), MoreExecutors.directExecutor());
77 78 }
78 79
79 80 private ListenableFuture<List<KvEntry>> getLatestTelemetry(TbContext ctx, EntityId entityId) {
80 81 ListenableFuture<List<TsKvEntry>> latest = ctx.getTimeseriesService().findLatest(ctx.getTenantId(), entityId, config.getAttrMapping().keySet());
81 82 return Futures.transform(latest, l ->
82   - l.stream().map(i -> (KvEntry) i).collect(Collectors.toList()));
  83 + l.stream().map(i -> (KvEntry) i).collect(Collectors.toList()), MoreExecutors.directExecutor());
83 84 }
84 85
85 86
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.metadata;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.thingsboard.rule.engine.api.RuleNode;
22 23 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -63,7 +64,7 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG
63 64 } else {
64 65 return Futures.immediateFuture(null);
65 66 }
66   - });
  67 + }, MoreExecutors.directExecutor());
67 68 }
68 69
69 70 private ListenableFuture<Customer> getCustomer(TbContext ctx, TbMsg msg) {
... ... @@ -79,7 +80,7 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG
79 80 } else {
80 81 return Futures.immediateFuture(null);
81 82 }
82   - });
  83 + }, MoreExecutors.directExecutor());
83 84 case ASSET:
84 85 return Futures.transformAsync(ctx.getAssetService().findAssetByIdAsync(ctx.getTenantId(), new AssetId(msg.getOriginator().getId())), asset -> {
85 86 if (asset != null) {
... ... @@ -91,7 +92,7 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG
91 92 } else {
92 93 return Futures.immediateFuture(null);
93 94 }
94   - });
  95 + }, MoreExecutors.directExecutor());
95 96 case ENTITY_VIEW:
96 97 return Futures.transformAsync(ctx.getEntityViewService().findEntityViewByIdAsync(ctx.getTenantId(), new EntityViewId(msg.getOriginator().getId())), entityView -> {
97 98 if (entityView != null) {
... ... @@ -103,7 +104,7 @@ public class TbGetCustomerDetailsNode extends TbAbstractGetEntityDetailsNode<TbG
103 104 } else {
104 105 return Futures.immediateFuture(null);
105 106 }
106   - });
  107 + }, MoreExecutors.directExecutor());
107 108 default:
108 109 throw new RuntimeException("Entity with entityType '" + msg.getOriginator().getEntityType() + "' is not supported.");
109 110 }
... ...
... ... @@ -17,16 +17,21 @@ package org.thingsboard.rule.engine.metadata;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21   -import org.thingsboard.rule.engine.api.*;
  22 +import org.thingsboard.rule.engine.api.RuleNode;
  23 +import org.thingsboard.rule.engine.api.TbContext;
  24 +import org.thingsboard.rule.engine.api.TbNode;
  25 +import org.thingsboard.rule.engine.api.TbNodeConfiguration;
  26 +import org.thingsboard.rule.engine.api.TbNodeException;
22 27 import org.thingsboard.rule.engine.api.util.TbNodeUtils;
23 28 import org.thingsboard.rule.engine.util.EntitiesFieldsAsyncLoader;
24 29 import org.thingsboard.server.common.data.id.EntityId;
25 30 import org.thingsboard.server.common.data.plugin.ComponentType;
26 31 import org.thingsboard.server.common.msg.TbMsg;
27 32
28   -import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
29 33 import static org.thingsboard.common.util.DonAsynchron.withCallback;
  34 +import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS;
30 35
31 36 /**
32 37 * Created by ashvayka on 19.01.18.
... ... @@ -71,7 +76,7 @@ public class TbGetOriginatorFieldsNode implements TbNode {
71 76 }
72 77 });
73 78 return null;
74   - }
  79 + }, MoreExecutors.directExecutor()
75 80 );
76 81 }
77 82 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.metadata;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import lombok.extern.slf4j.Slf4j;
21 22 import org.thingsboard.rule.engine.api.RuleNode;
22 23 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -59,6 +60,6 @@ public class TbGetTenantDetailsNode extends TbAbstractGetEntityDetailsNode<TbGet
59 60 } else {
60 61 return Futures.immediateFuture(null);
61 62 }
62   - });
  63 + }, MoreExecutors.directExecutor());
63 64 }
64 65 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.util;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import org.thingsboard.rule.engine.api.TbContext;
21 22 import org.thingsboard.rule.engine.api.TbNodeException;
22 23 import org.thingsboard.server.common.data.alarm.Alarm;
... ... @@ -39,6 +40,6 @@ public class EntitiesAlarmOriginatorIdAsyncLoader {
39 40 return Futures.transformAsync(future, in -> {
40 41 return in != null ? Futures.immediateFuture(in.getOriginator())
41 42 : Futures.immediateFuture(null);
42   - });
  43 + }, MoreExecutors.directExecutor());
43 44 }
44 45 }
... ...
... ... @@ -15,13 +15,17 @@
15 15 */
16 16 package org.thingsboard.rule.engine.util;
17 17
18   -import com.google.common.util.concurrent.AsyncFunction;
19 18 import com.google.common.util.concurrent.Futures;
20 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
21 21 import org.thingsboard.rule.engine.api.TbContext;
22 22 import org.thingsboard.rule.engine.api.TbNodeException;
23 23 import org.thingsboard.server.common.data.HasCustomerId;
24   -import org.thingsboard.server.common.data.id.*;
  24 +import org.thingsboard.server.common.data.id.AssetId;
  25 +import org.thingsboard.server.common.data.id.CustomerId;
  26 +import org.thingsboard.server.common.data.id.DeviceId;
  27 +import org.thingsboard.server.common.data.id.EntityId;
  28 +import org.thingsboard.server.common.data.id.UserId;
25 29
26 30 public class EntitiesCustomerIdAsyncLoader {
27 31
... ... @@ -44,6 +48,6 @@ public class EntitiesCustomerIdAsyncLoader {
44 48
45 49 private static <T extends HasCustomerId> ListenableFuture<CustomerId> getCustomerAsync(ListenableFuture<T> future) {
46 50 return Futures.transformAsync(future, in -> in != null ? Futures.immediateFuture(in.getCustomerId())
47   - : Futures.immediateFuture(null));
  51 + : Futures.immediateFuture(null), MoreExecutors.directExecutor());
48 52 }
49 53 }
... ...
... ... @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.util;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
20 21 import org.thingsboard.rule.engine.api.TbContext;
21 22 import org.thingsboard.rule.engine.api.TbNodeException;
22 23 import org.thingsboard.server.common.data.BaseData;
... ... @@ -66,6 +67,6 @@ public class EntitiesFieldsAsyncLoader {
66 67 ListenableFuture<T> future, Function<T, EntityFieldsData> converter) {
67 68 return Futures.transformAsync(future, in -> in != null ?
68 69 Futures.immediateFuture(converter.apply(in))
69   - : Futures.immediateFailedFuture(new RuntimeException("Entity not found!")));
  70 + : Futures.immediateFailedFuture(new RuntimeException("Entity not found!")), MoreExecutors.directExecutor());
70 71 }
71 72 }
... ...
... ... @@ -15,9 +15,9 @@
15 15 */
16 16 package org.thingsboard.rule.engine.util;
17 17
18   -import com.google.common.util.concurrent.AsyncFunction;
19 18 import com.google.common.util.concurrent.Futures;
20 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
21 21 import org.apache.commons.collections.CollectionUtils;
22 22 import org.thingsboard.rule.engine.api.TbContext;
23 23 import org.thingsboard.rule.engine.data.DeviceRelationsQuery;
... ... @@ -40,7 +40,7 @@ public class EntitiesRelatedDeviceIdAsyncLoader {
40 40 ListenableFuture<List<Device>> asyncDevices = deviceService.findDevicesByQuery(ctx.getTenantId(), query);
41 41
42 42 return Futures.transformAsync(asyncDevices, d -> CollectionUtils.isNotEmpty(d) ? Futures.immediateFuture(d.get(0).getId())
43   - : Futures.immediateFuture(null));
  43 + : Futures.immediateFuture(null), MoreExecutors.directExecutor());
44 44 }
45 45
46 46 private static DeviceSearchQuery buildQuery(EntityId originator, DeviceRelationsQuery deviceRelationsQuery) {
... ...
... ... @@ -15,9 +15,9 @@
15 15 */
16 16 package org.thingsboard.rule.engine.util;
17 17
18   -import com.google.common.util.concurrent.AsyncFunction;
19 18 import com.google.common.util.concurrent.Futures;
20 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
21 21 import org.apache.commons.collections.CollectionUtils;
22 22 import org.thingsboard.rule.engine.api.TbContext;
23 23 import org.thingsboard.rule.engine.data.RelationsQuery;
... ... @@ -39,10 +39,10 @@ public class EntitiesRelatedEntityIdAsyncLoader {
39 39 ListenableFuture<List<EntityRelation>> asyncRelation = relationService.findByQuery(ctx.getTenantId(), query);
40 40 if (relationsQuery.getDirection() == EntitySearchDirection.FROM) {
41 41 return Futures.transformAsync(asyncRelation, r -> CollectionUtils.isNotEmpty(r) ? Futures.immediateFuture(r.get(0).getTo())
42   - : Futures.immediateFuture(null));
  42 + : Futures.immediateFuture(null), MoreExecutors.directExecutor());
43 43 } else if (relationsQuery.getDirection() == EntitySearchDirection.TO) {
44 44 return Futures.transformAsync(asyncRelation, r -> CollectionUtils.isNotEmpty(r) ? Futures.immediateFuture(r.get(0).getFrom())
45   - : Futures.immediateFuture(null));
  45 + : Futures.immediateFuture(null), MoreExecutors.directExecutor());
46 46 }
47 47 return Futures.immediateFailedFuture(new IllegalStateException("Unknown direction"));
48 48 }
... ...
... ... @@ -15,14 +15,20 @@
15 15 */
16 16 package org.thingsboard.rule.engine.util;
17 17
18   -import com.google.common.util.concurrent.AsyncFunction;
19 18 import com.google.common.util.concurrent.Futures;
20 19 import com.google.common.util.concurrent.ListenableFuture;
  20 +import com.google.common.util.concurrent.MoreExecutors;
21 21 import org.thingsboard.rule.engine.api.TbContext;
22 22 import org.thingsboard.rule.engine.api.TbNodeException;
23 23 import org.thingsboard.server.common.data.HasTenantId;
24 24 import org.thingsboard.server.common.data.alarm.AlarmId;
25   -import org.thingsboard.server.common.data.id.*;
  25 +import org.thingsboard.server.common.data.id.AssetId;
  26 +import org.thingsboard.server.common.data.id.CustomerId;
  27 +import org.thingsboard.server.common.data.id.DeviceId;
  28 +import org.thingsboard.server.common.data.id.EntityId;
  29 +import org.thingsboard.server.common.data.id.RuleChainId;
  30 +import org.thingsboard.server.common.data.id.TenantId;
  31 +import org.thingsboard.server.common.data.id.UserId;
26 32
27 33 public class EntitiesTenantIdAsyncLoader {
28 34
... ... @@ -51,6 +57,7 @@ public class EntitiesTenantIdAsyncLoader {
51 57 private static <T extends HasTenantId> ListenableFuture<TenantId> getTenantAsync(ListenableFuture<T> future) {
52 58 return Futures.transformAsync(future, in -> {
53 59 return in != null ? Futures.immediateFuture(in.getTenantId())
54   - : Futures.immediateFuture(null);});
  60 + : Futures.immediateFuture(null);
  61 + }, MoreExecutors.directExecutor());
55 62 }
56 63 }
... ...