Search in sources :

Example 1 with CompleteConfiguration

use of javax.cache.configuration.CompleteConfiguration in project Payara by payara.

the class CacheManagerProxy method createCache.

@Override
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String string, C config) throws IllegalArgumentException {
    Cache<K, V> cache;
    JavaEEContextUtil ctxUtil = serverContext.getDefaultServices().getService(JavaEEContextUtil.class);
    if (ctxUtil != null && config instanceof CompleteConfiguration) {
        CompleteConfiguration<K, V> cfg = new CompleteConfigurationProxy<>((CompleteConfiguration<K, V>) config, ctxUtil);
        cache = delegate.createCache(string, cfg);
    } else {
        cache = delegate.createCache(string, config);
    }
    return ctxUtil != null ? new CacheProxy<>(cache, ctxUtil) : cache;
}
Also used : CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) JavaEEContextUtil(org.glassfish.internal.api.JavaEEContextUtil)

Example 2 with CompleteConfiguration

use of javax.cache.configuration.CompleteConfiguration in project cache2k by cache2k.

the class JCacheBuilder method setConfiguration.

public void setConfiguration(Configuration<K, V> cfg) {
    if (cfg instanceof CompleteConfiguration) {
        config = (CompleteConfiguration<K, V>) cfg;
        if (cfg instanceof ExtendedConfiguration) {
            cache2kConfiguration = ((ExtendedConfiguration<K, V>) cfg).getCache2kConfiguration();
            if (cache2kConfiguration != null) {
                if (cache2kConfiguration.getName() != null && !cache2kConfiguration.getName().equals(name)) {
                    throw new IllegalArgumentException("cache name mismatch.");
                }
                cache2kConfigurationWasProvided = true;
            }
        }
    } else {
        MutableConfiguration<K, V> _cfgCopy = new MutableConfiguration<K, V>();
        _cfgCopy.setTypes(cfg.getKeyType(), cfg.getValueType());
        _cfgCopy.setStoreByValue(cfg.isStoreByValue());
        config = _cfgCopy;
    }
    if (cache2kConfiguration == null) {
        cache2kConfiguration = CacheManagerImpl.PROVIDER.getDefaultConfiguration(manager.getCache2kManager());
        if (cfg instanceof ExtendedMutableConfiguration) {
            ((ExtendedMutableConfiguration) cfg).setCache2kConfiguration(cache2kConfiguration);
        }
    }
    cache2kConfiguration.setName(name);
    Cache2kCoreProviderImpl.augmentConfiguration(manager.getCache2kManager(), cache2kConfiguration);
    cache2kConfigurationWasProvided |= cache2kConfiguration.isExternalConfigurationPresent();
    if (cache2kConfigurationWasProvided) {
        extraConfiguration = CACHE2K_DEFAULTS;
        JCacheConfiguration _extraConfigurationSpecified = cache2kConfiguration.getSections().getSection(JCacheConfiguration.class);
        if (_extraConfigurationSpecified != null) {
            extraConfiguration = _extraConfigurationSpecified;
        }
    }
}
Also used : ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) JCacheConfiguration(org.cache2k.jcache.JCacheConfiguration) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) ExtendedConfiguration(org.cache2k.jcache.ExtendedConfiguration) ExtendedMutableConfiguration(org.cache2k.jcache.ExtendedMutableConfiguration) MutableConfiguration(javax.cache.configuration.MutableConfiguration)

Example 3 with CompleteConfiguration

use of javax.cache.configuration.CompleteConfiguration in project pdi-dataservice-server-plugin by pentaho.

the class ServiceCache method ttlMatches.

private boolean ttlMatches(Cache<CachedService.CacheKey, CachedService> cache, LogChannelInterface log) {
    CompleteConfiguration config = cache.getConfiguration(CompleteConfiguration.class);
    if (getTimeToLive() == null) {
        // ttl has not been modified
        return true;
    }
    if (config != null) {
        try {
            Duration duration = getConfigDuration(config);
            long ttl = Long.parseLong(getTimeToLive());
            return ttl == duration.getDurationAmount();
        } catch (NumberFormatException nfe) {
            log.logError(String.format("Failed to determine configured TTL value for cache '%s'.  TTL value = '%s'", cache.getName(), getTimeToLive()));
            throw nfe;
        }
    }
    log.logError(String.format("Failed to check TTL consistency with cache for name '%s'.\n  Assuming cache can be used", cache.getName()));
    return true;
}
Also used : CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) Duration(javax.cache.expiry.Duration)

Example 4 with CompleteConfiguration

use of javax.cache.configuration.CompleteConfiguration in project hazelcast by hazelcast.

