org.infinispan.jcache.ConfigurationAdapter Maven / Gradle / Ivy
package org.infinispan.jcache;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import javax.cache.configuration.CompleteConfiguration;
import javax.cache.configuration.Configuration;
import javax.cache.configuration.Factory;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.integration.CacheLoader;
import javax.cache.integration.CacheWriter;
/**
* ConfigurationAdapter takes {@link javax.cache.configuration.Configuration} and creates
* equivalent instance of {@link org.infinispan.configuration.cache.Configuration}
*
* @author Vladimir Blagojevic
* @author Galder Zamarreño
* @since 5.3
*/
public class ConfigurationAdapter {
private MutableConfiguration c;
private ConfigurationAdapter(MutableConfiguration configuration) {
this.c = configuration;
}
public MutableConfiguration getConfiguration() {
return c;
}
public org.infinispan.configuration.cache.Configuration build() {
ConfigurationBuilder cb = new ConfigurationBuilder();
if (c.isStoreByValue())
cb.storeAsBinary().enable();
Factory> cacheLoaderFactory = c.getCacheLoaderFactory();
if (cacheLoaderFactory != null) {
// User-defined cache loader will be plugged once cache has started
cb.persistence().addStore(JStoreAdapterConfigurationBuilder.class);
}
Factory> cacheWriterFactory = c.getCacheWriterFactory();
if (cacheWriterFactory != null) {
// User-defined cache writer will be plugged once cache has started
cb.persistence().addStore(JCacheWriterAdapterConfigurationBuilder.class);
}
if (c.isStatisticsEnabled())
cb.jmxStatistics().enable();
return cb.build();
}
public static ConfigurationAdapter create(Configuration c) {
// A configuration copy as required by the spec
if (c instanceof CompleteConfiguration) {
return new ConfigurationAdapter(
new MutableConfiguration((CompleteConfiguration) c));
} else {
//support use of Basic Configuration
MutableConfiguration mutableConfiguration = new MutableConfiguration();
mutableConfiguration.setStoreByValue(c.isStoreByValue());
mutableConfiguration.setTypes(c.getKeyType(), c.getValueType());
return new ConfigurationAdapter(
new MutableConfiguration(mutableConfiguration));
}
}
public static ConfigurationAdapter create() {
return new ConfigurationAdapter(new MutableConfiguration());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy