Showing
24 changed files
with
84 additions
and
33 deletions
... | ... | @@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; |
24 | 24 | import io.netty.channel.EventLoopGroup; |
25 | 25 | import org.springframework.data.redis.core.RedisTemplate; |
26 | 26 | import org.springframework.util.StringUtils; |
27 | -import org.thingsboard.rule.engine.api.ListeningExecutor; | |
27 | +import org.thingsboard.common.util.ListeningExecutor; | |
28 | 28 | import org.thingsboard.rule.engine.api.MailService; |
29 | 29 | import org.thingsboard.rule.engine.api.RuleChainTransactionService; |
30 | 30 | import org.thingsboard.rule.engine.api.RuleEngineDeviceRpcRequest; | ... | ... |
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.executors; |
17 | 17 | |
18 | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | 19 | import org.springframework.stereotype.Component; |
20 | +import org.thingsboard.common.util.AbstractListeningExecutor; | |
20 | 21 | |
21 | 22 | @Component |
22 | 23 | public class ClusterRpcCallbackExecutorService extends AbstractListeningExecutor { | ... | ... |
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.executors; |
17 | 17 | |
18 | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | 19 | import org.springframework.stereotype.Component; |
20 | +import org.thingsboard.common.util.AbstractListeningExecutor; | |
20 | 21 | |
21 | 22 | @Component |
22 | 23 | public class DbCallbackExecutorService extends AbstractListeningExecutor { | ... | ... |
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.service.executors; |
17 | 17 | |
18 | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | 19 | import org.springframework.stereotype.Component; |
20 | +import org.thingsboard.common.util.AbstractListeningExecutor; | |
20 | 21 | |
21 | 22 | @Component |
22 | 23 | public class ExternalCallExecutorService extends AbstractListeningExecutor { | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.service.mail; |
17 | 17 | |
18 | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | 19 | import org.springframework.stereotype.Component; |
20 | -import org.thingsboard.server.service.executors.AbstractListeningExecutor; | |
20 | +import org.thingsboard.common.util.AbstractListeningExecutor; | |
21 | 21 | |
22 | 22 | @Component |
23 | 23 | public class MailExecutorService extends AbstractListeningExecutor { | ... | ... |
... | ... | @@ -17,7 +17,7 @@ package org.thingsboard.server.service.script; |
17 | 17 | |
18 | 18 | import org.springframework.beans.factory.annotation.Value; |
19 | 19 | import org.springframework.stereotype.Component; |
20 | -import org.thingsboard.server.service.executors.AbstractListeningExecutor; | |
20 | +import org.thingsboard.common.util.AbstractListeningExecutor; | |
21 | 21 | |
22 | 22 | @Component |
23 | 23 | public class JsExecutorService extends AbstractListeningExecutor { | ... | ... |
... | ... | @@ -351,6 +351,7 @@ spring: |
351 | 351 | repositories: |
352 | 352 | enabled: "true" |
353 | 353 | jpa: |
354 | + open-in-view: "false" | |
354 | 355 | hibernate: |
355 | 356 | ddl-auto: "none" |
356 | 357 | database-platform: "${SPRING_JPA_DATABASE_PLATFORM:org.hibernate.dialect.PostgreSQLDialect}" |
... | ... | @@ -536,4 +537,4 @@ swagger: |
536 | 537 | license: |
537 | 538 | title: "${SWAGGER_LICENSE_TITLE:Apache License Version 2.0}" |
538 | 539 | url: "${SWAGGER_LICENSE_URL:https://github.com/thingsboard/thingsboard/blob/master/LICENSE}" |
539 | - version: "${SWAGGER_VERSION:2.0}" | |
\ No newline at end of file | ||
540 | + version: "${SWAGGER_VERSION:2.0}" | ... | ... |
common/util/src/main/java/org/thingsboard/common/util/AbstractListeningExecutor.java
renamed from
application/src/main/java/org/thingsboard/server/service/executors/AbstractListeningExecutor.java
... | ... | @@ -13,12 +13,12 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.server.service.executors; | |
16 | +package org.thingsboard.common.util; | |
17 | 17 | |
18 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | 19 | import com.google.common.util.concurrent.ListeningExecutorService; |
20 | 20 | import com.google.common.util.concurrent.MoreExecutors; |
21 | -import org.thingsboard.rule.engine.api.ListeningExecutor; | |
21 | +import org.thingsboard.common.util.ListeningExecutor; | |
22 | 22 | |
23 | 23 | import javax.annotation.PostConstruct; |
24 | 24 | import javax.annotation.PreDestroy; | ... | ... |
common/util/src/main/java/org/thingsboard/common/util/ListeningExecutor.java
renamed from
rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/ListeningExecutor.java
... | ... | @@ -13,7 +13,7 @@ |
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | -package org.thingsboard.rule.engine.api; | |
16 | +package org.thingsboard.common.util; | |
17 | 17 | |
18 | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | 19 | |
... | ... | @@ -24,4 +24,8 @@ public interface ListeningExecutor extends Executor { |
24 | 24 | |
25 | 25 | <T> ListenableFuture<T> executeAsync(Callable<T> task); |
26 | 26 | |
27 | + default <T> ListenableFuture<T> submit(Callable<T> task) { | |
28 | + return executeAsync(task); | |
29 | + } | |
30 | + | |
27 | 31 | } | ... | ... |
... | ... | @@ -48,6 +48,10 @@ |
48 | 48 | <artifactId>dao-api</artifactId> |
49 | 49 | </dependency> |
50 | 50 | <dependency> |
51 | + <groupId>org.thingsboard.common</groupId> | |
52 | + <artifactId>util</artifactId> | |
53 | + </dependency> | |
54 | + <dependency> | |
51 | 55 | <groupId>org.slf4j</groupId> |
52 | 56 | <artifactId>slf4j-api</artifactId> |
53 | 57 | </dependency> | ... | ... |
... | ... | @@ -17,16 +17,14 @@ package org.thingsboard.server.dao.sql; |
17 | 17 | |
18 | 18 | import com.google.common.util.concurrent.ListeningExecutorService; |
19 | 19 | import com.google.common.util.concurrent.MoreExecutors; |
20 | +import org.springframework.beans.factory.annotation.Autowired; | |
20 | 21 | |
21 | 22 | import javax.annotation.PreDestroy; |
22 | 23 | import java.util.concurrent.Executors; |
23 | 24 | |
24 | 25 | public abstract class JpaAbstractDaoListeningExecutorService { |
25 | 26 | |
26 | - protected ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); | |
27 | + @Autowired | |
28 | + protected JpaExecutorService service; | |
27 | 29 | |
28 | - @PreDestroy | |
29 | - void onDestroy() { | |
30 | - service.shutdown(); | |
31 | - } | |
32 | 30 | } | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2019 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.dao.sql; | |
17 | + | |
18 | +import org.springframework.beans.factory.annotation.Value; | |
19 | +import org.springframework.stereotype.Component; | |
20 | +import org.thingsboard.common.util.AbstractListeningExecutor; | |
21 | +import org.thingsboard.server.dao.util.SqlDao; | |
22 | + | |
23 | +@Component | |
24 | +@SqlDao | |
25 | +public class JpaExecutorService extends AbstractListeningExecutor { | |
26 | + | |
27 | + @Value("${spring.datasource.hikari.maximumPoolSize}") | |
28 | + private int poolSize; | |
29 | + | |
30 | + @Override | |
31 | + protected int getThreadPollSize() { | |
32 | + return poolSize; | |
33 | + } | |
34 | + | |
35 | +} | ... | ... |
... | ... | @@ -53,8 +53,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; |
53 | 53 | @SqlDao |
54 | 54 | public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> implements AuditLogDao { |
55 | 55 | |
56 | - private ListeningExecutorService insertService = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()); | |
57 | - | |
58 | 56 | @Autowired |
59 | 57 | private AuditLogRepository auditLogRepository; |
60 | 58 | |
... | ... | @@ -68,14 +66,9 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp |
68 | 66 | return auditLogRepository; |
69 | 67 | } |
70 | 68 | |
71 | - @PreDestroy | |
72 | - void onDestroy() { | |
73 | - insertService.shutdown(); | |
74 | - } | |
75 | - | |
76 | 69 | @Override |
77 | 70 | public ListenableFuture<Void> saveByTenantId(AuditLog auditLog) { |
78 | - return insertService.submit(() -> { | |
71 | + return service.submit(() -> { | |
79 | 72 | save(auditLog.getTenantId(), auditLog); |
80 | 73 | return null; |
81 | 74 | }); |
... | ... | @@ -83,22 +76,22 @@ public class JpaAuditLogDao extends JpaAbstractDao<AuditLogEntity, AuditLog> imp |
83 | 76 | |
84 | 77 | @Override |
85 | 78 | public ListenableFuture<Void> saveByTenantIdAndEntityId(AuditLog auditLog) { |
86 | - return insertService.submit(() -> null); | |
79 | + return service.submit(() -> null); | |
87 | 80 | } |
88 | 81 | |
89 | 82 | @Override |
90 | 83 | public ListenableFuture<Void> saveByTenantIdAndCustomerId(AuditLog auditLog) { |
91 | - return insertService.submit(() -> null); | |
84 | + return service.submit(() -> null); | |
92 | 85 | } |
93 | 86 | |
94 | 87 | @Override |
95 | 88 | public ListenableFuture<Void> saveByTenantIdAndUserId(AuditLog auditLog) { |
96 | - return insertService.submit(() -> null); | |
89 | + return service.submit(() -> null); | |
97 | 90 | } |
98 | 91 | |
99 | 92 | @Override |
100 | 93 | public ListenableFuture<Void> savePartitionsByTenantId(AuditLog auditLog) { |
101 | - return insertService.submit(() -> null); | |
94 | + return service.submit(() -> null); | |
102 | 95 | } |
103 | 96 | |
104 | 97 | @Override | ... | ... |
... | ... | @@ -70,7 +70,7 @@ public abstract class AbstractSqlTimeseriesDao extends JpaAbstractDaoListeningEx |
70 | 70 | if (poolSize <= 0) { |
71 | 71 | poolSize = maximumPoolSize * 4; |
72 | 72 | } |
73 | - insertService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(poolSize)); | |
73 | + insertService = MoreExecutors.listeningDecorator(Executors.newWorkStealingPool(poolSize)); | |
74 | 74 | break; |
75 | 75 | } |
76 | 76 | } |
... | ... | @@ -127,4 +127,4 @@ public abstract class AbstractSqlTimeseriesDao extends JpaAbstractDaoListeningEx |
127 | 127 | Aggregation.NONE, DESC_ORDER); |
128 | 128 | return findAllAsync(tenantId, entityId, findNewLatestQuery); |
129 | 129 | } |
130 | -} | |
\ No newline at end of file | ||
130 | +} | ... | ... |
... | ... | @@ -49,6 +49,11 @@ |
49 | 49 | <scope>provided</scope> |
50 | 50 | </dependency> |
51 | 51 | <dependency> |
52 | + <groupId>org.thingsboard.common</groupId> | |
53 | + <artifactId>util</artifactId> | |
54 | + <scope>provided</scope> | |
55 | + </dependency> | |
56 | + <dependency> | |
52 | 57 | <groupId>io.netty</groupId> |
53 | 58 | <artifactId>netty-all</artifactId> |
54 | 59 | <scope>provided</scope> |
... | ... | @@ -89,4 +94,4 @@ |
89 | 94 | <scope>provided</scope> |
90 | 95 | </dependency> |
91 | 96 | </dependencies> |
92 | -</project> | |
\ No newline at end of file | ||
97 | +</project> | ... | ... |
... | ... | @@ -18,6 +18,7 @@ package org.thingsboard.rule.engine.api; |
18 | 18 | import com.datastax.driver.core.ResultSetFuture; |
19 | 19 | import io.netty.channel.EventLoopGroup; |
20 | 20 | import org.springframework.data.redis.core.RedisTemplate; |
21 | +import org.thingsboard.common.util.ListeningExecutor; | |
21 | 22 | import org.thingsboard.server.common.data.Customer; |
22 | 23 | import org.thingsboard.server.common.data.Device; |
23 | 24 | import org.thingsboard.server.common.data.alarm.Alarm; | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | package org.thingsboard.rule.engine.action; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | +import org.thingsboard.common.util.ListeningExecutor; | |
19 | 20 | import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
20 | 21 | import org.thingsboard.rule.engine.api.*; |
21 | 22 | import org.thingsboard.server.common.data.plugin.ComponentType; | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | package org.thingsboard.rule.engine.filter; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | +import org.thingsboard.common.util.ListeningExecutor; | |
19 | 20 | import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
20 | 21 | import org.thingsboard.rule.engine.api.*; |
21 | 22 | import org.thingsboard.server.common.data.plugin.ComponentType; | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | package org.thingsboard.rule.engine.filter; |
17 | 17 | |
18 | 18 | import lombok.extern.slf4j.Slf4j; |
19 | +import org.thingsboard.common.util.ListeningExecutor; | |
19 | 20 | import org.thingsboard.rule.engine.api.util.TbNodeUtils; |
20 | 21 | import org.thingsboard.rule.engine.api.*; |
21 | 22 | import org.thingsboard.server.common.data.plugin.ComponentType; | ... | ... |
... | ... | @@ -28,6 +28,7 @@ import org.mockito.ArgumentCaptor; |
28 | 28 | import org.mockito.Mock; |
29 | 29 | import org.mockito.runners.MockitoJUnitRunner; |
30 | 30 | import org.mockito.stubbing.Answer; |
31 | +import org.thingsboard.common.util.ListeningExecutor; | |
31 | 32 | import org.thingsboard.rule.engine.api.*; |
32 | 33 | import org.thingsboard.server.common.data.alarm.Alarm; |
33 | 34 | import org.thingsboard.server.common.data.id.DeviceId; |
... | ... | @@ -376,4 +377,4 @@ public class TbAlarmNodeTest { |
376 | 377 | assertEquals(message, value.getMessage()); |
377 | 378 | } |
378 | 379 | |
379 | -} | |
\ No newline at end of file | ||
380 | +} | ... | ... |
... | ... | @@ -26,6 +26,7 @@ import org.mockito.Matchers; |
26 | 26 | import org.mockito.Mock; |
27 | 27 | import org.mockito.runners.MockitoJUnitRunner; |
28 | 28 | import org.mockito.stubbing.Answer; |
29 | +import org.thingsboard.common.util.ListeningExecutor; | |
29 | 30 | import org.thingsboard.rule.engine.api.*; |
30 | 31 | import org.thingsboard.server.common.data.id.RuleChainId; |
31 | 32 | import org.thingsboard.server.common.data.id.RuleNodeId; |
... | ... | @@ -123,4 +124,4 @@ public class TbJsFilterNodeTest { |
123 | 124 | assertEquals(expectedClass, value.getClass()); |
124 | 125 | assertEquals(message, value.getMessage()); |
125 | 126 | } |
126 | -} | |
\ No newline at end of file | ||
127 | +} | ... | ... |
... | ... | @@ -27,6 +27,7 @@ import org.mockito.Matchers; |
27 | 27 | import org.mockito.Mock; |
28 | 28 | import org.mockito.runners.MockitoJUnitRunner; |
29 | 29 | import org.mockito.stubbing.Answer; |
30 | +import org.thingsboard.common.util.ListeningExecutor; | |
30 | 31 | import org.thingsboard.rule.engine.api.*; |
31 | 32 | import org.thingsboard.server.common.data.id.RuleChainId; |
32 | 33 | import org.thingsboard.server.common.data.id.RuleNodeId; |
... | ... | @@ -105,4 +106,4 @@ public class TbJsSwitchNodeTest { |
105 | 106 | assertEquals(expectedClass, value.getClass()); |
106 | 107 | assertEquals(message, value.getMessage()); |
107 | 108 | } |
108 | -} | |
\ No newline at end of file | ||
109 | +} | ... | ... |
... | ... | @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; |
25 | 25 | import org.mockito.ArgumentCaptor; |
26 | 26 | import org.mockito.Mock; |
27 | 27 | import org.mockito.runners.MockitoJUnitRunner; |
28 | -import org.thingsboard.rule.engine.api.ListeningExecutor; | |
28 | +import org.thingsboard.common.util.ListeningExecutor; | |
29 | 29 | import org.thingsboard.rule.engine.api.TbContext; |
30 | 30 | import org.thingsboard.rule.engine.api.TbNodeConfiguration; |
31 | 31 | import org.thingsboard.rule.engine.api.TbNodeException; |
... | ... | @@ -166,4 +166,4 @@ public class TbChangeOriginatorNodeTest { |
166 | 166 | node = new TbChangeOriginatorNode(); |
167 | 167 | node.init(null, nodeConfiguration); |
168 | 168 | } |
169 | -} | |
\ No newline at end of file | ||
169 | +} | ... | ... |
... | ... | @@ -26,6 +26,7 @@ import org.mockito.Matchers; |
26 | 26 | import org.mockito.Mock; |
27 | 27 | import org.mockito.runners.MockitoJUnitRunner; |
28 | 28 | import org.mockito.stubbing.Answer; |
29 | +import org.thingsboard.common.util.ListeningExecutor; | |
29 | 30 | import org.thingsboard.rule.engine.api.*; |
30 | 31 | import org.thingsboard.server.common.data.id.RuleChainId; |
31 | 32 | import org.thingsboard.server.common.data.id.RuleNodeId; |
... | ... | @@ -123,4 +124,4 @@ public class TbTransformMsgNodeTest { |
123 | 124 | assertEquals(expectedClass, value.getClass()); |
124 | 125 | assertEquals(message, value.getMessage()); |
125 | 126 | } |
126 | -} | |
\ No newline at end of file | ||
127 | +} | ... | ... |