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


Java ResourcePoolsBuilder类代码示例

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


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

示例1: createCache

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
private void createCache(CacheManager cacheManager, String cacheName, Duration timeToLive, boolean persistentCache) {
	ResourcePoolsBuilder resourcePoolsBuilder = ResourcePoolsBuilder.heap(100);
	if (persistentCache) {
		resourcePoolsBuilder = resourcePoolsBuilder.disk(1, MemoryUnit.MB, true);
	}
	CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
		resourcePoolsBuilder)
		.withExpiry(Expirations.timeToLiveExpiration(timeToLive))
		.build();

	for (String cache : cacheManager.getCacheNames()) {
		if (cache.equals(cacheName)) {
			log.warn("cache '{}' already exists. skipping creation", cacheName);
			return;
		}
	}

	cacheManager.createCache(cacheName, Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));
}
 
开发者ID:cronn-de,项目名称:jira-sync,代码行数:20,代码来源:JiraServiceCacheConfig.java

示例2: testTem

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Test
public void testTem() {
    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
    .withCache("preConfigured",
       CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)))
    .build();

    cacheManager.init();

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

    Cache<Long, String> myCache = cacheManager.createCache("myCache",
            CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(10)));

    myCache.put(1L, "da one!");
    myCache.putIfAbsent(0L, "ee");
    String value = myCache.get(1L);

    System.out.println("Value is " + value);
    cacheManager.removeCache("preConfigured");
    cacheManager.close();
}
 
开发者ID:compasses,项目名称:elastic-rabbitmq,代码行数:24,代码来源:TestEhcache.java

示例3: load

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
public void load(String vocabFile, float cacheSize) throws IOException {

		int size = (int) (cacheSize * createVirtualMem(vocabFile, cacheSize));

		this.mCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
				.withCache("preConfigured", CacheConfigurationBuilder
						.newCacheConfigurationBuilder(String.class, double[].class, ResourcePoolsBuilder.heap(size))
						.build())
				.build(true);

		this.mCache = mCacheManager.getCache("preConfigured", String.class, double[].class);
		this.UNK = mWEVirtualMemory.swap(mCache, size);

		if (this.UNK == null)
			throw new IOException("Vector <UNK> not found!");
	}
 
开发者ID:SI3P,项目名称:supWSD,代码行数:17,代码来源:WEMemoryManagment.java

示例4: ServerInterfaceCache

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
private ServerInterfaceCache() {
	this.cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("airports",
			CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
					ResourcePoolsBuilder.newResourcePoolsBuilder()
					.heap(10, EntryUnit.ENTRIES)
					.offheap(10, MemoryUnit.MB)) 
			)
			.build(true);
	this.airportCache = this.cacheManager.getCache("airports", String.class, String.class);
	this.airplaneCache = this.cacheManager.createCache("airplanes",
			CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, 
					ResourcePoolsBuilder.newResourcePoolsBuilder()
					.heap(10, EntryUnit.ENTRIES)
					.offheap(10, MemoryUnit.MB)).build());
	this.flightCache = this.cacheManager.createCache("flights", 
			CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, 
					ResourcePoolsBuilder.newResourcePoolsBuilder()
					.heap(10, EntryUnit.ENTRIES)
					.offheap(10, MemoryUnit.MB)).build());
}
 
开发者ID:king-jam,项目名称:cs509,代码行数:21,代码来源:ServerInterfaceCache.java

示例5: cacheManager

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Bean
public CacheManager cacheManager(@Autowired Config config) {
    long ttl = Long.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_TTL));

    double pctOfHeap = Double.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_SIZE));
    long cacheSizeMB = new Double(Runtime.getRuntime().maxMemory() * pctOfHeap / 1048576.0).longValue();

    LogFactory.getLog(getClass()).info(
            String.format("Initializing cache TTL=%d secs, size=%d MB (%.2f percent of max heap)",
                    ttl, cacheSizeMB, pctOfHeap * 100));

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Object.class, Object.class,
                    ResourcePoolsBuilder.newResourcePoolsBuilder()
                            .heap(cacheSizeMB, MemoryUnit.MB))
            .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
            .build();

    Map<String, CacheConfiguration<?, ?>> caches = new HashMap<>();
    caches.put(CACHE_DEFAULT, cacheConfiguration);

    EhcacheCachingProvider provider = (EhcacheCachingProvider) javax.cache.Caching.getCachingProvider();

    // when our cacheManager bean is re-created several times for
    // diff test configurations, this provider seems to hang on to state
    // causing cache settings to not be right. so we always close().
    provider.close();

    DefaultConfiguration configuration = new DefaultConfiguration(
            caches, provider.getDefaultClassLoader());

    return new JCacheCacheManager(
            provider.getCacheManager(provider.getDefaultURI(), configuration));
}
 