the class CacheSerializationTest method test_CacheReplicationOperation_serialization.

@Test
public void test_CacheReplicationOperation_serialization() throws Exception {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();
    try {
        CachingProvider provider = createServerCachingProvider(hazelcastInstance);
        CacheManager manager = provider.getCacheManager();
        CompleteConfiguration configuration = new MutableConfiguration();
        Cache cache1 = manager.createCache("cache1", configuration);
        Cache cache2 = manager.createCache("cache2", configuration);
        Cache cache3 = manager.createCache("cache3", configuration);
        for (int i = 0; i < 1000; i++) {
            cache1.put("key" + i, i);
            cache2.put("key" + i, i);
            cache3.put("key" + i, i);
        }
        HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;
        Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
        original.setAccessible(true);
        HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
        NodeEngineImpl nodeEngine = impl.node.nodeEngine;
        CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);
        int partitionCount = nodeEngine.getPartitionService().getPartitionCount();
        for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
            CachePartitionSegment segment = cacheService.getSegment(partitionId);
            int replicaIndex = 1;
            Collection<ServiceNamespace> namespaces = segment.getAllNamespaces(replicaIndex);
            if (CollectionUtil.isEmpty(namespaces)) {
                continue;
            }
            CacheReplicationOperation operation = new CacheReplicationOperation();
            operation.prepare(segment, namespaces, replicaIndex);
            Data serialized = service.toData(operation);
            try {
                service.toObject(serialized);
            } catch (Exception e) {
                throw new Exception("Partition: " + partitionId, e);
            }
        }
    } finally {
        factory.shutdownAll();
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) CachePartitionSegment(com.hazelcast.cache.impl.CachePartitionSegment) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) CacheReplicationOperation(com.hazelcast.cache.impl.operation.CacheReplicationOperation) Data(com.hazelcast.internal.serialization.Data) CachePartitionEventData(com.hazelcast.cache.impl.CachePartitionEventData) HazelcastInstanceProxy(com.hazelcast.instance.impl.HazelcastInstanceProxy) MutableConfiguration(javax.cache.configuration.MutableConfiguration) UnknownHostException(java.net.UnknownHostException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheManager(javax.cache.CacheManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache) CacheService(com.hazelcast.cache.impl.CacheService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with CompleteConfiguration

use of javax.cache.configuration.CompleteConfiguration in project ignite by apache.

the class CacheManager method createCache.

/**
 * {@inheritDoc}
 */
@Override
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName, C cacheCfg) throws IllegalArgumentException {
    kernalGateway.readLock();
    try {
        if (cacheCfg == null)
            throw new NullPointerException();
        if (cacheName == null)
            throw new NullPointerException();
        CacheConfiguration<K, V> igniteCacheCfg;
        if (cacheCfg instanceof CompleteConfiguration)
            igniteCacheCfg = new CacheConfiguration<>((CompleteConfiguration<K, V>) cacheCfg);
        else {
            igniteCacheCfg = new CacheConfiguration<>();
            igniteCacheCfg.setTypes(cacheCfg.getKeyType(), cacheCfg.getValueType());
        }
        igniteCacheCfg.setName(cacheName);
        IgniteCache<K, V> res = ignite.createCache(igniteCacheCfg);
        if (res == null)
            throw new CacheException();
        ((GatewayProtectedCacheProxy<K, V>) res).setCacheManager(this);
        if (igniteCacheCfg.isManagementEnabled())
            enableManagement(cacheName, true);
        if (igniteCacheCfg.isStatisticsEnabled())
            enableStatistics(cacheName, true);
        return res;
    } finally {
        kernalGateway.readUnlock();
    }
}
Also used : GatewayProtectedCacheProxy(org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy) CompleteConfiguration(javax.cache.configuration.CompleteConfiguration) CacheException(javax.cache.CacheException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CompleteConfiguration (javax.cache.configuration.CompleteConfiguration)5 MutableConfiguration (javax.cache.configuration.MutableConfiguration)2 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)1 CachePartitionEventData (com.hazelcast.cache.impl.CachePartitionEventData)1 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)1 CacheService (com.hazelcast.cache.impl.CacheService)1 CacheReplicationOperation (com.hazelcast.cache.impl.operation.CacheReplicationOperation)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 HazelcastInstanceImpl (com.hazelcast.instance.impl.HazelcastInstanceImpl)1 HazelcastInstanceProxy (com.hazelcast.instance.impl.HazelcastInstanceProxy)1 Data (com.hazelcast.internal.serialization.Data)1 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Field (java.lang.reflect.Field)1 UnknownHostException (java.net.UnknownHostException)1 Cache (javax.cache.Cache)1 CacheException (javax.cache.CacheException)1