当前位置: 首页>>代码示例>>Java>>正文


Java Configuration类代码示例

本文整理汇总了Java中javax.cache.configuration.Configuration的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Configuration类属于javax.cache.configuration包,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: JCacheConfiguration

import javax.cache.configuration.Configuration; //导入依赖的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();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:JCacheConfiguration.java

示例2: testRedissonConfig

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Test
public void testRedissonConfig() throws InterruptedException, IllegalArgumentException, URISyntaxException, IOException {
    RedisProcess runner = new RedisRunner()
            .nosave()
            .randomDir()
            .port(6311)
            .run();
    
    URL configUrl = getClass().getResource("redisson-jcache.json");
    Config cfg = Config.fromJSON(configUrl);
    
    Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
    Cache<String, String> cache = Caching.getCachingProvider().getCacheManager()
            .createCache("test", config);
    
    cache.put("1", "2");
    Assert.assertEquals("2", cache.get("1"));
    
    cache.close();
    runner.stop();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:JCacheTest.java

示例3: configure

import javax.cache.configuration.Configuration; //导入依赖的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);
}
 
开发者ID:bootique-examples,项目名称:bootique-jcache-demo,代码行数:18,代码来源:Application.java

示例4: createManager

import javax.cache.configuration.Configuration; //导入依赖的package包/类
public CacheManager createManager(Map<String, Configuration<?, ?>> configs, ShutdownManager shutdownManager) {

        CachingProvider provider;
        try {
            // TODO: an explicit config property to pick explicit provider out of available choices... though probably
            // pointless in most cases (do we realistically expect multiple providers on classpath?)
            provider = Caching.getCachingProvider();
        } catch (CacheException e) {
            throw new RuntimeException("'bootique-jcache' doesn't bundle any JCache providers. " +
                    "You must place a JCache 1.0 provider on classpath explicitly.", e);
        }

        shutdownManager.addShutdownHook(provider);

        CacheManager manager = getConfigUri().map(u -> provider.getCacheManager(u, null)).orElse(provider.getCacheManager());
        shutdownManager.addShutdownHook(manager);

        // now load contributed configs
        configs.forEach(manager::createCache);

        return manager;
    }
 
开发者ID:bootique,项目名称:bootique-jcache,代码行数:23,代码来源:JCacheFactory.java

示例5: getOrCreateCacheConfiguration

import javax.cache.configuration.Configuration; //导入依赖的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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:JCacheManager.java

示例6: getConfiguration

import javax.cache.configuration.Configuration; //导入依赖的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());
}
 
开发者ID:trivago,项目名称:triava,代码行数:18,代码来源:TCacheJSR107.java

示例7: createCache

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Override
public <K, V, C extends Configuration<K, V>> javax.cache.Cache<K, V> createCache(String cacheName, C configuration)
		throws IllegalArgumentException
{
	assertNotClosed();
	
	if (cacheName == null)
	{
		throw new NullPointerException("cacheName is null"); // JSR-107 compliance
	}

	// Create a new Builder, this will copy the configuration.
	InternalBuilder<K,V> builder = new InternalBuilder<>(this, configuration);
	builder.setId(cacheName);
	Cache<K, V> tcache = builder.build();
	return tcache.jsr107cache();
}
 
开发者ID:trivago,项目名称:triava,代码行数:18,代码来源:TCacheFactory.java

示例8: getCache

import javax.cache.configuration.Configuration; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valType) {
    kernalGateway.readLock();

    try {
        Cache<K, V> cache = getCache0(cacheName);

        if (cache != null) {
            if(!keyType.isAssignableFrom(cache.getConfiguration(Configuration.class).getKeyType()))
                throw new ClassCastException();

            if(!valType.isAssignableFrom(cache.getConfiguration(Configuration.class).getValueType()))
                throw new ClassCastException();
        }

        return cache;
    }
    finally {
        kernalGateway.readUnlock();
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:22,代码来源:CacheManager.java

示例9: JCacheTemplateCache

import javax.cache.configuration.Configuration; //导入依赖的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
    }
}
 
开发者ID:kawasima,项目名称:moshas,代码行数:19,代码来源:JCacheTemplateCache.java

示例10: getCache

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Override
public <K, V> Cache<K, V> getCache(String cacheName, Class<K> keyType, Class<V> valueType) {
    checkClosed();
    if (keyType == null || valueType == null) {
        throw new NullPointerException();
    }
    if (cacheName == null) {
        throw new NullPointerException();
    }
    Cache<K, V> res = caches.get(cacheName);
    if (res == null) {
        return null;
    }
    Configuration configuration = res.getConfiguration(Configuration.class);
    if ((!keyType.equals(configuration.getKeyType()))
        || !valueType.equals(configuration.getValueType())) {
        throw new ClassCastException();
    }
    return res;
}
 
