Search in sources :

Example 1 with Redisson

use of org.redisson.Redisson 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)

Example 2 with Redisson

use of org.redisson.Redisson in project redisson by redisson.

the class JCachingProvider method getCacheManager.

@Override
public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {
    if (uri == null) {
        uri = getDefaultURI();
    }
    if (uri == null) {
        throw new CacheException("Uri is not defined. Can't load default configuration");
    }
    if (classLoader == null) {
        classLoader = getDefaultClassLoader();
    }
    ConcurrentMap<URI, CacheManager> value = new ConcurrentHashMap<URI, CacheManager>();
    ConcurrentMap<URI, CacheManager> oldValue = managers.putIfAbsent(classLoader, value);
    if (oldValue != null) {
        value = oldValue;
    }
    CacheManager manager = value.get(uri);
    if (manager != null) {
        return manager;
    }
    Config config = loadConfig(uri);
    Redisson redisson = null;
    if (config != null) {
        redisson = (Redisson) Redisson.create(config);
    }
    manager = new JCacheManager(redisson, classLoader, this, properties, uri);
    CacheManager oldManager = value.putIfAbsent(uri, manager);
    if (oldManager != null) {
        if (redisson != null) {
            redisson.shutdown();
        }
        manager = oldManager;
    }
    return manager;
}
Also used : CacheException(javax.cache.CacheException) Config(org.redisson.config.Config) CacheManager(javax.cache.CacheManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) URI(java.net.URI) Redisson(org.redisson.Redisson)

Aggregations

CacheException (javax.cache.CacheException)2 Redisson (org.redisson.Redisson)2 URI (java.net.URI)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CacheManager (javax.cache.CacheManager)1 Config (org.redisson.config.Config)1 JCacheConfiguration (org.redisson.jcache.configuration.JCacheConfiguration)1 RedissonConfiguration (org.redisson.jcache.configuration.RedissonConfiguration)1