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;
}
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;
}
}
}
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;
}
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();
}
}
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();
}
}
Aggregations