开发者ID:diennea,项目名称:blazingcache,代码行数:21,代码来源:BlazingCacheManager.java

示例11: isStoreByValue

import javax.cache.configuration.Configuration; //导入依赖的package包/类
private static <K, V> boolean isStoreByValue(Configuration<K, V> config, CacheConfiguration<K, V> ehcacheConfig) {
  if(ehcacheConfig != null) {
    Collection<ServiceConfiguration<?>> serviceConfigurations = ehcacheConfig.getServiceConfigurations();
    for (ServiceConfiguration<?> serviceConfiguration : serviceConfigurations) {
      if (serviceConfiguration instanceof DefaultCopierConfiguration) {
        DefaultCopierConfiguration<?> copierConfig = (DefaultCopierConfiguration)serviceConfiguration;
        if(copierConfig.getType().equals(DefaultCopierConfiguration.Type.VALUE)) {
          if(copierConfig.getClazz().isAssignableFrom(IdentityCopier.class)) {
            return false;
          } else {
            return true;
          }
        }
      }
    }
  }
  return config.isStoreByValue();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:19,代码来源:Eh107CompleteConfiguration.java

示例12: createCache

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Override public <K, V, C extends Configuration<K, V>> Cache<K, V> createCache( String cacheName, C configuration ) {
  Preconditions.checkState( !closed.get(), "Cache manager is closed" );
  Cache<K, V> cache = null;
  try {
    cache = newCache( cacheName, configuration );
    if ( managedCacheMap.putIfAbsent( cacheName, cache ) == null ) {
      return cache;
    } else {
      throw new CacheException( "Cache already exists: " + cacheName );
    }
  } catch ( Throwable t ) {
    if ( cache != null ) {
      cache.close();
    }
    throw Throwables.propagate( t );
  }
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:18,代码来源:AbstractCacheManager.java

示例13: getCache

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Override public <K, V> Cache<K, V> getCache( String cacheName, Class<K> keyType, Class<V> valueType ) {
  Preconditions.checkState( !closed.get(), "Cache manager is closed" );
  final Cache<?, ?> cache;
  Preconditions.checkNotNull( cacheName, "Cache Name can not be null" );
  Preconditions.checkNotNull( keyType, "Key Type can not be null" );
  Preconditions.checkNotNull( valueType, "Value Type can not be null" );

  cache = managedCacheMap.get( cacheName );
  if ( cache == null ) {
    return null;
  }

  Configuration<K, V> configuration = cache.getConfiguration( Configuration.class );
  Preconditions.checkArgument( keyType.equals( configuration.getKeyType() ), "Key Type is incompatible" );
  Preconditions.checkArgument( valueType.equals( configuration.getValueType() ), "Value Type is incompatible" );
  return (Cache<K, V>) cache;
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:18,代码来源:AbstractCacheManager.java

示例14: testCreateCache

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Test
public void testCreateCache() throws Exception {
  MutableConfiguration<String, Map> configuration = new MutableConfiguration<String, Map>();
  configuration.setTypes( String.class, Map.class );
  Cache<String, Map> cache = cacheManager.createCache( CACHE_NAME, configuration );
  assertThat( cache.getConfiguration( Configuration.class ), sameInstance( (Configuration) configuration ) );
  assertThat( cache.getName(), is( CACHE_NAME ) );
  assertThat( mockCaches, hasSize( 1 ) );

  try {
    cacheManager.createCache( CACHE_NAME, configuration );
    fail( "Exception should have been thrown" );
  } catch ( Throwable t ) {
    assertThat( t, instanceOf( CacheException.class ) );
  }

  assertThat( mockCaches, hasSize( 2 ) );
  verify( mockCaches.get( 1 ) ).close();
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:20,代码来源:AbstractCacheManagerTest.java

示例15: setUp

import javax.cache.configuration.Configuration; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  guavaCache = CacheBuilder.newBuilder().build();
  cache = new WrappedCache<Object, Object>( guavaCache ) {

    @Override public String getName() {
      return CACHE_NAME;
    }

    @Override public CacheManager getCacheManager() {
      return cacheManager;
    }

    @Override public <C extends Configuration<Object, Object>> C getConfiguration( Class<C> clazz ) {
      return Constants.unwrap( configuration, clazz );
    }
  };
}
 
开发者ID:pentaho,项目名称:pentaho-osgi-bundles,代码行数:19,代码来源:WrappedCacheTest.java


注:本文中的javax.cache.configuration.Configuration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。