Search in sources :

Example 96 with CacheConfig

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

the class AbstractCacheRecordStore method canPersistWanReplicatedData.

private boolean canPersistWanReplicatedData(CacheConfig cacheConfig, NodeEngine nodeEngine) {
    boolean persistWanReplicatedData = false;
    WanReplicationRef wanReplicationRef = cacheConfig.getWanReplicationRef();
    if (wanReplicationRef != null) {
        String wanReplicationRefName = wanReplicationRef.getName();
        Config config = nodeEngine.getConfig();
        WanReplicationConfig wanReplicationConfig = config.getWanReplicationConfig(wanReplicationRefName);
        if (wanReplicationConfig != null) {
            WanConsumerConfig wanConsumerConfig = wanReplicationConfig.getConsumerConfig();
            if (wanConsumerConfig != null) {
                persistWanReplicatedData = wanConsumerConfig.isPersistWanReplicatedData();
            }
        }
    }
    return persistWanReplicatedData;
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanReplicationRef(com.hazelcast.config.WanReplicationRef) WanConsumerConfig(com.hazelcast.config.WanConsumerConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig) CacheConfig(com.hazelcast.config.CacheConfig) WanConsumerConfig(com.hazelcast.config.WanConsumerConfig) ConfigValidator.checkCacheEvictionConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheEvictionConfig) EvictionConfig(com.hazelcast.config.EvictionConfig) Config(com.hazelcast.config.Config) WanReplicationConfig(com.hazelcast.config.WanReplicationConfig)

Example 97 with CacheConfig

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

the class AbstractCacheService method putCacheConfigIfAbsent.

@Override
public CacheConfig putCacheConfigIfAbsent(CacheConfig config) {
    // ensure all configs registered in CacheService are not PreJoinCacheConfig's
    CacheConfig cacheConfig = asCacheConfig(config);
    CompletableFuture<CacheConfig> future = new CompletableFuture<>();
    CompletableFuture<CacheConfig> localConfigFuture = configs.putIfAbsent(cacheConfig.getNameWithPrefix(), future);
    // if the existing cache config future is not yet fully configured, we block here
    CacheConfig localConfig = localConfigFuture == null ? null : localConfigFuture.join();
    if (localConfigFuture == null) {
        try {
            if (cacheConfig.isStatisticsEnabled()) {
                setStatisticsEnabled(cacheConfig, cacheConfig.getNameWithPrefix(), true);
            }
            if (cacheConfig.isManagementEnabled()) {
                setManagementEnabled(cacheConfig, cacheConfig.getNameWithPrefix(), true);
            }
            logger.info("Added cache config: " + cacheConfig);
            additionalCacheConfigSetup(config, false);
            // now it is safe for others to obtain the new cache config
            future.complete(cacheConfig);
        } catch (Throwable e) {
            configs.remove(cacheConfig.getNameWithPrefix(), future);
            future.completeExceptionally(e);
            throw rethrow(e);
        }
    } else {
        additionalCacheConfigSetup(localConfig, true);
    }
    return localConfig;
}
Also used : InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) CacheConfig(com.hazelcast.config.CacheConfig) ConfigValidator.checkCacheConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheConfig) PreJoinCacheConfig.asCacheConfig(com.hazelcast.cache.impl.PreJoinCacheConfig.asCacheConfig)

Example 98 with CacheConfig

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

the class AbstractCacheService method getMergePolicy.

public SplitBrainMergePolicy getMergePolicy(String dataStructureName) {
    CacheConfig cacheConfig = getCacheConfig(dataStructureName);
    String mergePolicyName = cacheConfig.getMergePolicyConfig().getPolicy();
    return mergePolicyProvider.getMergePolicy(mergePolicyName);
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig) ConfigValidator.checkCacheConfig(com.hazelcast.internal.config.ConfigValidator.checkCacheConfig) PreJoinCacheConfig.asCacheConfig(com.hazelcast.cache.impl.PreJoinCacheConfig.asCacheConfig)

Example 99 with CacheConfig

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

the class AbstractCacheService method createDistributedObject.

@Override
public DistributedObject createDistributedObject(String cacheNameWithPrefix, UUID source, boolean local) {
    try {
        /*
             * In here, cacheNameWithPrefix is the full cache name.
             * Full cache name contains, Hazelcast prefix, cache name prefix and pure cache name.
             */
        // At first, lookup cache name in the created cache configs.
        CacheConfig cacheConfig = getCacheConfig(cacheNameWithPrefix);
        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 = cacheNameWithPrefix.substring(HazelcastCacheManager.CACHE_MANAGER_PREFIX.length());
            // Lookup prefixed cache name in the config.
            cacheConfig = findCacheConfig(cacheName);
            if (cacheConfig == null) {
                throw new CacheNotExistsException("Couldn't find cache config with name " + cacheNameWithPrefix);
            }
            cacheConfig.setManagerPrefix(HazelcastCacheManager.CACHE_MANAGER_PREFIX);
        }
        checkCacheConfig(cacheConfig, mergePolicyProvider);
        if (putCacheConfigIfAbsent(cacheConfig) == null && !local) {
            // if the cache config was not previously known, ensure the new cache config
            // becomes available on all members before the proxy is returned to the caller
            createCacheConfigOnAllMembers(PreJoinCacheConfig.of(cacheConfig));
        }
        return new CacheProxy(cacheConfig, nodeEngine, this);
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : 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)

Example 100 with CacheConfig

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

the class RingbufferCacheEventJournalImpl method getEventJournalConfig.

/**
 * {@inheritDoc}
 *
 * @throws CacheNotExistsException if the cache configuration was not found
 */
@Override
public EventJournalConfig getEventJournalConfig(ObjectNamespace namespace) {
    String name = namespace.getObjectName();
    CacheConfig cacheConfig = getCacheService().getCacheConfig(name);
    if (cacheConfig == null) {
        throw new CacheNotExistsException("Cache " + name + " is already destroyed or not created yet, on " + nodeEngine.getLocalMember());
    }
    EventJournalConfig config = cacheConfig.getEventJournalConfig();
    if (config == null || !config.isEnabled()) {
        return null;
    }
    return config;
}
Also used : CacheConfig(com.hazelcast.config.CacheConfig) EventJournalConfig(com.hazelcast.config.EventJournalConfig) CacheNotExistsException(com.hazelcast.cache.CacheNotExistsException)

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