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;
}
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;
}
Aggregations