geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xasima Xirohata" <>
Subject Re: POJO caching in geronimo
Date Wed, 07 May 2008 13:07:55 GMT
Hello, Gianny.  I have developed a very simple codebase to install POJO
through GBean. It just exposes only java.util.Map as interface and uses
HashMap as implementation. It's mainly the yet another example on writing
gbean than clear implementation of the pluggable cache. I will put the basic
code here (if someone will decide to do the same ) and  I will provide some
ideas to enhance this and ask some question in the next letter.

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoBuilder;
import org.apache.geronimo.gbean.GBeanLifecycle;

 * POJO Cache GBean
public class POJOCacheGBean extends HashMap  implements GBeanLifecycle, Map

  private static final long serialVersionUID = 1L;
  private static final GBeanInfo GBEAN_INFO;
  //TODO[CORE] figure out an actual object name
  private  String objectName = "CacheGBean";
  private String message;

  private static final Log log = LogFactory.getLog(POJOCacheGBean.class);

  /* --------------- GERONIMO KERNEL REGISTRATION ----------------- */

  static {
    GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder(POJOCacheGBean.class
        .getName(), POJOCacheGBean.class);

    Method[] methods = HashMap.class.getMethods();
    Iterator it = Arrays.asList(methods).iterator();
    while(it.hasNext()) {
      Method m = (Method);
      infoBuilder.addOperation(m.getName(), m.getParameterTypes(),

    infoBuilder.addAttribute("message", String.class.getName(), true);

    GBEAN_INFO = infoBuilder.getBeanInfo();

  public static GBeanInfo getGBeanInfo() {
    return GBEAN_INFO;

  public POJOCacheGBean(String message){
    this.message = message;
  public POJOCacheGBean() {


  /* --------------- / GERONIMO KERNEL REGISTRATION ----------------- */

  /* --------------- EXPOSED API -------------------- */
  public String toString() {
    return "GBEAN cache";
  public String getMessage() {
    return message;

  /* --------------- / EXPOSED API ------------------ */

  /* --------------- GERONIMO life cycle -------------- */
  public void doFail() { + "failed");


  public void doStart() throws Exception {"Starting " + objectName);

  public void doStop() throws Exception {"Stopping " + objectName);

  /* --------------- / GERONIMO life cycle ------------- */


w-cache-gbean.xml  (Deployment Plan)
<module xmlns="">

  <gbean name="POJOCache"
    <attribute name="message">configuration value</attribute>

pom.xml (Project description in terms of maven)
<?xml version="1.0" encoding="UTF-8"?>





======================== GERONIMO POJO cache gbean =========================
     @name GERONIMO POJO Cache GBEAN
     @date 1 May 2008
     @modification  {
         @date(1 May 2008) created
     @component core-geronimo-services-test


This gbean provide the POJO cache functionality based on simple
java.util.hashmap. It seems to
very easy switch the implementation to the more enhanced like EHCACHE and

If you use eclipse do the following
1. Do right click on the project and choose MAVEN -> RUN -> Package...
You need to get  test-gbean-1.0.jar at the end of the process in the /target

2. We suppose that you use geronimo-2.1, so go to
choose the  /target/test-gbean-1.0.jar as Archive and the
/target/w-cache-gbean.xml as the plan.
Check 'start app' and press install
You will get this GBEAN installed into geronimo as service successfully.

3. To ensure if everything is ok, just follow the link
You have to find an
component in running state.

4. If you need to play and test the gbean a little bit more just go to
Choose ServiceModuleMBEANS and you find  configuration gbean in the
list. Expand this item and go to the gbean at its own. If you will choose
'operation' tab you will found all exposed operation and can play with them

5. To use the gbean from your application (for example, in WAR)  you need to
place the following into geronimo-web.xml deployment plan
<web-app xmlns=""


And get the cache in the following manner

  cache = (Map<String, Template>) new InitialContext()


On Thu, May 1, 2008 at 6:22 AM, Gianny Damour <>

> Hello Xasima,
> WADI does not yet provide a POJO caching solution.
> Regarding the
> class, AFAIK it was more an idea than an actual fully working caching
> implementation.
> I know that a Geronimo POJO caching solution, GCache, was implemented a
> while back in the geronimo-sandbox and documented here http://
> However, as
> this caching solution has not been touched for a while, I do not think it is
> in a working state.
> The approach you are taking seems to me reasonable and I think it would be
> quite useful for other users to have such GBean services for JCS or EHCache.
> FYI, I am currently working on the implementation of a hierarchical,
> transactional, distributed, partitioned and replicated cache and data-grid
> solution as part of WADI. I hope to have a working solution at the end of
> the month and hopefully before you having the need for it :)
> Thanks,
> Gianny
> On 01/05/2008, at 2:22 AM, Xasima Xirohata wrote:
>  Hi. I want to figure out what is the proper strategy to plug-in POJO
> > cache into geronimo (2.1).
> > I want to use the different implementation of caching (HashMap,
> >  EHCACHE, JCS) and work in standalone mode  (not explicit clustering support
> > for the first time).
> >
> > In the existed code we just want to get a cache instance using JNDI,
> > cast this to java.util.Map and  invoke plain put/get methods.
> > I have explored geronimo docs and found the following possibilities:
> >    1) use the terracotta (
> > that exposes such an wrapper around different implementation.
> >    2) use the wadi and the
> > class somehow
> >    3) use the custom gbean as wrapper upon different implementation of
> > caching (as the general solution for any separate custom services).
> >
> > Unfortunately, the 70Mb size of Terracotta seems too heavy to use for
> > such a use case when I don't plan to work with clustering at once.
> > I don't found a page to integrate this options with WADI, please provide
> > some details on this..
> > So I have stopped with the last way. I think that having POJO cache
> > exposed as gbean (instead of using as regular embedded jar) is a right
> > strategy since it is quite naturally to
> >    1) implement initializing, clearing, storing (if persistence is on)
> > of POJO cache when the correspondent geronimo lifecycle events occur
> >    2) providing different <attribute > </attribute> in the gbean plan
> > configure in external manner different  POJO cache parameters
> >    3) having MBean that reports on state and loads of the cache ( it may
> > be interesting how  much objects are consumes from this and if we need to
> > change expiration policy or allocate more size)
> >
> > Am I right with the approach? Do you have any predefined gbeans (or
> > prototype in sandbox code area) code for this?
> > Could I use WADI for this purpose?
> > --
> > Best regards,
> > ~ Xasima Xirohata ~
> >

Best regards,
~ Xasima Xirohata ~

View raw message