Java Code Examples for org.ehcache.config.ResourcePools

Following code examples demonstrate how to use org.ehcache.config.ResourcePools from ehcache. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.ehcache.config.ResourcePools and various code implementation of this class.
Example 1
Project : ehcache Source File : BaseCacheConfigurationTest.java View Source Code on GitHub

  public void testThrowsWithNullValueType() {
    expectedException.expect(NullPointerException.class);
    expectedException.expectMessage("valueType");

    new BaseCacheConfiguration<>(Long.class, null, null,
      null, null, mock(ResourcePools.class));
  }
			
Example 2
Project : ehcache Source File : BaseCacheConfigurationTest.java View Source Code on GitHub

  public void testThrowsWithNullKeyType() {
    expectedException.expect(NullPointerException.class);
    expectedException.expectMessage("keyType");

    new BaseCacheConfiguration<>(null, String.class, null,
      null, null, mock(ResourcePools.class));
  }
			
Example 3
Project : ehcache Source File : CacheConfigurationTest.java View Source Code on GitHub

	public void test() {

		EvictionAdvisor<K, V> evictionAdvisor = null;
		Expiry<K, V> expiry = null;
		ResourcePools resourcePools = null;
		ServiceConfiguration serviceConfigurations1 = null;
		ServiceConfiguration serviceConfigurations2 = null;

		BaseCacheConfiguration<K, V> base = new BaseCacheConfiguration<>(K.class, V.class, evictionAdvisor,
				this.getClass().getClassLoader(), expiry, resourcePools, serviceConfigurations1,
				serviceConfigurations2);
		

	}
			
Example 4
Project : ehcache Source File : CacheConfig.java View Source Code on GitHub

			public void customize(CacheManager cacheManager) {
				ResourcePools resourcePools = ResourcePoolsBuilder.newResourcePoolsBuilder()
						.heap(ON_HEAP_CACHE_SIZE_ENTRIES, EntryUnit.ENTRIES)
						.offheap(OFF_HEAP_CACHE_SIZE_MB, MemoryUnit.MB).build();

				CacheEventListenerConfigurationBuilder eventLoggerConfig = CacheEventListenerConfigurationBuilder
						.newEventListenerConfiguration(new CacheEventLogger(), EventType.CREATED, EventType.EXPIRED)
						.unordered().asynchronous();

				CacheConfiguration<?, ?> cacheConfiguration = CacheConfigurationBuilder
						.newCacheConfigurationBuilder(Long.class, BigDecimal.class, resourcePools)
						.withExpiry(ExpiryPolicyBuilder.timeToLiveExpiration(Duration.ofSeconds(CACHE_EXPIRY_SECONDS)))
						.add(eventLoggerConfig).build();

				cacheManager.createCache("squareCache",
						Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));

			}
			
Example 5
Project : ehcache Source File : EhcacheConfigurationTest.java View Source Code on GitHub

    public void testProgrammaticConfiguration() throws Exception {
        EhcacheManager manager = ehcacheConf.getManager();
        Cache<String, String> cache = manager.getCache("myCacheConf", String.class, String.class);

        ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();

        SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
        assertNotNull(h);
        assertEquals(100, h.getSize());
        assertEquals(EntryUnit.ENTRIES, h.getUnit());

        SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
        assertNotNull(o);
        assertEquals(1, o.getSize());
        assertEquals(MemoryUnit.MB, o.getUnit());
    }
			
Example 6
Project : ehcache Source File : EhCacheAdapter.java View Source Code on GitHub

    public EhCacheAdapter(EhCacheConfiguration configuration) {
        this.configuration = configuration;

        ResourcePools resourcePools = ResourcePoolsBuilder.heap(configuration.getResourcePoolSize()).build();

        ExpiryPolicy<Object, Object> expiry = ExpiryPolicyBuilder
                .timeToLiveExpiration(Duration.ofSeconds(configuration.getTimeToLiveSeconds()));

        org.ehcache.config.CacheConfiguration<String, Object> cacheConfiguration = CacheConfigurationBuilder
                .newCacheConfigurationBuilder(String.class, Object.class, resourcePools)
                .withExpiry(expiry)
                .build();

        cache = CACHE_MANAGER.createCache(configuration.getAlias(), cacheConfiguration);
    }
			
