Commit 9029a366a5dc17d8b648837fbc14aa85f7971407

Authored by Igor Kulikov
2 parents 591bc88c 840c0428

Merge branch 'master' of github.com:thingsboard/thingsboard

@@ -82,7 +82,8 @@ public abstract class ComponentMsgProcessor<T extends EntityId> extends Abstract @@ -82,7 +82,8 @@ public abstract class ComponentMsgProcessor<T extends EntityId> extends Abstract
82 82
83 protected void checkActive() { 83 protected void checkActive() {
84 if (state != ComponentLifecycleState.ACTIVE) { 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,6 +18,7 @@ package org.thingsboard.server.dao.cache;
18 import com.github.benmanes.caffeine.cache.Caffeine; 18 import com.github.benmanes.caffeine.cache.Caffeine;
19 import com.github.benmanes.caffeine.cache.RemovalCause; 19 import com.github.benmanes.caffeine.cache.RemovalCause;
20 import com.github.benmanes.caffeine.cache.Ticker; 20 import com.github.benmanes.caffeine.cache.Ticker;
  21 +import com.github.benmanes.caffeine.cache.Weigher;
21 import lombok.Data; 22 import lombok.Data;
22 import lombok.extern.slf4j.Slf4j; 23 import lombok.extern.slf4j.Slf4j;
23 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 24 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean; @@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration; 32 import org.springframework.context.annotation.Configuration;
32 33
33 import java.util.Arrays; 34 import java.util.Arrays;
  35 +import java.util.Collection;
34 import java.util.List; 36 import java.util.List;
35 import java.util.Map; 37 import java.util.Map;
36 import java.util.concurrent.TimeUnit; 38 import java.util.concurrent.TimeUnit;
@@ -64,8 +66,9 @@ public class CaffeineCacheConfiguration { @@ -64,8 +66,9 @@ public class CaffeineCacheConfiguration {
64 private CaffeineCache buildCache(String name, CacheSpecs cacheSpec) { 66 private CaffeineCache buildCache(String name, CacheSpecs cacheSpec) {
65 final Caffeine<Object, Object> caffeineBuilder 67 final Caffeine<Object, Object> caffeineBuilder
66 = Caffeine.newBuilder() 68 = Caffeine.newBuilder()
  69 + .weigher(collectionSafeWeigher())
  70 + .maximumWeight(cacheSpec.getMaxSize())
67 .expireAfterWrite(cacheSpec.getTimeToLiveInMinutes(), TimeUnit.MINUTES) 71 .expireAfterWrite(cacheSpec.getTimeToLiveInMinutes(), TimeUnit.MINUTES)
68 - .maximumSize(cacheSpec.getMaxSize())  
69 .ticker(ticker()); 72 .ticker(ticker());
70 return new CaffeineCache(name, caffeineBuilder.build()); 73 return new CaffeineCache(name, caffeineBuilder.build());
71 } 74 }
@@ -80,4 +83,12 @@ public class CaffeineCacheConfiguration { @@ -80,4 +83,12 @@ public class CaffeineCacheConfiguration {
80 return new PreviousDeviceCredentialsIdKeyGenerator(); 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 }