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