geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Xasima Xirohata" <xas...@gmail.com>
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.

POJOCacheGBean.java
----------------------
package com.w.geronimo.services.test.gbean;

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)it.next();
      infoBuilder.addOperation(m.getName(), m.getParameterTypes(),
m.getReturnType().getName());
    }
    infoBuilder.addInterface(Map.class);

    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() {
    log.info(objectName + "failed");


  }

  public void doStart() throws Exception {
    log.info("Starting " + objectName);
  }

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

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

}

w-cache-gbean.xml  (Deployment Plan)
----------------------
<module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1">
  <environment>
    <moduleId>
      <groupId>com.w.core.geronimo.services</groupId>
      <artifactId>pojo-cache</artifactId>
      <version>1.0</version>
      <type>car</type>
    </moduleId>
    <dependencies></dependencies>
  </environment>

  <gbean name="POJOCache"
class="com.w.geronimo.services.test.gbean.POJOCacheGBean">
    <attribute name="message">configuration value</attribute>
  </gbean>
</module>

pom.xml (Project description in terms of maven)
--------------------------
<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>w-core-geronimo-services</groupId>
  <artifactId>test-gbean</artifactId>
  <name></name>
  <version>1.0</version>
  <description></description>
  <dependencies>
    <dependency>
      <groupId>org.apache.geronimo.framework</groupId>
      <artifactId>geronimo-kernel</artifactId>
      <version>2.1</version>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.3</version>
    </dependency>

    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.0.4</version>
    </dependency>
  </dependencies>

</project>


readme
--------------------------

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


DESCRIPTION
----------

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
JCS.

TEST
----------
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
directory

2. We suppose that you use geronimo-2.1, so go to
http://localhost:8080/console/portal/Applications/Deploy%20New
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
http://localhost:8080/console/portal/Applications/System%20Modules
You have to find an com.w.core.geronimo.services/pojo-cache/1.0/car
component in running state.

4. If you need to play and test the gbean a little bit more just go to
http://localhost:8080/console/portal/Debug%20Views/JMX%20Viewer
Choose ServiceModuleMBEANS and you find
com.w.core.geronimo.services/pojo-cache/1.0/car  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="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
  xmlns:security="http://geronimo.apache.org/xml/ns/security-2.0">
  <environment
    xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.2">
    ....
      <dependencies>
      <dependency>
        <groupId>com.w.core.geronimo.services</groupId>
        <artifactId>pojo-cache</artifactId>
        <version>1.0</version>
        <type>car</type>
      </dependency>
    </dependencies>

    ...
    </environment>
    <gbean-ref
    xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1">
    <ref-name>cache</ref-name>
    <ref-type>java.util.Map</ref-type>
    <pattern>
      <name>POJOCache</name>
    </pattern>
  </gbean-ref>

And get the cache in the following manner

  cache = (Map<String, Template>) new InitialContext()
          .lookup("java:comp/env/cache");

-----------------------------------



On Thu, May 1, 2008 at 6:22 AM, Gianny Damour <gianny.damour@optusnet.com.au>
wrote:

> Hello Xasima,
>
> WADI does not yet provide a POJO caching solution.
>
> Regarding the http://incubator.apache.org/wadi/wadi-core/apidocs/org/codehaus/wadi/gridstate/impl/GCache.html
> 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://
> cwiki.apache.org/GMOxDEV/geronimo-clustering-with-gcache.html. 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 (http://www.terracotta.org/confluence/display/orgsite/Distributed+Caches)
> > that exposes such an wrapper around different implementation.
> >    2) use the wadi and the http://incubator.apache.org/wadi/wadi-core/apidocs/org/codehaus/wadi/gridstate/impl/GCache.html
> > 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
to
> > 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 ~

Mime
View raw message