Ehcache Cluster Tier Manager Lifecycle
When configuring a cache manager to connect to a cluster tier manager there are three possible connection modes:
CacheManagerBuilder<PersistentCacheManager> autoCreate = CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
.autoCreate(server -> server //1
.resourcePool("resource-pool", 8, MemoryUnit.MB, "primary-server-resource")))
.withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));
CacheManagerBuilder<PersistentCacheManager> autoCreateOnReconnect = CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
.autoCreateOnReconnect(server -> server //2
.resourcePool("resource-pool", 8, MemoryUnit.MB, "primary-server-resource")))
.withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));
CacheManagerBuilder<PersistentCacheManager> expecting = CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))
.expecting(server -> server //3
.resourcePool("resource-pool", 8, MemoryUnit.MB, "primary-server-resource")))
.withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));
CacheManagerBuilder<PersistentCacheManager> configless = CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create("terracotta://localhost/my-application"))) //4
.withCache("clustered-cache", CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.with(ClusteredResourcePoolBuilder.clusteredShared("resource-pool"))));
1 | In auto-create mode, if no cluster tier manager exists, then one is created with the supplied configuration. If it exists, and its configuration matches the supplied configuration, then a connection is established. If the supplied configuration does not match, then the cache manager will fail to initialize. |
2 | In auto create on reconnect mode, we additionally support auto creation of any necessary entities when reconnecting to a cluster. This behavior is useful in a non-persistent cluster in case the cluster loses its state due to a restart (planned or accidental). |
3 | In expected mode if a cluster tier manager exists, and its configuration matches the supplied configuration, then a connection is established. If the supplied configuration does not match, or the cluster tier manager does not exist, then the cache manager will fail to initialize. |
4 | In config-less mode, if a cluster tier manager exists, then a connection is established without regard to its configuration. If it does not exist, then the cache manager will fail to initialize. |