Tuesday, February 28, 2012

A Java cache for OSB


ConcurrentHashMap is a Thread-safe implementation of a HashMap, optimized for concurrent reads and writes scenario.

You can expose a ConcurrentHashMap as a Static attribute of a Java Bean, accessed by OSB Message Flow via Java Callout or Custom XPath.

cache (the individual cache) is a HashMap - where String is the Object Key (e.g. the userId), and XmlObject is the corresponging cached response (e.g. the User object). A Cache will contain homogeneous objects (XmlObject of the same type).

caches (collection of cache) is a HashMap, where String is the Cache Name (e.g. "USERS")

caches.get("USERS").get("1234") will return the XmlObject describing user 1234

caches.clear() will remove all caches
caches.get("USERS").clear() will clear an individual cache

Caches can be cleared with a REST Proxy Service http://myhost:myport/CacheService/ClearCache/USERS
One can use a cron job with a wget command to clear them periodically

One can add metainformation to a Cache, such as the creation time, the last update time, the last access time...

One can expose management of the Caches via JMX (registering the MBeanAgent into the Weblogic or JVM MBean tree), and administering via JConsole or any other JMX-Enabled tool.

The advantage of storing an XmlObject in cache is that it doesn't require conversion inside OSB, since OSB stores complex variables in XmlObject format.
In Coherence the object would be stored in POF format - requiring further materialization to XmlObject format

No comments: