use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class AbstractHazelcastCacheManager method createCacheInternal.
private <K, V, C extends Configuration<K, V>> ICacheInternal<K, V> createCacheInternal(String cacheName, C configuration) throws IllegalArgumentException {
checkIfManagerNotClosed();
checkNotNull(cacheName, "cacheName must not be null");
checkNotNull(configuration, "configuration must not be null");
CacheConfig<K, V> newCacheConfig = createCacheConfig(cacheName, configuration);
if (caches.containsKey(newCacheConfig.getNameWithPrefix())) {
throw new CacheException("A cache named " + cacheName + " already exists.");
}
// Create cache config on all nodes as sync
CacheConfig<K, V> currentCacheConfig = createCacheConfig(cacheName, newCacheConfig, true, true);
// Create cache proxy object with cache config
ICacheInternal<K, V> cacheProxy = createCacheProxy(newCacheConfig);
if (currentCacheConfig == null) {
// Put created cache config.
// Single thread region because "createConfigOnPartition" is single threaded by partition thread
addCacheConfigIfAbsent(newCacheConfig);
// Put created cache. No need to a "putIfAbsent" as this is a single threaded region
caches.put(newCacheConfig.getNameWithPrefix(), cacheProxy);
// Register listeners
registerListeners(newCacheConfig, cacheProxy);
return cacheProxy;
}
ICacheInternal<?, ?> cache = getOrPutIfAbsent(currentCacheConfig.getNameWithPrefix(), cacheProxy);
CacheConfig config = cache.getConfiguration(CacheConfig.class);
if (config.equals(newCacheConfig)) {
return (ICacheInternal<K, V>) cache;
}
throw new CacheException("A cache named " + cacheName + " already exists.");
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class PostJoinCacheOperation method writeInternal.
@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
super.writeInternal(out);
out.writeInt(configs.size());
for (CacheConfig config : configs) {
out.writeObject(config);
}
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class PostJoinCacheOperation method readInternal.
@Override
protected void readInternal(ObjectDataInput in) throws IOException {
super.readInternal(in);
int confSize = in.readInt();
for (int i = 0; i < confSize; i++) {
CacheConfig config = in.readObject();
configs.add(config);
}
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class AbstractCacheService method createDistributedObject.
@Override
public DistributedObject createDistributedObject(String fullCacheName) {
try {
/*
* In here, `fullCacheName` is the full cache name.
* Full cache name contains, Hazelcast prefix, cache name prefix and pure cache name.
*/
if (fullCacheName.equals(SETUP_REF)) {
// workaround to make clients older than 3.7 to work with 3.7+ servers due to changes in the cache init!
CacheSimpleConfig cacheSimpleConfig = new CacheSimpleConfig();
cacheSimpleConfig.setName("setupRef");
CacheConfig cacheConfig = new CacheConfig(cacheSimpleConfig);
cacheConfig.setManagerPrefix(HazelcastCacheManager.CACHE_MANAGER_PREFIX);
return new CacheProxy(cacheConfig, nodeEngine, this);
} else {
// At first, lookup cache name in the created cache configs.
CacheConfig cacheConfig = getCacheConfig(fullCacheName);
if (cacheConfig == null) {
/*
* Prefixed cache name contains cache name prefix and pure cache name, but not Hazelcast prefix (`/hz/`).
* Cache name prefix is generated by using specified URI and classloader scopes.
* This means, if there is no specified URI and classloader, prefixed cache name is pure cache name.
* This means, if there is no specified URI and classloader, prefixed cache name is pure cache name.
*/
// If cache config is not created yet, remove Hazelcast prefix and get prefixed cache name.
String cacheName = fullCacheName.substring(HazelcastCacheManager.CACHE_MANAGER_PREFIX.length());
// Lookup prefixed cache name in the config.
cacheConfig = findCacheConfig(cacheName);
checkCacheSimpleConfig(cacheName, cacheConfig);
cacheConfig.setManagerPrefix(HazelcastCacheManager.CACHE_MANAGER_PREFIX);
}
checkCacheConfig(fullCacheName, cacheConfig);
putCacheConfigIfAbsent(cacheConfig);
return new CacheProxy(cacheConfig, nodeEngine, this);
}
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
}
use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.
the class AbstractCacheService method findCacheConfig.
@Override
public CacheConfig findCacheConfig(String simpleName) {
if (simpleName == null) {
return null;
}
CacheSimpleConfig cacheSimpleConfig = nodeEngine.getConfig().findCacheConfigOrNull(simpleName);
if (cacheSimpleConfig == null) {
return null;
}
try {
// Set name explicitly, because found config might have a wildcard name.
CacheConfig cacheConfig = new CacheConfig(cacheSimpleConfig).setName(simpleName);
CacheConfigAccessor.setSerializationService(cacheConfig, nodeEngine.getSerializationService());
return cacheConfig;
} catch (Exception e) {
throw new CacheException(e);
}
}
Aggregations