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


Java Configuration类代码示例

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


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

示例1: main

import org.ehcache.config.Configuration; //导入依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating cache manager via XML resource");
  Configuration xmlConfig = new XmlConfiguration(BasicXML.class.getResource("/ehcache.xml"));
  try (CacheManager cacheManager = newCacheManager(xmlConfig)) {
    cacheManager.init();

    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);

    LOGGER.info("Putting to cache");
    basicCache.put(1L, "da one!");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:BasicXML.java

示例2: main

import org.ehcache.config.Configuration; //导入依赖的package包/类
public static void main(String[] args) {
  LOGGER.info("Creating clustered cache manager from XML");
  final URL myUrl = ClusteredXML.class.getResource("/ehcache.xml");
  Configuration xmlConfig = new XmlConfiguration(myUrl);
  try (CacheManager cacheManager = newCacheManager(xmlConfig)) {
    cacheManager.init();
    
    Cache<Long, String> basicCache = cacheManager.getCache("basicCache", Long.class, String.class);
    
    LOGGER.info("Getting from cache");
    String value = basicCache.get(1L);
    LOGGER.info("Retrieved '{}'", value);

    LOGGER.info("Closing cache manager");
  }

  LOGGER.info("Exiting");
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:19,代码来源:ClusteredXML.java

示例3: testSerializers

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testSerializers() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/default-serializer.xml"));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();

  Cache<Long, Double> bar = cacheManager.getCache("bar", Long.class, Double.class);
  bar.put(1L, 1.0);
  assertThat(bar.get(1L), equalTo(1.0));

  Cache<String, String> baz = cacheManager.getCache("baz", String.class, String.class);
  baz.put("1", "one");
  assertThat(baz.get("1"), equalTo("one"));

  Cache<String, Object> bam = cacheManager.createCache("bam", newCacheConfigurationBuilder(String.class, Object.class, heap(10)).build());
  bam.put("1", "one");
  assertThat(bam.get("1"), equalTo((Object)"one"));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例4: testCopiers

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testCopiers() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/cache-copiers.xml"));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();

  Cache<Description, Person> bar = cacheManager.getCache("bar", Description.class, Person.class);
  Description desc = new Description(1234, "foo");
  Person person = new Person("Bar", 24);
  bar.put(desc, person);
  assertEquals(person, bar.get(desc));
  assertNotSame(person, bar.get(desc));

  Cache<Long, Person> baz = cacheManager.getCache("baz", Long.class, Person.class);
  baz.put(1L, person);
  assertEquals(person, baz.get(1L));
  assertNotSame(person, baz.get(1L));

  Employee empl = new Employee(1234, "foo", 23);
  Cache<Long, Employee> bak = cacheManager.getCache("bak", Long.class, Employee.class);
  bak.put(1L, empl);
  assertSame(empl, bak.get(1L));
  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:IntegrationConfigurationTest.java

示例5: testLoaderWriter

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testLoaderWriter() throws ClassNotFoundException, SAXException, InstantiationException,
    IOException, IllegalAccessException {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/cache-integration.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  assertThat(cache, notNullValue());
  assertThat(cache.get(1), notNullValue());
  final Number key = new Long(42);
  cache.put(key, "Bye y'all!");
  assertThat(TestCacheLoaderWriter.lastWrittenKey, is(key));

  assertThat(configuration.getCacheConfigurations().containsKey("template1"), is(true));
  final Cache<Number, String> templateCache = cacheManager.getCache("template1", Number.class, String.class);
  assertThat(templateCache, notNullValue());
  assertThat(templateCache.get(1), notNullValue());
  final Number key1 = new Long(100);
  templateCache.put(key1, "Bye y'all!");
  assertThat(TestCacheLoaderWriter.lastWrittenKey, is(key1));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:IntegrationConfigurationTest.java

示例6: testCacheEventListener

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testCacheEventListener() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-cacheEventListener.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  cache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.CREATED));
  cache.put(10, "cat");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
  cache.remove(10);
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.REMOVED));
  cache.put(10, "dog");
  resetValues();
  assertThat(configuration.getCacheConfigurations().containsKey("template1"), is(true));
  final Cache<Number, String> templateCache = cacheManager.getCache("template1", Number.class, String.class);
  templateCache.put(10,"cat");
  assertThat(TestCacheEventListener.FIRED_EVENT, nullValue());
  templateCache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:23,代码来源:IntegrationConfigurationTest.java

