Terracotta Ehcache 10.7 | Ehcache API Developer Guide | Clustered Caches | Creating a Cluster with Multiple Stripes
 
Creating a Cluster with Multiple Stripes
Server-side tasks for setting up a Multi-Stripe Cluster
*Before you create a cluster, start at least one server on each of the stripes which are going to be part of the cluster.
*Use the activate command of the config toolto make the cluster ready for client operations.
For more details about usage of the config tool, refer to the section Config Tool in the Terracotta Server Administration Guide.
Client Side Code
The client-side code for connecting to a cluster will be similar to the following:

PersistentCacheManager cacheManager =
CacheManagerBuilder.newCacheManagerBuilder()
.with(ClusteringServiceConfigurationBuilder.cluster(URI.create(
"terracotta://localhost:9410/multi-stripe-cm")).autoCreate()) // 1
.withCache("myCache", CacheConfigurationBuilder.newCacheConfigurationBuilder(
Long.class, String.class, ResourcePoolsBuilder.heap(10)
.with(ClusteredResourcePoolBuilder.clusteredDedicated(
"primary-server-resource", 10, MemoryUnit.MB)))) // 2
.build(true);

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

myCache.put(42L, "Success!");
System.out.println(myCache.get(42L));
1
Connection to a multi-stripe cluster requires a URI with the host:port of all servers that belong to one of the stripes.
2
The size of the resource pool on each stripe is the total pool size divided by the numbers of stripes in the cluster.
Note: 
*It's recommended to check the availability of resources across all stripes in the cluster before configuring a cache, otherwise cache creation will fail on the stripes with insufficient resources.
*Creating cluster with cluster tool is a mandatory first step, otherwise cache creation will succeed on only one of the stripes represented by the provided URI. Creating a cluster after creating clustered resources is not supported and will result in errors.