Search in sources :

Example 1 with RedissonConfiguration

use of org.redisson.jcache.configuration.RedissonConfiguration in project redisson by redisson.

the class JCacheManager method createCache.

@Override
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName, C configuration) throws IllegalArgumentException {
    checkNotClosed();
    Redisson cacheRedisson = redisson;
    if (cacheName == null) {
        throw new NullPointerException();
    }
    if (configuration == null) {
        throw new NullPointerException();
    }
    if (cacheRedisson == null && !(configuration instanceof RedissonConfiguration)) {
        throw new IllegalStateException("Default configuration hasn't been specified!");
    }
    boolean hasOwnRedisson = false;
    if (configuration instanceof RedissonConfiguration) {
        RedissonConfiguration<K, V> rc = (RedissonConfiguration<K, V>) configuration;
        if (rc.getConfig() != null) {
            cacheRedisson = (Redisson) Redisson.create(rc.getConfig());
            hasOwnRedisson = true;
        } else {
            cacheRedisson = (Redisson) rc.getRedisson();
        }
    }
    JCacheConfiguration<K, V> cfg = new JCacheConfiguration<K, V>(configuration);
    JCache<K, V> cache = new JCache<K, V>(this, cacheRedisson, cacheName, cfg, hasOwnRedisson);
    JCache<?, ?> oldCache = caches.putIfAbsent(cacheName, cache);
    if (oldCache != null) {
        throw new CacheException("Cache " + cacheName + " already exists");
    }
    if (cfg.isStatisticsEnabled()) {
        enableStatistics(cacheName, true);
    }
    if (cfg.isManagementEnabled()) {
        enableManagement(cacheName, true);
    }
    return cache;
}
Also used : CacheException(javax.cache.CacheException) RedissonConfiguration(org.redisson.jcache.configuration.RedissonConfiguration) Redisson(org.redisson.Redisson) JCacheConfiguration(org.redisson.jcache.configuration.JCacheConfiguration)

Aggregations

CacheException (javax.cache.CacheException)1 Redisson (org.redisson.Redisson)1 JCacheConfiguration (org.redisson.jcache.configuration.JCacheConfiguration)1 RedissonConfiguration (org.redisson.jcache.configuration.RedissonConfiguration)1