Search in sources :

Example 91 with CacheConfig

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.");
}
Also used : CacheException(javax.cache.CacheException) CacheConfig(com.hazelcast.config.CacheConfig)

Example 92 with CacheConfig

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);
    }
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 93 with CacheConfig

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);
    }
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 94 with CacheConfig

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);
    }
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) CacheConfig(com.hazelcast.config.CacheConfig)

Example 95 with CacheConfig

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);
    }
}
Also used : CacheSimpleConfig(com.hazelcast.config.CacheSimpleConfig) CacheException(javax.cache.CacheException) CacheConfig(com.hazelcast.config.CacheConfig) ConfigValidator.checkCacheConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheConfig) PreJoinCacheConfig.asCacheConfig(com.hazelcast.cache.impl.PreJoinCacheConfig.asCacheConfig) CacheNotExistsException(com.hazelcast.cache.CacheNotExistsException) CacheException(javax.cache.CacheException)

Aggregations

CacheConfig (com.hazelcast.config.CacheConfig)147 Test (org.junit.Test)65 QuickTest (com.hazelcast.test.annotation.QuickTest)55 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)48 CacheManager (javax.cache.CacheManager)45 HazelcastInstance (com.hazelcast.core.HazelcastInstance)34 CachingProvider (javax.cache.spi.CachingProvider)28 Config (com.hazelcast.config.Config)23 NearCacheConfig (com.hazelcast.config.NearCacheConfig)23 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 AssertTask (com.hazelcast.test.AssertTask)16 ClientConfig (com.hazelcast.client.config.ClientConfig)15 CacheTestSupport.createClientCachingProvider (com.hazelcast.cache.CacheTestSupport.createClientCachingProvider)14 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)11 ConfigValidator.checkCacheConfig (com.hazelcast.internal.config.ConfigValidator.checkCacheConfig)11 ICacheService (com.hazelcast.cache.impl.ICacheService)10 Cache (javax.cache.Cache)10 PreJoinCacheConfig.asCacheConfig (com.hazelcast.cache.impl.PreJoinCacheConfig.asCacheConfig)9 CacheConfigTest (com.hazelcast.config.CacheConfigTest)9