本文整理汇总了Java中javax.cache.configuration.MutableConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java MutableConfiguration类的具体用法?Java MutableConfiguration怎么用?Java MutableConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MutableConfiguration类属于javax.cache.configuration包,在下文中一共展示了MutableConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JCacheConfiguration
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
public JCacheConfiguration(Configuration<K, V> configuration) {
if (configuration != null) {
if (configuration instanceof RedissonConfiguration) {
configuration = ((RedissonConfiguration<K, V>)configuration).getJcacheConfig();
}
if (configuration instanceof CompleteConfiguration) {
delegate = new MutableConfiguration<K, V>((CompleteConfiguration<K, V>) configuration);
} else {
delegate = new MutableConfiguration<K, V>();
delegate.setStoreByValue(configuration.isStoreByValue());
delegate.setTypes(configuration.getKeyType(), configuration.getValueType());
}
} else {
delegate = new MutableConfiguration<K, V>();
}
this.expiryPolicy = delegate.getExpiryPolicyFactory().create();
}
示例2: configure
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
//programmatically configured cache
Configuration<String, String> programmaticCache =
new MutableConfiguration<String, String>()
.setTypes(String.class, String.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_HOUR))
.setReadThrough(true)
.setWriteThrough(true)
.addCacheEntryListenerConfiguration(new MyCache2EntryListenerConfiguration());
//contribute the cache into BQ
JCacheModule.extend(binder).setConfiguration("myCache2", programmaticCache);
BQCoreModule.extend(binder).addCommand(DemoHazelcastCommand.class);
}
示例3: cacheExposesMetrics
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@ParameterizedTest
@MethodSource("cachingProviders")
void cacheExposesMetrics(CachingProvider provider) {
CacheManager cacheManager = provider.getCacheManager();
MutableConfiguration<Integer, String> configuration = new MutableConfiguration<>();
configuration.setTypes(Integer.class, String.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
.setStatisticsEnabled(true);
Cache<Integer, String> cache = cacheManager.createCache("a", configuration);
cache.put(1, "test");
MeterRegistry registry = new SimpleMeterRegistry();
JCacheMetrics.monitor(registry, cache, "jcache", emptyList());
assertThat(registry.mustFind("jcache.puts").tags("name", "a").gauge().value()).isEqualTo(1.0);
}
示例4: createCache
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
/**
* Create a new cache from the given cache manager.
*
* @param cacheName Name of the cache.
* @param keyClass Type of the key class.
* @param valueClass Type of the value class.
* @param defaultExpiryTime Cache expire time in minutes.
* @param cacheConfigMap Cache config map.
* @param cacheManager Cache manager to use to create the cache.
* @param <K> Type of the Key.
* @param <V> Type of the Value.
* @return Created cache.
*/
public static <K, V> Cache<K, V> createCache(String cacheName, Class<K> keyClass, Class<V> valueClass,
int defaultExpiryTime, Map<String, CacheConfig> cacheConfigMap,
CacheManager cacheManager) {
Duration cacheExpiry = new Duration(TimeUnit.MINUTES, getExpireTime(cacheConfigMap, cacheName,
defaultExpiryTime));
boolean isStatisticsEnabled = false;
if (cacheConfigMap.get(cacheName) != null) {
isStatisticsEnabled = cacheConfigMap.get(cacheName).isStatisticsEnabled();
}
MutableConfiguration<K, V> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false)
.setTypes(keyClass, valueClass)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(cacheExpiry))
.setStatisticsEnabled(isStatisticsEnabled);
return cacheManager.createCache(cacheName, configuration);
}
示例5: testCacheManagerWithCustomInvalidProperties
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testCacheManagerWithCustomInvalidProperties()
throws Exception
{
Properties properties = new Properties();
properties.setProperty("unknownProperty", "true");
try (CacheManager cacheManager = cachingProvider.getCacheManager(null, null, properties);)
{
assertNotNull(cacheManager);
MutableConfiguration configuration = new MutableConfiguration();
configuration.setStoreByValue(false);
cacheManager.createCache("test", configuration);
}
}
示例6: testCreateCacheWithModifiedExpiryPolicy
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Test
public void testCreateCacheWithModifiedExpiryPolicy()
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY));
Cache cache = cacheManager.createCache("cache", configuration);
CompleteConfiguration actualConfiguration =
(CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);
assertEquals(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY), actualConfiguration.getExpiryPolicyFactory());
}
示例7: testCreateCacheWithTouchedExpiryPolicy
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Test
public void testCreateCacheWithTouchedExpiryPolicy()
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));
Cache cache = cacheManager.createCache("cache", configuration);
CompleteConfiguration actualConfiguration =
(CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);
assertEquals(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE), actualConfiguration.getExpiryPolicyFactory());
}
示例8: init
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Before
public void init()
{
cachingProvider = Caching.getCachingProvider(GuavaCachingProvider.class.getName());
assertNotNull(cachingProvider);
cacheManager = cachingProvider.getCacheManager();
assertNotNull(cacheManager);
configuration.setStoreByValue(false);
configuration.setTypes(String.class, Integer.class);
cache = cacheManager.createCache("cache", configuration);
assertNotNull(cache);
assertEquals("cache", cache.getName());
assertEquals(cacheManager, cache.getCacheManager());
assertEquals(configuration, cache.getConfiguration(MutableConfiguration.class));
}
示例9: getOrCreateCacheConfiguration
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
Configuration getOrCreateCacheConfiguration() {
if (configuration.getCacheConfiguration() != null) {
return configuration.getCacheConfiguration();
}
MutableConfiguration mutableConfiguration = new MutableConfiguration();
if (configuration.getCacheLoaderFactory() != null) {
mutableConfiguration.setCacheLoaderFactory(configuration.getCacheLoaderFactory());
}
if (configuration.getCacheWriterFactory() != null) {
mutableConfiguration.setCacheWriterFactory(configuration.getCacheWriterFactory());
}
if (configuration.getExpiryPolicyFactory() != null) {
mutableConfiguration.setExpiryPolicyFactory(configuration.getExpiryPolicyFactory());
}
mutableConfiguration.setManagementEnabled(configuration.isManagementEnabled());
mutableConfiguration.setStatisticsEnabled(configuration.isStatisticsEnabled());
mutableConfiguration.setReadThrough(configuration.isReadThrough());
mutableConfiguration.setStoreByValue(configuration.isStoreByValue());
return mutableConfiguration;
}
示例10: maybeCreateCache
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
public synchronized <K, V> Cache<K, V> maybeCreateCache(final String name,
final MutableConfiguration<K, V> mutableConfiguration) {
checkNotNull(name);
checkNotNull(mutableConfiguration);
Cache<K, V> cache = manager()
.getCache(name, mutableConfiguration.getKeyType(), mutableConfiguration.getValueType());
if (cache == null) {
cache = manager().createCache(name, mutableConfiguration);
log.debug("Created cache: {}", cache);
}
else {
log.debug("Re-using existing cache: {}", cache);
}
return cache;
}
示例11: createCacheConfig
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
public static <K, V> MutableConfiguration<K, V> createCacheConfig(
@Nullable final Class<K> keyType,
@Nullable final Class<V> valueType,
final Factory<? extends ExpiryPolicy> expiryPolicyFactory)
{
MutableConfiguration<K, V> config = new MutableConfiguration<K, V>()
.setStoreByValue(false)
.setExpiryPolicyFactory(expiryPolicyFactory)
.setManagementEnabled(true)
.setStatisticsEnabled(true);
if (keyType != null && valueType != null) {
config.setTypes(keyType, valueType);
}
return config;
}
示例12: setup
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Override
protected void setup(Settings settings, CacheManager cacheManager) {
cacheManager.createCache(STRING_LONG_CACHE, new MutableConfiguration()
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf())
.setStatisticsEnabled(true)
.setStoreByValue(true));
cacheManager.createCache(STRING_STRING_CACHE, new MutableConfiguration()
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf())
.setStatisticsEnabled(true)
.setStoreByValue(true));
cacheManager.createCache(LONG_STRING_CACHE, new MutableConfiguration()
.setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf())
.setStatisticsEnabled(true)
.setStoreByValue(true));
}
示例13: before
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@BeforeClass
public static void before() throws Exception {
dataModel = Converters.toDataModel(new XSSFWorkbook(pathDataModel));
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration config = new MutableConfiguration();
config.setStoreByValue(false)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ETERNAL))
.setStatisticsEnabled(false);
cacheManager.createCache(CacheBasedDataSetAccessor.DATA_SET_TO_ID_CACHE_NAME, config.setTypes(IDataModelId.class, IDataSet.class));
cacheManager.createCache(CacheBasedDataSetAccessor.DATA_SET_TO_NAME_CACHE_NAME, config.setTypes(String.class, IDataSet.class));
ExternalServices.INSTANCE.setDataSetAccessor(new CacheBasedDataSetAccessor());
expectedValues = new HashMap<>();
SpreadsheetEvaluator evaluator = new SpreadsheetEvaluator(dataModel);
for (int i = expectedRowStart; i <= expectedRowEnd; i++) {
ICellValue value = evaluator.evaluate(A1Address.fromA1Address(expectedColumn + i)).getResult();
expectedValues.put(expectedColumn + i, value.get());
}
}
示例14: JCacheTemplateCache
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
public JCacheTemplateCache() {
Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
if (cachingProviders.hasNext()) {
CachingProvider cachingProvider = cachingProviders.next();
CacheManager cacheManager = cachingProvider.getCacheManager();
Configuration<String, Template> config = new MutableConfiguration<String, Template>()
.setTypes(String.class, Template.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
if (cache == null) {
this.cache = cacheManager.createCache("TemplateCache", config);
} else {
this.cache = cache;
}
} else {
this.cache = null; // to keep compatibility with 0.1.0, but ugly
}
}
示例15: testStatistics
import javax.cache.configuration.MutableConfiguration; //导入依赖的package包/类
@Test
public void testStatistics() {
CachingProvider cachingProvider = Caching.getCachingProvider();
Properties p = new Properties();
try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
MutableConfiguration<String, String> config
= new MutableConfiguration<String, String>()
.setTypes(String.class, String.class)
.setStatisticsEnabled(true)
.setManagementEnabled(true);
BlazingCacheCache<String, String> cache = cacheManager.createCache("simpleCache", config).unwrap(BlazingCacheCache.class);
BlazingCacheStatisticsMXBean<String, String> stats = cache.getStatisticsMXBean();
cache.put("1", "test");
cache.get("1");
assertEquals(1L, stats.getCachePuts());
assertEquals(1L, stats.getCacheGets());
assertEquals(1L, stats.getCacheHits());
cache.get("2");
assertEquals(1L, stats.getCacheMisses());
stats.clear();
assertEquals(0L, stats.getCachePuts());
assertEquals(0L, stats.getCacheGets());
assertEquals(0L, stats.getCacheHits());
assertEquals(0L, stats.getCacheMisses());
}
}