Terracotta Ehcache 10.2 | Ehcache API Developer Guide | Fast Restartability | Example of a Restartability Scenario
 
Example of a Restartability Scenario
The following example illustrates a typical scenario of a CacheManager containing a mix of restartable and non-restartable caches.

EnterpriseServerSideConfigurationBuilder serverSideConfigBuilder =
EnterpriseClusteringServiceConfigurationBuilder
.enterpriseCluster(connectionURI)
.autoCreate()
.defaultServerResource("primary-server-resource")
.resourcePool("shared-pool", 20, MemoryUnit.MB,
"secondary-server-resource") // 1
.restartable("data-directory-name");

PersistentCacheManager cacheManager = CacheManagerBuilder
.newCacheManagerBuilder()
.with(serverSideConfigBuilder)
.build(true);

ClusteredResourcePool restartableDedicatedPool =
ClusteredRestartableResourcePoolBuilder
.clusteredRestartableDedicated(
"primary-server-resource", 4, MemoryUnit.MB);

ClusteredResourcePool restartableSharedPool =
ClusteredRestartableResourcePoolBuilder
.clusteredRestartableShared("shared-pool");

ClusteredResourcePool nonRestartableDedicatedPool =
ClusteredResourcePoolBuilder
.clusteredDedicated(
"primary-server-resource", 8, MemoryUnit.MB); // 2

ClusteredResourcePool nonRestartableSharedPool =
ClusteredResourcePoolBuilder
.clusteredShared("shared-pool"); // 3

Cache<Long, String> restartableDedicatedPoolCache = cacheManager
.createCache("restartableDedicatedPoolCache",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(restartableDedicatedPool))); // 4

Cache<Long, String> restartableSharedPoolCache = cacheManager
.createCache("restartableSharedPoolCache",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(restartableSharedPool))); // 5

Cache<String, Boolean> nonRestartableDedicatedPoolCache = cacheManager
.createCache("nonRestartableDedicatedPoolCache",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, Boolean.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(nonRestartableDedicatedPool))); // 6

Cache<String, Boolean> nonRestartableSharedPoolCache = cacheManager
.createCache("nonRestartableSharedPoolCache",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(String.class, Boolean.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(nonRestartableSharedPool))); // 7

cacheManager.close();
cacheManager.destroy();
1
Registers with the CacheManager a resource pool named shared-pool of size 20 MB, reserved from server's secondary-server-resource.
2
Creates a non-restartable dedicated resource pool of size 8 MB from server's primary-server-resource.
3
Specifies a non-restartable shared resource pool which could be used by multiple caches.
4
Creates a Cache using a restartable dedicated pool.
5
Creates a Cache using a restartable shared pool.
6
Creates a Cache using the non-restartable dedicated pool created in Step 2 above.
7
Creates a Cache using the non-restartable shared pool created in Step 3 above. Note here that the same pool is shared by restartable and non-restartable caches.

Copyright © 2010-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Innovation Release