本文整理汇总了Java中org.ehcache.config.builders.CacheConfigurationBuilder.getExistingServiceConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java CacheConfigurationBuilder.getExistingServiceConfiguration方法的具体用法?Java CacheConfigurationBuilder.getExistingServiceConfiguration怎么用?Java CacheConfigurationBuilder.getExistingServiceConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ehcache.config.builders.CacheConfigurationBuilder
的用法示例。
在下文中一共展示了CacheConfigurationBuilder.getExistingServiceConfiguration方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleStoreByValue
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
private <K, V> CacheConfigurationBuilder<K, V> handleStoreByValue(Eh107CompleteConfiguration<K, V> jsr107Configuration, CacheConfigurationBuilder<K, V> builder, String cacheName) {
DefaultCopierConfiguration copierConfig = builder.getExistingServiceConfiguration(DefaultCopierConfiguration.class);
if(copierConfig == null) {
if(jsr107Configuration.isStoreByValue()) {
if (xmlConfiguration != null) {
DefaultCopyProviderConfiguration defaultCopyProviderConfiguration = findSingletonAmongst(DefaultCopyProviderConfiguration.class,
xmlConfiguration.getServiceCreationConfigurations().toArray());
if (defaultCopyProviderConfiguration != null) {
Map<Class<?>, ClassInstanceConfiguration<Copier<?>>> defaults = defaultCopyProviderConfiguration.getDefaults();
handleCopierDefaultsforImmutableTypes(defaults);
boolean matchingDefault = false;
if (defaults.containsKey(jsr107Configuration.getKeyType())) {
matchingDefault = true;
} else {
builder = builder.add(new DefaultCopierConfiguration<>(SerializingCopier.<K>asCopierClass(), DefaultCopierConfiguration.Type.KEY));
}
if (defaults.containsKey(jsr107Configuration.getValueType())) {
matchingDefault = true;
} else {
builder = builder.add(new DefaultCopierConfiguration<>(SerializingCopier.<K>asCopierClass(), DefaultCopierConfiguration.Type.VALUE));
}
if (matchingDefault) {
LOG.info("CacheManager level copier configuration overwriting JSR-107 by-value semantics for cache {}", cacheName);
}
return builder;
}
}
builder = addDefaultCopiers(builder, jsr107Configuration.getKeyType(), jsr107Configuration.getValueType());
LOG.debug("Using default Copier for JSR-107 store-by-value cache {}", cacheName);
}
} else {
LOG.info("Cache level copier configuration overwriting JSR-107 by-value semantics for cache {}", cacheName);
}
return builder;
}
示例2: mergeConfigurations
import org.ehcache.config.builders.CacheConfigurationBuilder; //导入方法依赖的package包/类
<K, V> ConfigHolder<K, V> mergeConfigurations(String cacheName, Configuration<K, V> configuration) {
final Eh107CompleteConfiguration<K, V> jsr107Configuration = new Eh107CompleteConfiguration<>(configuration);
Eh107Expiry<K, V> expiryPolicy = null;
Jsr107CacheLoaderWriter<? super K, V> loaderWriter = null;
try {
CacheConfigurationBuilder<K, V> builder = newCacheConfigurationBuilder(configuration.getKeyType(), configuration.getValueType(), heap(Long.MAX_VALUE));
String templateName = jsr107Service.getTemplateNameForCache(cacheName);
if (xmlConfiguration != null && templateName != null) {
CacheConfigurationBuilder<K, V> templateBuilder;
try {
templateBuilder = xmlConfiguration.newCacheConfigurationBuilderFromTemplate(templateName,
jsr107Configuration.getKeyType(), jsr107Configuration.getValueType());
} catch (IllegalStateException e) {
templateBuilder = xmlConfiguration.newCacheConfigurationBuilderFromTemplate(templateName,
jsr107Configuration.getKeyType(), jsr107Configuration.getValueType(), heap(Long.MAX_VALUE));
}
if (templateBuilder != null) {
builder = templateBuilder;
LOG.info("Configuration of cache {} will be supplemented by template {}", cacheName, templateName);
}
}
builder = handleStoreByValue(jsr107Configuration, builder, cacheName);
final boolean hasConfiguredExpiry = builder.hasConfiguredExpiry();
if (hasConfiguredExpiry) {
LOG.info("Cache {} will use expiry configuration from template {}", cacheName, templateName);
} else {
expiryPolicy = initExpiryPolicy(jsr107Configuration);
builder = builder.withExpiry(expiryPolicy);
}
boolean useEhcacheLoaderWriter;
DefaultCacheLoaderWriterConfiguration ehcacheLoaderWriterConfiguration = builder.getExistingServiceConfiguration(DefaultCacheLoaderWriterConfiguration.class);
if (ehcacheLoaderWriterConfiguration == null) {
useEhcacheLoaderWriter = false;
// No template loader/writer - let's activate the JSR-107 one if any
loaderWriter = initCacheLoaderWriter(jsr107Configuration, new MultiCacheException());
if (loaderWriter != null && (jsr107Configuration.isReadThrough() || jsr107Configuration.isWriteThrough())) {
cacheLoaderWriterFactory.registerJsr107Loader(cacheName, loaderWriter);
}
} else {
useEhcacheLoaderWriter = true;
if (!jsr107Configuration.isReadThrough() && !jsr107Configuration.isWriteThrough()) {
LOG.warn("Activating Ehcache loader/writer for JSR-107 cache {} which was neither read-through nor write-through", cacheName);
}
LOG.info("Cache {} will use loader/writer configuration from template {}", cacheName, templateName);
}
CacheConfiguration<K, V> cacheConfiguration = builder.build();
setupManagementAndStatsInternal(jsr107Configuration, findSingletonAmongst(Jsr107CacheConfiguration.class, cacheConfiguration.getServiceConfigurations()));
if (hasConfiguredExpiry) {
expiryPolicy = new EhcacheExpiryWrapper<>(cacheConfiguration.getExpiryPolicy());
}
return new ConfigHolder<>(
new CacheResources<>(cacheName, loaderWriter, expiryPolicy, initCacheEventListeners(jsr107Configuration)),
new Eh107CompleteConfiguration<>(jsr107Configuration, cacheConfiguration, hasConfiguredExpiry, useEhcacheLoaderWriter),
cacheConfiguration, useEhcacheLoaderWriter);
} catch (Throwable throwable) {
MultiCacheException mce = new MultiCacheException();
CacheResources.close(expiryPolicy, mce);
CacheResources.close(loaderWriter, mce);
if (throwable instanceof IllegalArgumentException) {
String message = throwable.getMessage();
if (mce.getMessage() != null) {
message = message + "\nSuppressed " + mce.getMessage();
}
throw new IllegalArgumentException(message, throwable);
}
mce.addFirstThrowable(throwable);
throw mce;
}
}