Search in sources :

Example 71 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class ClientCacheStatsTest method testNearCacheStatsWhenNearCacheEnabled.

@Test
public void testNearCacheStatsWhenNearCacheEnabled() {
    String cacheName = randomName();
    CacheConfig cacheConfig = createCacheConfig();
    cacheConfig.setName(cacheName);
    ClientConfig clientConfig = ((HazelcastClientProxy) client).getClientConfig();
    clientConfig.addNearCacheConfig(new NearCacheConfig().setName(cacheName));
    ICache<Integer, String> cache = createCache(cacheName, cacheConfig);
    CacheStatistics stats = cache.getLocalCacheStatistics();
    assertNotNull(stats.getNearCacheStatistics());
}
Also used : CacheStatistics(com.hazelcast.cache.CacheStatistics) NearCacheConfig(com.hazelcast.config.NearCacheConfig) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy) CacheConfig(com.hazelcast.config.CacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) CacheStatsTest(com.hazelcast.cache.stats.CacheStatsTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class AbstractCacheService method deleteCache.

@Override
public void deleteCache(String name, String callerUuid, boolean destroy) {
    CacheConfig config = deleteCacheConfig(name);
    if (destroy) {
        destroySegments(name);
        sendInvalidationEvent(name, null, SOURCE_NOT_AVAILABLE);
    } else {
        closeSegments(name);
    }
    cacheContexts.remove(name);
    operationProviderCache.remove(name);
    deregisterAllListener(name);
    setStatisticsEnabled(config, name, false);
    setManagementEnabled(config, name, false);
    deleteCacheStat(name);
    deleteCacheResources(name);
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig)

Example 73 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 74 with CacheConfig

use of com.hazelcast.config.CacheConfig in project hazelcast by hazelcast.

the class CacheReplicationOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    super.readInternal(in);
    int confSize = in.readInt();
    for (int i = 0; i < confSize; i++) {
        final CacheConfig config = in.readObject();
        configs.add(config);
    }
    int count = in.readInt();
    for (int i = 0; i < count; i++) {
        int subCount = in.readInt();
        String name = in.readUTF();
        Map<Data, CacheRecord> m = new HashMap<Data, CacheRecord>(subCount);
        data.put(name, m);
        // which adds another Data entry at the end of the stream!
        for (int j = 0; j < subCount + 1; j++) {
            Data key = in.readData();
            // the number on the stream due to found expired entries
            if (key == null || key.dataSize() == 0) {
                break;
            }
            CacheRecord record = in.readObject();
            m.put(key, record);
        }
    }
    nearCacheStateHolder.readData(in);
}
Also used : CacheRecord(com.hazelcast.cache.impl.record.CacheRecord) HashMap(java.util.HashMap) Data(com.hazelcast.nio.serialization.Data) CacheConfig(com.hazelcast.config.CacheConfig)

Example 75 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)

Aggregations

CacheConfig (com.hazelcast.config.CacheConfig)77 Test (org.junit.Test)30 CacheManager (javax.cache.CacheManager)28 QuickTest (com.hazelcast.test.annotation.QuickTest)27 ParallelTest (com.hazelcast.test.annotation.ParallelTest)25 CachingProvider (javax.cache.spi.CachingProvider)16 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 AssertTask (com.hazelcast.test.AssertTask)13 NearCacheConfig (com.hazelcast.config.NearCacheConfig)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ICacheService (com.hazelcast.cache.impl.ICacheService)8 HazelcastClientCachingProvider (com.hazelcast.client.cache.impl.HazelcastClientCachingProvider)8 ICache (com.hazelcast.cache.ICache)5 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 Data (com.hazelcast.nio.serialization.Data)5 CacheService (com.hazelcast.cache.impl.CacheService)4 HazelcastServerCachingProvider.createCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider.createCachingProvider)4 Map (java.util.Map)4