Merge branch 'master' of github.com:thingsboard/thingsboard
This commit is contained in:
		
						commit
						9029a366a5
					
				@ -82,7 +82,8 @@ public abstract class ComponentMsgProcessor<T extends EntityId> extends Abstract
 | 
			
		||||
 | 
			
		||||
    protected void checkActive() {
 | 
			
		||||
        if (state != ComponentLifecycleState.ACTIVE) {
 | 
			
		||||
            throw new IllegalStateException("Rule chain is not active!");
 | 
			
		||||
            logger.warning("Rule chain is not active. Current state [{}] for processor [{}] tenant [{}]", state, tenantId, entityId);
 | 
			
		||||
            throw new IllegalStateException("Rule chain is not active! " + entityId + " - " + tenantId);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@ package org.thingsboard.server.dao.cache;
 | 
			
		||||
import com.github.benmanes.caffeine.cache.Caffeine;
 | 
			
		||||
import com.github.benmanes.caffeine.cache.RemovalCause;
 | 
			
		||||
import com.github.benmanes.caffeine.cache.Ticker;
 | 
			
		||||
import com.github.benmanes.caffeine.cache.Weigher;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 | 
			
		||||
@ -31,6 +32,7 @@ import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
@ -64,8 +66,9 @@ public class CaffeineCacheConfiguration {
 | 
			
		||||
    private CaffeineCache buildCache(String name, CacheSpecs cacheSpec) {
 | 
			
		||||
        final Caffeine<Object, Object> caffeineBuilder
 | 
			
		||||
                = Caffeine.newBuilder()
 | 
			
		||||
                .weigher(collectionSafeWeigher())
 | 
			
		||||
                .maximumWeight(cacheSpec.getMaxSize())
 | 
			
		||||
                .expireAfterWrite(cacheSpec.getTimeToLiveInMinutes(), TimeUnit.MINUTES)
 | 
			
		||||
                .maximumSize(cacheSpec.getMaxSize())
 | 
			
		||||
                .ticker(ticker());
 | 
			
		||||
        return new CaffeineCache(name, caffeineBuilder.build());
 | 
			
		||||
    }
 | 
			
		||||
@ -80,4 +83,12 @@ public class CaffeineCacheConfiguration {
 | 
			
		||||
        return new PreviousDeviceCredentialsIdKeyGenerator();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Weigher<? super Object, ? super Object> collectionSafeWeigher() {
 | 
			
		||||
        return (Weigher<Object, Object>) (key, value) -> {
 | 
			
		||||
            if(value instanceof Collection) {
 | 
			
		||||
                return ((Collection) value).size();
 | 
			
		||||
            }
 | 
			
		||||
            return 1;
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user