Monday, May 18, 2009

Great Movie - Crash (2004)

LINK http://www.imdb.com/title/tt0375679/

Wednesday, March 25, 2009

Random Notes on JBOSS Cache

JBOSS Cache Notes:

http://www.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.3.0.cp04/html/Tree_Cache_Guide/index.html

http://www.redhat.com/docs/en-US/JBoss_Enterprise_Application_Platform/4.3.0.cp04/pdf/Cache_Frequently_Asked_Questions/JBoss_Cache_Frequently_Asked_Questions_CP04.pdf

TreeCache Example:
TreeCache tree = new TreeCache();
tree.setClusterName("demo-cluster");
tree.setClusterProperties("default.xml"); // uses defaults if not provided
tree.setCacheMode(TreeCache.REPL_SYNC);
tree.createService(); // not necessary, but is same as MBean lifecycle
tree.startService(); // kick start tree cache
tree.put("/a/b/c", "name", "Ben");
tree.put("/a/b/c/d", "uid", new Integer(322649));
Integer tmp = (Integer) tree.get("/a/b/c/d", "uid");
tree.remove("/a/b");
tree.stopService();
tree.destroyService(); // not necessary, but is same as MBean lifecycle


TreeCache requires that all keys and node be Serializable. Where this is not a requirement with a PojoCache.

PojoCache extends the functionality of the TreeCache.

JBOSS Cache Websites:
- http://www.jboss.org/jbosscache/
- http://www.jboss.org/wiki/Wiki.jsp?page=CVSRepository

JBoss Cache Version Check:
- java -jar jboss-cache.jar org.jboss.cache.Version

JBoos cache uses JGroups under the covers.

JBossCache has five different cache modes,
- LOCAL - single instance, it will not attempt to replicate anything.
- REPL_SYNC - replicate synchronous between the different cache instances.
- REPL_AYSNC - asynchronous replication betweencache instances.

In the event of a network crash REPL_SYNC will return an error, where REPL_ASYNC will continue to work (However the cache will be out of sync.)
Asynchronous replication is faster (no caller blocking)

ClusterConfig is the attribute where the cluster name is defined. Once a server joins the cluster every change is replicated.

Buddy Replication allows each node to pick one or more 'buddies' in the cluster and only replicate to its buddies. (As of, JBoss Cache 1.4.0)

JBoss Cache is Thread safe.

JBoss Cache allows for presistance and passivation/overflow to a data store.
- Cache Passivation is the process of removing an object from in-memory cache and writing it to a secondary data store (e.g., file system, database) on eviction.


IsolationLevel controls the cache locking.
- NONE
- READ_UNCOMMITTED
- READ_COMMITTED
- REPEATABLE_READ
- SERIALIZABLE

JBoss TreeCache allows for event notification pre and post.

POJOCache uses twice as much memory. Not a good option if running a local cache or not persisting.


Concurrent Access:
JBoss Cache uses a pessimistic locking scheme by default to prevent concurrent access to the same data. Optimistic locking may alternatively be used.


example of how to use JBoss Cache in a standalone (i.e. outside an application server) fashion with dummy transactions:
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.cache.transaction.DummyContextFactory");
User Transaction tx=(UserTransaction)new InitialContext(prop).lookup("UserTransaction");
TreeCache tree = new TreeCache();
PropertyConfigurator config = new PropertyConfigurator();
config.configure(tree, "META-INF/replSync-service.xml");
tree.createService(); // not necessary
tree.startService(); // kick start tree cache

try {
tx.begin();
tree.put("/classes/cs-101", "description", "the basics");
tree.put("/classes/cs-101", "teacher", "Ben");
tx.commit();
}
catch(Throwable ex) {
try { tx.rollback(); } catch(Throwable t) {}
}



Eviction Policies:
- TreeCache
- org.jboss.cache.eviction.LFUPolicy - Least Frequently Used removed
- org.jboss.cache.eviction.FIFOPolicy - First in First out removed
- org.jboss.cache.eviction.MRUPolicy - Most recently used removed (Why would anyone use this?)
- POJOCache
- org.jboss.cache.aop.eviction.AopLRUPolicy
- ...

Eviction policies can be global or per region.

OOM (OutOfMemoryException) this can be adjusted by modifying the EvictionPolicyConfig attributes.
- wakeUpIntervalInSeconds
- timeToLiveInSeconds
- maxNodes
- region



CacheLoaders are available to store and retrieve data.
- Used to preload a cache.
- Custom CacheLoaders are created by implementing the org.jboss.cache.loader.CacheLoader class.
- There are a few predefined classloaders




JBoss Cache is managed and monitored through the jconsole.