BigMemory 4.3.8 | Code Samples | Example: Nonstop/Rejoin
 
Example: Nonstop/Rejoin
Note:
The following description focuses on code snippets from the full code example, which is available at the /code-samples/src/ location in the installed product kit.
The nonstop feature allows certain operations to proceed on clients that have become disconnected from the cluster, and it allows operations to proceed even if they cannot complete by the nonstop timeout value. The rejoin feature then allows clients to identify a source of Terracotta configuration, so that clients can rejoin a cluster after having been either disconnected from that cluster or timed out by a Terracotta Server.
This example demonstrates the nonstop and rejoin features of BigMemory Max. After loading the configuration below, use the scripts provided to start and run the server. Then stop the server and verify that the nonstop feature is working. Start the server again and watch the rejoin feature in action.
Configuration managerConfig = new Configuration()
.terracotta(new TerracottaClientConfiguration().url("localhost:9510").rejoin(true))
.cache(new CacheConfiguration().name("nonstop-sample")
.persistence(new PersistenceConfiguration().strategy(DISTRIBUTED))
.maxBytesLocalHeap(128, MemoryUnit.MEGABYTES)
.maxBytesLocalOffHeap(1, MemoryUnit.GIGABYTES)
.terracotta(new TerracottaConfiguration()
.nonstop(new NonstopConfiguration()
.immediateTimeout(false)
.timeoutMillis(10000).enabled(true)
)
));
CacheManager manager = CacheManager.create(managerConfig);
Ehcache bigMemory = manager.getEhcache("nonstop-sample");
try {
System.out.println("**** Put key 1 / value timDoe. ****");
final Person timDoe = new Person("Tim Doe", 35, Person.Gender.MALE,
"eck street", "San Mateo", "CA");
bigMemory.put(new Element("1", timDoe));
System.out.println("**** Get key 1 / value timDoe. ****");
System.out.println(bigMemory.get("1"));
waitForInput();
System.out
.println("**** Now you have to kill the server using the
stop-sample-server.bat on Windows or stop-sample-server.sh otherwise ****");
try {
while (true) {
bigMemory.get("1");
}
} catch (NonStopCacheException e) {
System.out
.println("**** Server is unreachable - NonStopException received when trying
to do a get on the server. NonStop is working ****");
}
System.out
.println("**** Now you have to restart the server using the start-sample-server.bat
on Windows or start-sample-server.sh otherwise ****");
boolean serverStart = false;
while (serverStart == false) {
try {
bigMemory.get("1");
//if server is unreachable, exception is thrown when doing the get
serverStart = true;
} catch (NonStopCacheException e) {
}
}
System.out
.println("**** Server is reachable - No More NonStopException received when
trying to do a get on the server. Rejoin is working ****");
} finally
{
if (manager != null) manager.shutdown();
}