Example 7
Project : ehcache Source File : EhCache.java View Source Code on GitHub

    public EhCache(long heapEntries, long offHeapMBSize, String diskPath, long diskGBSize) {

        ResourcePools resourcePools = ResourcePoolsBuilder.newResourcePoolsBuilder()
                .heap(heapEntries, EntryUnit.ENTRIES)
                .offheap(offHeapMBSize, MemoryUnit.MB)
                .disk(diskGBSize, MemoryUnit.GB)
                .build();

        CacheConfiguration<String, Serializable> configuration = CacheConfigurationBuilder
                .newCacheConfigurationBuilder(String.class, Serializable.class, resourcePools)
                .build();

        cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
                .with(CacheManagerBuilder.persistence(diskPath))
                .withCache("cachex", configuration)
                .build(true);

        ehcache = cacheManager.getCache("cachex", String.class, Serializable.class);
    }
			
Example 8
Project : ehcache Source File : UnSupportedResourceTypeTest.java View Source Code on GitHub

  public void testUnSupportedResourceType() {
    XAStore.Provider provider = new XAStore.Provider();

    @SuppressWarnings("unchecked")
    Store.Configuration<Object, Object> configuration = mock(Store.Configuration.class);

    ResourcePools resourcePools = mock(ResourcePools.class);
    Set<ResourceType<?>> resourceTypes = new HashSet<>();
    resourceTypes.add(new TestResourceType());

    when(configuration.getResourcePools()).thenReturn(resourcePools);
    when(resourcePools.getResourceTypeSet()).thenReturn(resourceTypes);

    try {
      provider.createStore(configuration, (ServiceConfiguration<?>) null);
      fail("IllegalStateException expected");
    } catch (IllegalStateException e) {

    }

  }
			
Example 9
Project : ehcache Source File : EhcacheSpringConfigurationTest.java View Source Code on GitHub

    public void testFileConfiguration() throws Exception {
        Cache<String, String> cache = getCache(ehcacheFileConf, "myFileCacheConf");
        ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();

        SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
        assertNotNull(h);
        assertEquals(150, h.getSize());
        assertEquals(EntryUnit.ENTRIES, h.getUnit());
    }
			
Example 10
Project : ehcache Source File : EhcacheSpringConfigurationTest.java View Source Code on GitHub

    public void testProgrammaticConfiguration() throws Exception {
        Cache<String, String> cache = getCache(ehcacheConf, "myProgrammaticCacheConf");
        ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();

        SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
        assertNotNull(h);
        assertEquals(100, h.getSize());
        assertEquals(EntryUnit.ENTRIES, h.getUnit());

        SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
        assertNotNull(o);
        assertEquals(1, o.getSize());
        assertEquals(MemoryUnit.MB, o.getUnit());
    }
			
Example 11
Project : ehcache Source File : EhcacheComponentConfigurationTest.java View Source Code on GitHub

    public void testCacheManager() throws Exception {
        assertEquals(
            context().getRegistry().lookupByNameAndType("ehcache", EhcacheComponent.class).getCacheManager(),
            endpoint.getManager().getCacheManager()
        );

        Cache<String, String> cache =  endpoint.getManager().getCache("myCache", String.class, String.class);
        ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();

        SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
        assertNotNull(h);
        assertEquals(100, h.getSize());
        assertEquals(EntryUnit.ENTRIES, h.getUnit());

        SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
        assertNotNull(o);
        assertEquals(1, o.getSize());
        assertEquals(MemoryUnit.MB, o.getUnit());
    }