开发者ID:codeforkjeff,项目名称:conciliator,代码行数:35,代码来源:Application.java

示例6: getCache

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Override
public <K, V> Optional<Cache<K, V>> getCache(String name, Class<K> keyType, Class<V> valueType) {
	Cache<K, V> cache = null;
	Optional<CacheConfig> optionalCacheConfig = this.cacheConfigs.entrySet().stream().filter(entry -> {
		return entry.getValue().getCacheName().equals(name); }).map(entry -> { return entry.getValue(); }).findFirst();
	if (optionalCacheConfig.isPresent()) {
		org.ehcache.Cache<K, V> ehcache = this.cacheMgr.getCache(name, keyType, valueType);
		if (ehcache == null) {
			try {
				CacheConfig cacheConfig = optionalCacheConfig.get();
				Expiry<Object, Object> timeToLiveExpiration = Expirations
						.timeToLiveExpiration(new Duration((long) cacheConfig.getTtlSeconds(), TimeUnit.SECONDS));
				cache = new EhcacheCache<>(this.cacheMgr.createCache(cacheConfig.getCacheName(),
						CacheConfigurationBuilder
								.newCacheConfigurationBuilder(keyType, valueType, ResourcePoolsBuilder.heap(1000l))
								.withExpiry(timeToLiveExpiration).build()));
			} catch (Exception ex) {
				LOGGER.error("Could not get Cache with name: [{}], Exception!!", name, ex);
			}
		}
	} else {
		LOGGER.warn("CacheConfig against name [{}] doesn't exist, please create it first!", name);
	}
	return Optional.ofNullable(cache);
}
 
开发者ID:AdeptJ,项目名称:adeptj-modules,代码行数:26,代码来源:EhcacheCacheProvider.java

示例7: createInMemoryCacheManager

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
private CacheManager createInMemoryCacheManager() {
    long cacheSize = properties.getCache().getEhcache().getSize();
    long ttl = properties.getCache().getEhcache().getTimeToLiveSeconds();

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
        .newCacheConfigurationBuilder(Object.class, Object.class, ResourcePoolsBuilder
            .newResourcePoolsBuilder()
            .heap(cacheSize))
        .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
        .build();

    Map<String, org.ehcache.config.CacheConfiguration<?, ?>> caches = createCacheConfigurations(cacheConfiguration);

    EhcacheCachingProvider provider = getCachingProvider();
    DefaultConfiguration configuration = new DefaultConfiguration(caches, provider.getDefaultClassLoader());
    return provider.getCacheManager(provider.getDefaultURI(), configuration);
}
 
开发者ID:ehcache,项目名称:ehcache3-samples,代码行数:18,代码来源:CacheConfiguration.java

示例8: createRegistry

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    registry.bind(
        "myConf",
        CacheConfigurationBuilder.newCacheConfigurationBuilder(
            String.class,
            String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
                .heap(100, EntryUnit.ENTRIES)
                .offheap(1, MemoryUnit.MB))
        .build()
    );

    return registry;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:EhcacheConfigurationTest.java

示例9: EhCacheDao

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
/**
 * To initiate EhCacheDao with cacheManager and cache.
 * 
 * @param cacheName
 *            name of the cache.
 * @param cacheSize
 *            cache size.
 */
public EhCacheDao(final String cacheName, final long cacheSize) {

	setCacheManager(CacheManagerBuilder.newCacheManagerBuilder()
			.using(PooledExecutionServiceConfigurationBuilder.newPooledExecutionServiceConfigurationBuilder() 
					.defaultPool("dflt", 0, 10)
			        .pool("defaultEventPool", 1, 3)
			        .pool("cache2Pool", 2, 2)
			        .build())
			    .withDefaultEventListenersThreadPool("defaultEventPool")
			.withCache(cacheName, CacheConfigurationBuilder
					.newCacheConfigurationBuilder(Long.class, byte[].class, ResourcePoolsBuilder.heap(cacheSize))
					.build())
			.build(true));

	setCache(cacheManager.getCache(cacheName, Long.class, byte[].class));
}
 
