Tag: jboss cache

  • First profit of my blog :)

    Here is a thanking e-mail I’ve got (that made me really happy and gave a good karma):

    Hello Jan,
    Regard http://www.jankowalski.pl/category/glassfish-2, I wish to thank you deeply for your explanations how you worked out the JB cache under Glassfish.

    I have been spending hours just looking and trying several cache solutions. Finally the JB cache seemed promising, except all docs seemed made for the JB AS only. I was really on the point to give it up and either look for , again, another cache solution or , after all, start from scratch and write my own.

    At that point I started to think about, if I was to write my own, I may use the servlet context to handle some kind of pointer to the cache. That is while looking for that I finally find your page, and thank you Jan, the information you gave I tried and it worked directly for me.

    Thank you thank you thank you. Your idea of using the naming way in context and the code example made things crystal clear.

    This should bring you good karma :)

    Best regards,

    Fabrice Duche
    www.fdicc.org

  • Jboss Cache on Glassfish 2.1.1

    Previously I’ve just mentioned that I am working on JbossCache deployed to glassfish. I want to have it distributed. My frustration was I couldn’t find any configuration file online of replication mode. It turned out that example configuration was inside JBoss Cache zip file, Core Edition version 3.2.5 “Malagueta” (download full zip jbosscache-core-3.2.5.GA-all.zip) in file jbosscache-core-3.2.5.GA\etc\config-samples\total-replication.xml.

    • remember to put your configuration-cache.xml in WEB-INF/classes
    • I’ve changed they way of communication from sync to async. (should be faster)
    • upload 7 jar to your AS and restart: commons-logging.jar, jbosscache-core.jar, jboss-common-core.jar, jboss-logging-spi.jar, jboss-transaction-api.jar, jcip-annotations.jar, jgroups.jar

    After loading 7jars to domain/libs and restarting Glassfish I was able to deploy web application with one class: JbossCacheActivatorServletContextListener

    public class JbossCacheActivatorServletContextListener implements ServletContextListener {
    
        private Cache cache = null;
    
        public void contextInitialized(ServletContextEvent sce) {
            try {
                CacheFactory factory = new DefaultCacheFactory();
                cache = factory.createCache("cache-configuration.xml");
                InitialContext ctx = new InitialContext();
                ctx.bind("JBossCacheRef", cache);
            } catch (NamingException ex) {
                Logger.getLogger(JbossCacheActivatorServletContextListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
        public void contextDestroyed(ServletContextEvent sce) {
            try {
                InitialContext ctx = new InitialContext();
                ctx.unbind("JBossCacheRef");
                cache.stop();
            } catch (NamingException ex) {
                Logger.getLogger(JbossCacheActivatorServletContextListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    after all if there is cache instance. You can login to jconsole localhost:8686 and look for (ObjectName jboss.cache) it under MBeans node.

    Testing.

    1. I run cache on two separate Glassfish AS. They are in the same network (same mask; I am sure it works either in opposite condition but it will need more configuration).
    2. I’ve coded two ejb’s as with @WebService annotation, one i puting into cache and second is reading from it.
    3. I’ve turned off one node and put something into second one cache. I check for content… is ok. Then I start first node and check… and content is being replicated from the second what makes it work perfect.

    Attention.

    In jboss cache user guide guys from jboss cache suggest to register it into JMX (5.4.2. Registering the CacheJmxWrapper with the MBeanServer). As you can see I put referance to cache into InitialContext. That is why becasue I could not get into jbosscache trought the jmx mbeans cuz Glassfished sets a different ObjectName for this object, so I’ve got problems with finding it.

  • Jboss Cache on Glassfish

    As some of you could notice I am openESB developer and fan. It’s development tool (Netbeans) is tightly bounded with Glassfish. Of course you can bound Jboss or any other AS to it. But I am accustomed to Glassfish (and previous Sun Application Server since JCAPS) so I work with it and all people from my division too. (more…)