Tuesday, May 18, 2010
Steve Jobs Stanford Commencement
Friday, May 07, 2010
A Couple Minutes With Non-Stop Ehcache
- Download Ehcache 2.1
- Download the NonStopCache 1.0
- Start the Terracotta server
- run the below program (source code below)
Regular cache. No Decorator
The size of the cache is: 0
After put the size is: 1
Here are the keys:
Key:0
Done with cache.
Sleeping, Stop your server
Disconnected NonStop with noop cache.
The size of the cache is: 0
After put the size is: 0
Here are the keys:
Done with cache.
Disconnected NonStop with local reads cache.
The size of the cache is: 1
After put the size is: 1
Here are the keys:
Key:0
Done with cache.
Disconnected NonStop with exception cache.
Exception in thread "main" net.sf.ehcache.constructs.nonstop.NonStopCacheException: getKeys timed out
at net.sf.ehcache.constructs.nonstop.behavior.ExceptionOnTimeoutBehavior.getKeys(ExceptionOnTimeoutBehavior.java:114)
at net.sf.ehcache.constructs.nonstop.behavior.ClusterOfflineBehavior.getKeys(ClusterOfflineBehavior.java:120)
at net.sf.ehcache.constructs.nonstop.NonStopCache.getKeys(NonStopCache.java:264)
at MyFirstNonStopEhcacheSample.addToCacheAndPrint(MyFirstNonStopEhcacheSample.java:45)
at MyFirstNonStopEhcacheSample.(MyFirstNonStopEhcacheSample.java:40)
at MyFirstNonStopEhcacheSample.main(MyFirstNonStopEhcacheSample.java:60)
What Just Happened?
The cache is first loaded into an ordinary undecorated cache. This is performed before the server kill and proceeds without incident. The next round of operations on the cache were performed with the server down.
- These decorators are all being used on the same cache. This way you can make the behavior specific to the user of the cache. It gives tremendous flexibility.
- You'll notice this little sample flies through despite the timeout being set to 13 seconds. This is because it's in fail fast mode. In this configurable mode if the cache knows it can't communicate it will return the failure case immediately. If that's not what you want you can instead set it up to not fail fast and wait the full timeout no matter what.
- I did this work in config but the same setup can be done in code
And the Config file ehcachenonstop.xml:
Saturday, May 01, 2010
A Couple Minutes With Terracotta Toolkit Nightly
- Downloaded the nightly and unpacked
- Grabbed a quick sample app
import org.terracotta.api.ClusteringToolkit;
import org.terracotta.api.TerracottaClient;
import org.terracotta.coordination.Barrier;
public class PlayingWithExpressBarrier {
public static void main(String[] args) {
final String barrierName = args[0];
final int numberOfParties = Integer.parseInt(args[1]);
//Start the Terracotta client
ClusteringToolkit clustering = new TerracottaClient(
"localhost:9510").getToolkit();
//Get an instance of a barrier by name
Barrier barrier = clustering.getBarrier(barrierName,
numberOfParties);
try {
System.out.println("Waiting ...");
int index = barrier.await();
System.out.println("... finished " + index);
} catch (Exception e) {
e.printStackTrace();
}
}
}
- I worked in eclipse so at this point all I had to do is add the toolkit jar to the classpath to get it to compile
- Now kickoff the Terracotta server
- And run the sample 3 time