本文整理汇总了Java中javax.cache.configuration.CompleteConfiguration类的典型用法代码示例。如果您正苦于以下问题:Java CompleteConfiguration类的具体用法?Java CompleteConfiguration怎么用?Java CompleteConfiguration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompleteConfiguration类属于javax.cache.configuration包,在下文中一共展示了CompleteConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCache
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Override
public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType) {
checkNotClosed();
if (cacheName == null) {
throw new NullPointerException();
}
if (keyType == null) {
throw new NullPointerException();
}
if (valueType == null) {
throw new NullPointerException();
}
JCache<?, ?> cache = caches.get(cacheName);
if (cache == null) {
return null;
}
if (!keyType.isAssignableFrom(cache.getConfiguration(CompleteConfiguration.class).getKeyType())) {
throw new ClassCastException("Wrong type of key for " + cacheName);
}
if (!valueType.isAssignableFrom(cache.getConfiguration(CompleteConfiguration.class).getValueType())) {
throw new ClassCastException("Wrong type of value for " + cacheName);
}
return (Cache<K, V>) cache;
}
示例2: JCacheConfiguration
import javax.cache.configuration.CompleteConfiguration; //导入依赖的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();
}
示例3: getCache
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Override
public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType)
{
checkState();
if (cacheName != null && caches.containsKey(cacheName))
{
Cache<?, ?> cache = caches.get(cacheName);
CompleteConfiguration<?, ?> configuration = cache.getConfiguration(CompleteConfiguration.class);
if (configuration.getKeyType().isAssignableFrom(keyType)
&& configuration.getValueType().isAssignableFrom(valueType))
{
return (Cache<K, V>) cache;
}
throw new IllegalArgumentException("Provided key and/or value types are incompatible with this cache!");
}
return null;
}
示例4: testCreateCacheWithModifiedExpiryPolicy
import javax.cache.configuration.CompleteConfiguration; //导入依赖的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());
}
示例5: testCreateCacheWithTouchedExpiryPolicy
import javax.cache.configuration.CompleteConfiguration; //导入依赖的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());
}
示例6: jCacheCacheWithCachesAndCustomConfig
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Test
public void jCacheCacheWithCachesAndCustomConfig() {
String cachingProviderFqn = MockCachingProvider.class.getName();
load(JCacheCustomConfiguration.class, "spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn,
"spring.cache.cacheNames[0]=one", "spring.cache.cacheNames[1]=two");
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
assertThat(cacheManager.getCacheNames(), containsInAnyOrder("one", "two"));
assertThat(cacheManager.getCacheNames(), hasSize(2));
CompleteConfiguration<?, ?> defaultCacheConfiguration = this.context
.getBean(CompleteConfiguration.class);
verify(cacheManager.getCacheManager()).createCache("one",
defaultCacheConfiguration);
verify(cacheManager.getCacheManager()).createCache("two",
defaultCacheConfiguration);
}
示例7: getConfiguration
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <C extends Configuration<K, V>> C getConfiguration(Class<C> clazz)
{
Builder<K, V> builder = tcache.builder;
if (clazz.isAssignableFrom(javax.cache.configuration.Configuration.class))
{
return (C)builder;
}
if (clazz.isAssignableFrom(CompleteConfiguration.class))
{
return (C)builder;
}
throw new IllegalArgumentException("Unsupported configuration class: " + clazz.toString());
}
示例8: testUsingEhcacheConfiguration
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testUsingEhcacheConfiguration() throws Exception {
// tag::ehcacheBasedConfigurationExample[]
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.heap(10)).build(); // <1>
Cache<Long, String> cache = cacheManager.createCache("myCache",
Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration)); // <2>
Eh107Configuration<Long, String> configuration = cache.getConfiguration(Eh107Configuration.class);
configuration.unwrap(CacheConfiguration.class); // <3>
configuration.unwrap(CacheRuntimeConfiguration.class); // <4>
try {
cache.getConfiguration(CompleteConfiguration.class); // <5>
throw new AssertionError("IllegalArgumentException expected");
} catch (IllegalArgumentException iaex) {
// Expected
}
// end::ehcacheBasedConfigurationExample[]
}
示例9: createConfiguration
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Override public <K, V> CompleteConfiguration<K, V> createConfiguration( Class<K> keyType, Class<V> valueType,
Map<String, String> properties ) {
MutableConfiguration<K, V> configuration = new MutableConfiguration<K, V>();
configuration.setTypes( keyType, valueType );
if ( properties.containsKey( CONFIG_TTL ) ) {
Long ttl = Longs.tryParse( Strings.nullToEmpty( properties.get( CONFIG_TTL ) ) );
Preconditions.checkArgument( ttl != null, "Template config error", CONFIG_TTL );
Optional<ExpiryFunction> expiryFunction;
if ( properties.containsKey( CONFIG_TTL_RESET ) ) {
expiryFunction = Enums.getIfPresent( ExpiryFunction.class, properties.get( CONFIG_TTL_RESET ) );
} else {
expiryFunction = Optional.of( CONFIG_TTL_RESET_DEFAULT );
}
Preconditions.checkArgument( expiryFunction.isPresent(), "Template config error", CONFIG_TTL_RESET );
configuration.setExpiryPolicyFactory( expiryFunction.get().createFactory( ttl ) );
}
if ( properties.containsKey( CONFIG_STORE_BY_VALUE ) ) {
configuration.setStoreByValue( Boolean.valueOf( properties.get( CONFIG_STORE_BY_VALUE ) ) );
}
return configuration;
}
示例10: testCreateConfiguration
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Test
public void testCreateConfiguration() throws Exception {
CompleteConfiguration<String, List> configuration = service.createConfiguration(
String.class, List.class, ImmutableMap.<String, String>builder().
put( Constants.CONFIG_TTL, String.valueOf( 60 * 2 ) ).
put( Constants.CONFIG_TTL_RESET, Constants.ExpiryFunction.ACCESS.name() ).
put( Constants.CONFIG_STORE_BY_VALUE, "false" ).
build()
);
assertThat( configuration.getKeyType(), Matchers.<Class>equalTo( String.class ) );
assertThat( configuration.getValueType(), Matchers.<Class>equalTo( List.class ) );
assertFalse( configuration.isStoreByValue() );
ExpiryPolicy expiryPolicy = configuration.getExpiryPolicyFactory().create();
assertThat( expiryPolicy, instanceOf( AccessedExpiryPolicy.class ) );
assertThat( expiryPolicy.getExpiryForAccess(), equalTo( new Duration( TimeUnit.MINUTES, 2 ) ) );
assertThat( expiryPolicy.getExpiryForUpdate(), nullValue() );
}
示例11: cacheConfigTest
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Test
public void cacheConfigTest() {
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
MutableConfiguration<Long, String> configuration = new MutableConfiguration<Long, String>();
configuration.setTypes(Long.class, String.class);
Cache<Long, String> cache = cacheManager.createCache("someCache", configuration);
CompleteConfiguration<Long, String> completeConfiguration = cache.getConfiguration(CompleteConfiguration.class);
Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);
CacheRuntimeConfiguration<Long, String> runtimeConfiguration = eh107Configuration
.unwrap(CacheRuntimeConfiguration.class);
}
示例12: configEhcache2Jsr107
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Test
public void configEhcache2Jsr107() {
CachingProvider provider = Caching.getCachingProvider();
CacheManager cacheManager = provider.getCacheManager();
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)).build();
Cache<Long, String> cache = cacheManager.createCache("myCache",
Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));
Eh107Configuration<Long, String> configuration = cache.getConfiguration(Eh107Configuration.class);
configuration.unwrap(CacheConfiguration.class);
configuration.unwrap(CacheRuntimeConfiguration.class);
try {
cache.getConfiguration(CompleteConfiguration.class);
throw new AssertionError("IllegalArgumentException expected");
} catch (IllegalArgumentException iaex) {
// Expected
}
}
示例13: getCache
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Override
public <K, V> Cache<K, V> getCache(String cacheName) {
if (isClosed()) {
throw new IllegalStateException("CacheManager closed");
}
synchronized (caches) {
Cache<?, ?> cache = caches.get(cacheName);
if (cache == null) {
return null;
} else {
Configuration<?, ?> configuration = cache.getConfiguration(CompleteConfiguration.class);
Class<?> actualKeyType = configuration.getKeyType();
Class<?> actualValueType = configuration.getValueType();
if (actualKeyType.equals(Object.class)
&& actualValueType.equals(Object.class)) {
//no runtime type checking
return (Cache<K, V>) cache;
} else {
throw new IllegalArgumentException("Cache " + cacheName + " was defined with runtime type checking"
+ " as a Cache<" + actualKeyType.getName() + ", " + actualValueType.getName() + ">");
}
}
}
}
示例14: RateLimitingFilter
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
public RateLimitingFilter(JHipsterProperties jHipsterProperties) {
this.jHipsterProperties = jHipsterProperties;
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<String, GridBucketState> config =
new MutableConfiguration<String, GridBucketState>()
.setTypes(String.class, GridBucketState.class);
this.cache = cacheManager.createCache(GATEWAY_RATE_LIMITING_CACHE_NAME, config);
this.buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(cache);
}
示例15: createCache
import javax.cache.configuration.CompleteConfiguration; //导入依赖的package包/类
@Override
public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache(String cacheName, C configuration)
throws IllegalArgumentException
{
checkState();
if (cacheName == null || configuration == null)
{
throw new NullPointerException();
}
else if (!(configuration instanceof CompleteConfiguration))
{
throw new IllegalArgumentException("Invalid configuration implementation!");
}
CompleteConfiguration<K, V> completeConfiguration = (CompleteConfiguration) configuration;
validateConfiguration(completeConfiguration);
synchronized (lock)
{
if (caches.containsKey(cacheName))
{
throw new CacheException("This cache already exists!");
}
Cache<K, V> cache = new GuavaCache<>(cacheName, completeConfiguration, this);
caches.put(cacheName, cache);
return cache;
}
}