Commit 9029a366a5dc17d8b648837fbc14aa85f7971407
Merge branch 'master' of github.com:thingsboard/thingsboard
Showing
2 changed files
with
14 additions
and
2 deletions
... | ... | @@ -82,7 +82,8 @@ public abstract class ComponentMsgProcessor<T extends EntityId> extends Abstract |
82 | 82 | |
83 | 83 | protected void checkActive() { |
84 | 84 | if (state != ComponentLifecycleState.ACTIVE) { |
85 | - throw new IllegalStateException("Rule chain is not active!"); | |
85 | + logger.warning("Rule chain is not active. Current state [{}] for processor [{}] tenant [{}]", state, tenantId, entityId); | |
86 | + throw new IllegalStateException("Rule chain is not active! " + entityId + " - " + tenantId); | |
86 | 87 | } |
87 | 88 | } |
88 | 89 | ... | ... |
... | ... | @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.cache; |
18 | 18 | import com.github.benmanes.caffeine.cache.Caffeine; |
19 | 19 | import com.github.benmanes.caffeine.cache.RemovalCause; |
20 | 20 | import com.github.benmanes.caffeine.cache.Ticker; |
21 | +import com.github.benmanes.caffeine.cache.Weigher; | |
21 | 22 | import lombok.Data; |
22 | 23 | import lombok.extern.slf4j.Slf4j; |
23 | 24 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
... | ... | @@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean; |
31 | 32 | import org.springframework.context.annotation.Configuration; |
32 | 33 | |
33 | 34 | import java.util.Arrays; |
35 | +import java.util.Collection; | |
34 | 36 | import java.util.List; |
35 | 37 | import java.util.Map; |
36 | 38 | import java.util.concurrent.TimeUnit; |
... | ... | @@ -64,8 +66,9 @@ public class CaffeineCacheConfiguration { |
64 | 66 | private CaffeineCache buildCache(String name, CacheSpecs cacheSpec) { |
65 | 67 | final Caffeine<Object, Object> caffeineBuilder |
66 | 68 | = Caffeine.newBuilder() |
69 | + .weigher(collectionSafeWeigher()) | |
70 | + .maximumWeight(cacheSpec.getMaxSize()) | |
67 | 71 | .expireAfterWrite(cacheSpec.getTimeToLiveInMinutes(), TimeUnit.MINUTES) |
68 | - .maximumSize(cacheSpec.getMaxSize()) | |
69 | 72 | .ticker(ticker()); |
70 | 73 | return new CaffeineCache(name, caffeineBuilder.build()); |
71 | 74 | } |
... | ... | @@ -80,4 +83,12 @@ public class CaffeineCacheConfiguration { |
80 | 83 | return new PreviousDeviceCredentialsIdKeyGenerator(); |
81 | 84 | } |
82 | 85 | |
86 | + private Weigher<? super Object, ? super Object> collectionSafeWeigher() { | |
87 | + return (Weigher<Object, Object>) (key, value) -> { | |
88 | + if(value instanceof Collection) { | |
89 | + return ((Collection) value).size(); | |
90 | + } | |
91 | + return 1; | |
92 | + }; | |
93 | + } | |
83 | 94 | } | ... | ... |