3 Replies Latest reply on Feb 19, 2009 6:00 PM by brian.stansberry

    configuration of cache when moving from JBoss 4.2.3 to JBoss

    tugman

      Hi all.

      I have a EJB3 based app running in JBoss 4.2.3. I'm trying to move it to JBoss 5, but I'm having problems with the new cache configuration.

      I'm trying to configure it via jBoss microcontainer as seen in documentation:

      http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/3.0.2.GA/userguide_en/html/deployment.html#deployment.microcontainer


      Should it be configured in jboss-cache-manager-jboss-beans.xml ? Or a separate file ?


      Then i'm trying to access it (with no success) like I was doing in JBoss 4.2.3 :

      MBeanServer mbserver = MBeanServerLocator.locateJBoss();
      ObjectName objName = new ObjectName("my.cache:service=MyCache");
      myCache = (Cache) mbserver.getAttribute(objName, "Instance");


      I suspect that the cache is not even being created because I can't see it via jmx-console. It used to appear in JBoss 4.


      After reading the documentation, I'm not getting it to work in JBoss 5.


      Thanks in advance!
      Regards.

        • 1. Re: configuration of cache when moving from JBoss 4.2.3 to J
          jaikiran
          • 2. Re: configuration of cache when moving from JBoss 4.2.3 to J
            tugman

            Thanks a lot jaikiran, the "CacheManager service for AS5 wiki" seems very helpful.

            Now I created an alias (to try to not change my code) in the configAlias property like this:

             <entry>
             <key>my.cache:service=MyCache</key>
             <value>mvcc-shared</value>
             </entry>


            I'm pointing for mvcc-shared just to test.
            Then I'm trying to look up for it like I was doing in JBoss 4:


            MBeanServer mbserver = MBeanServerLocator.locateJBoss();
            ObjectName objName = new ObjectName("my.cache:service=MyCache");
            myCache = (Cache) mbserver.getAttribute(objName, "Instance");


            But with no success. I get an "InstanceNotFoundException".

            The way to look up for the cache changed also in JBoss5 ?

            • 3. Re: configuration of cache when moving from JBoss 4.2.3 to J
              brian.stansberry

              Lot's of stuff here. :)

              First, at the very bottom of
              https://www.jboss.org/community/docs/DOC-12928 there is a file attachment which includes a zipped draft of updated (but still very much draft) AS 5 clustering docs. See section 9.2 for more on the CacheManager.

              Second, I'm assuming you're working with the CacheManager because your EJB3 app needs it -- i.e. you're talking about the cache used for a clustered EJB3 SFSB or a JPA/Hibernate second level cache. If not, if this is a custom cache used by your app, you don't need to use the CacheManager if you don't want to. Chapter 9 of the docs zip referenced above has more on this.

              Third, your cache will not be created or registered in JMX until someone calls into the CacheManager and requests it via a call to getCache("my.cache:service=MyCache", true). This is one of the purposes of the CacheManager -- avoiding deploying caches that no service actually uses. Normally the getCache() call would be done by a container that's managing a JEE component that needs the cache (i.e. the JBossWeb session Manager for a clustered webapp; the EJB container for a clustered EJB3 SFSB; the Hibernate SessionFactory for JPA/Hibernate with second level caching enabled.)

              Fourth, once your cache is created, if you want to access your cache via JMX, you would do this:

              MBeanServer mbserver = MBeanServerLocator.locateJBoss();
              ObjectName objName = new ObjectName("jboss.cache:service=Cache,config=mvcc-shared");
              myCache = (Cache) mbserver.getAttribute(objName, "Cache");
              


              The CacheManager registers the cache in JMX by constructing an ObjectName from the config name a la the above pattern. Note that in JBC 3 the name of the mbean attribute that gives you a ref to the cache itself is now "Cache" instead of "Instance".

              Fifth, you can also get a ref to the cache via the CacheManager. See the docs zip for details.