Showing
1 changed file
with
23 additions
and
5 deletions
... | ... | @@ -50,6 +50,10 @@ import org.thingsboard.server.extensions.api.exception.ToErrorResponseEntity; |
50 | 50 | import org.thingsboard.server.service.security.model.SecurityUser; |
51 | 51 | |
52 | 52 | import javax.annotation.Nullable; |
53 | +import javax.annotation.PostConstruct; | |
54 | +import javax.annotation.PreDestroy; | |
55 | +import java.util.concurrent.ExecutorService; | |
56 | +import java.util.concurrent.Executors; | |
53 | 57 | import java.util.function.BiConsumer; |
54 | 58 | |
55 | 59 | /** |
... | ... | @@ -83,6 +87,20 @@ public class AccessValidator { |
83 | 87 | @Autowired |
84 | 88 | protected RuleChainService ruleChainService; |
85 | 89 | |
90 | + private ExecutorService executor; | |
91 | + | |
92 | + @PostConstruct | |
93 | + public void initExecutor() { | |
94 | + executor = Executors.newSingleThreadExecutor(); | |
95 | + } | |
96 | + | |
97 | + @PreDestroy | |
98 | + public void shutdownExecutor() { | |
99 | + if (executor != null) { | |
100 | + executor.shutdownNow(); | |
101 | + } | |
102 | + } | |
103 | + | |
86 | 104 | public DeferredResult<ResponseEntity> validateEntityAndCallback(SecurityUser currentUser, String entityType, String entityIdStr, |
87 | 105 | BiConsumer<DeferredResult<ResponseEntity>, EntityId> onSuccess) throws ThingsboardException { |
88 | 106 | return validateEntityAndCallback(currentUser, entityType, entityIdStr, onSuccess, (result, t) -> handleError(t, result, HttpStatus.INTERNAL_SERVER_ERROR)); |
... | ... | @@ -162,7 +180,7 @@ public class AccessValidator { |
162 | 180 | return ValidationResult.ok(); |
163 | 181 | } |
164 | 182 | } |
165 | - })); | |
183 | + }), executor); | |
166 | 184 | } |
167 | 185 | } |
168 | 186 | |
... | ... | @@ -183,7 +201,7 @@ public class AccessValidator { |
183 | 201 | return ValidationResult.ok(); |
184 | 202 | } |
185 | 203 | } |
186 | - })); | |
204 | + }), executor); | |
187 | 205 | } |
188 | 206 | } |
189 | 207 | |
... | ... | @@ -205,7 +223,7 @@ public class AccessValidator { |
205 | 223 | return ValidationResult.ok(); |
206 | 224 | } |
207 | 225 | } |
208 | - })); | |
226 | + }), executor); | |
209 | 227 | } |
210 | 228 | } |
211 | 229 | |
... | ... | @@ -226,7 +244,7 @@ public class AccessValidator { |
226 | 244 | return ValidationResult.ok(); |
227 | 245 | } |
228 | 246 | } |
229 | - })); | |
247 | + }), executor); | |
230 | 248 | } |
231 | 249 | } |
232 | 250 | |
... | ... | @@ -245,7 +263,7 @@ public class AccessValidator { |
245 | 263 | } else { |
246 | 264 | return ValidationResult.ok(); |
247 | 265 | } |
248 | - })); | |
266 | + }), executor); | |
249 | 267 | } |
250 | 268 | } |
251 | 269 | ... | ... |