示例7: testCacheEventListenerWithMultipleListener

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testCacheEventListenerWithMultipleListener() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/ehcache-multipleCacheEventListener.xml"));
  assertThat(configuration.getCacheConfigurations().containsKey("bar"), is(true));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  final Cache<Number, String> cache = cacheManager.getCache("bar", Number.class, String.class);
  resetValues();
  cache.put(10, "dog");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.CREATED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT, is(nullValue()));
  resetValues();
  cache.put(10, "cat");
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.UPDATED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT.getType(), is(EventType.UPDATED));
  resetValues();
  cache.remove(10);
  assertThat(TestCacheEventListener.FIRED_EVENT.getType(), is(EventType.REMOVED));
  assertThat(TestSecondCacheEventListener.SECOND_LISTENER_FIRED_EVENT.getType(), is(EventType.REMOVED));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例8: testThreadPools

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testThreadPools() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/thread-pools.xml"));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  try {
    Cache<String, String> cache = cacheManager.createCache("testThreadPools", newCacheConfigurationBuilder(String.class, String.class, heap(10))
            .add(new DefaultCacheLoaderWriterConfiguration(ThreadRememberingLoaderWriter.class))
            .add(newUnBatchedWriteBehindConfiguration().useThreadPool("small"))
            .build());

    cache.put("foo", "bar");

    ThreadRememberingLoaderWriter.USED.acquireUninterruptibly();

    assertThat(ThreadRememberingLoaderWriter.LAST_SEEN_THREAD.getName(), containsString("[small]"));
  } finally {
    cacheManager.close();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例9: testThreadPoolsUsingDefaultPool

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testThreadPoolsUsingDefaultPool() throws Exception {
  Configuration configuration = new XmlConfiguration(this.getClass().getResource("/configs/thread-pools.xml"));
  final CacheManager cacheManager = CacheManagerBuilder.newCacheManager(configuration);
  cacheManager.init();
  try {
    Cache<String, String> cache = cacheManager.createCache("testThreadPools", newCacheConfigurationBuilder(String.class, String.class, heap(10))
            .add(new DefaultCacheLoaderWriterConfiguration(ThreadRememberingLoaderWriter.class))
            .add(newUnBatchedWriteBehindConfiguration())
            .build());

    cache.put("foo", "bar");

    ThreadRememberingLoaderWriter.USED.acquireUninterruptibly();

    assertThat(ThreadRememberingLoaderWriter.LAST_SEEN_THREAD.getName(), containsString("[big]"));
  } finally {
    cacheManager.close();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:IntegrationConfigurationTest.java

示例10: createCacheManager

import org.ehcache.config.Configuration; //导入依赖的package包/类
private Eh107CacheManager createCacheManager(URI uri, Configuration config, Properties properties) {
  Eh107CacheLoaderWriterProvider cacheLoaderWriterFactory = new Eh107CacheLoaderWriterProvider();

  Object[] serviceCreationConfigurations = config.getServiceCreationConfigurations().toArray();

  Jsr107Service jsr107Service = new DefaultJsr107Service(ServiceUtils.findSingletonAmongst(Jsr107Configuration.class, serviceCreationConfigurations));

  Collection<Service> services = new ArrayList<>(4);
  services.add(cacheLoaderWriterFactory);
  services.add(jsr107Service);

  if (ServiceUtils.findSingletonAmongst(DefaultSerializationProviderConfiguration.class, serviceCreationConfigurations) == null) {
    services.add(new DefaultJsr107SerializationProvider());
  }

  Eh107InternalCacheManager ehcacheManager = new Eh107InternalCacheManager(config, services, !jsr107Service.jsr107CompliantAtomics());
  ehcacheManager.init();

  return new Eh107CacheManager(this, ehcacheManager, properties, config.getClassLoader(), uri,
          new ConfigurationMerger(config, jsr107Service, cacheLoaderWriterFactory));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:EhcacheCachingProvider.java

示例11: testDoesNotifyAboutCache

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testDoesNotifyAboutCache() {
  final CacheConfiguration<Object, Object> cacheConfiguration = new BaseCacheConfiguration<>(Object.class, Object.class, null, null, null, ResourcePoolsHelper
    .createHeapOnlyPools());
  final Store.Provider mock = mock(Store.Provider.class);
  when(mock.rank(any(Set.class), any(Collection.class))).thenReturn(1);

  final CacheEventDispatcherFactory cenlProvider = mock(CacheEventDispatcherFactory.class);
  final CacheEventDispatcher<Object, Object> cenlServiceMock = mock(CacheEventDispatcher.class);
  when(cenlProvider.createCacheEventDispatcher(any(Store.class))).thenReturn(cenlServiceMock);

  final Collection<Service> services = getServices(mock, cenlProvider);
  when(mock.createStore(ArgumentMatchers.<Store.Configuration>any())).thenReturn(mock(Store.class));
  Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
  DefaultConfiguration config = new DefaultConfiguration(caches, null);
  EhcacheManager cacheManager = new EhcacheManager(config, services);
  final CacheManagerListener listener = mock(CacheManagerListener.class);
  cacheManager.registerListener(listener);
  cacheManager.init();
  final String cacheAlias = "bar";
  cacheManager.createCache(cacheAlias, cacheConfiguration);
  final Cache<Object, Object> bar = cacheManager.getCache(cacheAlias, Object.class, Object.class);
  verify(listener).cacheAdded(cacheAlias, bar);
  cacheManager.removeCache(cacheAlias);
  verify(listener).cacheRemoved(cacheAlias, bar);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:EhcacheManagerTest.java

示例12: testDoesNotNotifyAboutCacheOnInitOrClose

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testDoesNotNotifyAboutCacheOnInitOrClose() {
  final CacheConfiguration<Object, Object> cacheConfiguration = new BaseCacheConfiguration<>(Object.class, Object.class, null, null, null, ResourcePoolsHelper
    .createHeapOnlyPools());
  final Store.Provider mock = mock(Store.Provider.class);
  when(mock.rank(any(Set.class), any(Collection.class))).thenReturn(1);

  final CacheEventDispatcherFactory cenlProvider = mock(CacheEventDispatcherFactory.class);
  final CacheEventDispatcher<Object, Object> cenlServiceMock = mock(CacheEventDispatcher.class);
  when(cenlProvider.createCacheEventDispatcher(any(Store.class))).thenReturn(cenlServiceMock);

  final Collection<Service> services = getServices(mock, cenlProvider);
  when(mock.createStore(ArgumentMatchers.<Store.Configuration>any())).thenReturn(mock(Store.class));
  final String cacheAlias = "bar";
  Map<String, CacheConfiguration<?, ?>> caches = newCacheMap();
  caches.put(cacheAlias, cacheConfiguration);
  DefaultConfiguration config = new DefaultConfiguration(caches, null);
  EhcacheManager cacheManager = new EhcacheManager(config, services);
  final CacheManagerListener listener = mock(CacheManagerListener.class);
  cacheManager.registerListener(listener);
  cacheManager.init();
  final Cache<Object, Object> bar = cacheManager.getCache(cacheAlias, Object.class, Object.class);
  verify(listener, never()).cacheAdded(cacheAlias, bar);
  cacheManager.close();
  verify(listener, never()).cacheRemoved(cacheAlias, bar);
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:EhcacheManagerTest.java

示例13: doPreSetup

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Override
protected void doPreSetup() throws Exception {
    final URL url = this.getClass().getResource(EHCACHE_CONFIG);
    final Configuration xmlConfig = new XmlConfiguration(url);

    cacheManager = CacheManagerBuilder.newCacheManager(xmlConfig);
    cacheManager.init();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:EhcacheTestSupport.java

示例14: testOneServiceConfig

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testOneServiceConfig() throws Exception {
  Configuration config = new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/one-service.xml"));

  assertThat(config.getServiceCreationConfigurations(), IsCollectionContaining.<ServiceCreationConfiguration<?>>hasItem(instanceOf(BarConfiguration.class)));
  assertThat(config.getCacheConfigurations().keySet(), hasSize(0));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:8,代码来源:XmlConfigurationTest.java

示例15: testOneCacheConfig

import org.ehcache.config.Configuration; //导入依赖的package包/类
@Test
public void testOneCacheConfig() throws Exception {
  Configuration config = new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/one-cache.xml"));

  assertThat(config.getServiceCreationConfigurations(), hasSize(0));
  assertThat(config.getCacheConfigurations().keySet(), hasItem("bar"));
  assertThat(config.getCacheConfigurations().get("bar").getServiceConfigurations(), IsCollectionContaining.<ServiceConfiguration<?>>hasItem(instanceOf(FooConfiguration.class)));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:9,代码来源:XmlConfigurationTest.java


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