开发者ID:debmalya,项目名称:JavaVAD,代码行数:25,代码来源:EhCacheDao.java

示例10: testUsingEhcacheConfiguration

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的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[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:24,代码来源:EhCache107ConfigurationIntegrationDocTest.java

示例11: testXAWithStatefulSerializer

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Test
public void testXAWithStatefulSerializer() throws Exception {
  BitronixTransactionManager manager = TransactionManagerServices.getTransactionManager();
  try (CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
        .using(new LookupTransactionManagerProviderConfiguration(
          BitronixTransactionManagerLookup.class))
        .withCache("xaCache",
          CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Long.class, Person.class,
              ResourcePoolsBuilder.heap(5))
            .withExpiry(ExpiryPolicyBuilder.noExpiration()).add(new XAStoreConfiguration("xaCache"))
            .build())
        .build(true)) {

    Cache<Long, Person> cache = cacheManager.getCache("xaCache", Long.class, Person.class);
    manager.begin();
    cache.put(1L, new Person("James", 42));
    manager.commit();

    manager.begin();
    assertNotNull(cache.get(1L));
    manager.commit();
  } finally {
    manager.shutdown();
  }
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:StatefulSerializerTest.java

示例12: setUp

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Before
public void setUp() {
  transactionManagerWrapper = new TransactionManagerWrapper(testTransactionManager, new NullXAResourceRegistry());
  classLoader = ClassLoader.getSystemClassLoader();
  keySerializer = new JavaSerializer<>(classLoader);
  valueSerializer = new JavaSerializer<>(classLoader);
  CopyProvider copyProvider = new DefaultCopyProvider(new DefaultCopyProviderConfiguration());
  keyCopier = copyProvider.createKeyCopier(Long.class, keySerializer);
  valueCopier = copyProvider.createValueCopier(valueClass, valueSerializer);
  Store.Configuration<Long, SoftLock<String>> onHeapConfig = new StoreConfigurationImpl<>(Long.class, valueClass,
    null, classLoader, ExpiryPolicyBuilder.noExpiration(), ResourcePoolsBuilder.newResourcePoolsBuilder()
    .heap(10, EntryUnit.ENTRIES)
    .build(),
    0, keySerializer, valueSerializer);
  testTimeSource = new TestTimeSource();
  eventDispatcher = NullStoreEventDispatcher.nullStoreEventDispatcher();
  onHeapStore = new OnHeapStore<>(onHeapConfig, testTimeSource, keyCopier, valueCopier, new NoopSizeOfEngine(), eventDispatcher);
  journal = new TransientJournal<>();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:XAStoreTest.java

示例13: evictionTest

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
public void evictionTest() {
    CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Long.class, String.class, ResourcePoolsBuilder.heap(2L))
            .withEvictionAdvisor(new OddKeysEvictionAdvisor<Long, String>()).build();

    CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
            .build(true);

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

    // Work with the cache
    cache.put(42L, "The Answer!");
    cache.put(41L, "The wrong Answer!");
    cache.put(39L, "The other wrong Answer!");

    cacheManager.close();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:18,代码来源:TestEviction.java

示例14: threeTiersCacheManager

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Test
public void threeTiersCacheManager() throws Exception {
  // tag::threeTiersCacheManager[]
  PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
    .with(CacheManagerBuilder.persistence(new File(getStoragePath(), "myData")))
    .withCache("threeTieredCache",
      CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder()
          .heap(10, EntryUnit.ENTRIES)
          .offheap(1, MemoryUnit.MB)
          .disk(20, MemoryUnit.MB, true)
      )
    ).build(true);
  // end::threeTiersCacheManager[]

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

示例15: diskSegments

import org.ehcache.config.builders.ResourcePoolsBuilder; //导入依赖的package包/类
@Test
public void diskSegments() throws Exception {
  // tag::diskSegments[]
  String storagePath = getStoragePath();
  PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
    .with(CacheManagerBuilder.persistence(new File(storagePath, "myData")))
    .withCache("less-segments",
      CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
        ResourcePoolsBuilder.newResourcePoolsBuilder().disk(10, MemoryUnit.MB))
      .add(new OffHeapDiskStoreConfiguration(2)) // <1>
    )
    .build(true);

  persistentCacheManager.close();
  // end::diskSegments[]
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:17,代码来源:Tiering.java


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