5 Replies Latest reply on Nov 7, 2004 8:26 PM by Norbert von Truchsess

    JBossCache inside EJB

    joise joise Newbie

      how to instantiate the only one jboss cache instance per jvm from a ejb?
      is good this combination in terms of performance, concurrent access ... :
      client-->EJB Layer-->DAO-->JBossCache-->BBDD

      Thanks in advance.

        • 1. Re: JBossCache inside EJB
          Ben Wang Master

          If you are running inside JBoss, use a JBossCache MBean (and deploy it as a MBean service).

          -Ben

          • 2. Re: JBossCache inside EJB
            skotagiri Newbie

             


            If you are running inside JBoss, use a JBossCache MBean (and deploy it as a MBean service).


            One issue with using JBossCache MBean in the EJB environment is, you have to keep your CacheLoader outside of the EAR file and place your CacheLoader jar in the server lib directory.

            Also, if the backend store is RDBMS, and if you would like to get access to the JDBC DataSource through ENC ( Enterprise Naming Context java:/comp) inside the CacheLoader, then you may have a problem (I did not try this, but since the CacheLoader is invoked within the MBean ClassLoader, I am assuming that the ENC is not available).

            Here is how I am using the Cache in my EJB enviroment.

            Create TreeCache through a startup servlet (That way I do not have to keep my CacheLoader class outside of the EAR file and I will not get Class Loading errors) and access the JDBC DataSource inside my CacheLoader using through ENC.

            Your comments and feedback is welcome.

            Thanks.

            • 3. Re: JBossCache inside EJB
              Ben Wang Master

              Hi, to follow up your comments:

              1. I am not clear why do you need to put the CacheLoader jar file in your ear file? When you deploy JBossCache as a MBean serivce, you typically place the jboss-cache.jar under all/lib directory, for example. After that, you simply drop a, say, replSync-service.xml under the deploy directory. It is not under any J2EE enc scope.

              2. For RDBMS cache loader, that's true, you can't access it thru java:/comp. But there is a datasource binding under java:/DefaultDS (for example) as well.

              Do I miss anything?

              -Ben

              • 4. Re: JBossCache inside EJB
                Bela Ban Master

                 

                "skotagiri" wrote:

                Also, if the backend store is RDBMS, and if you would like to get access to the JDBC DataSource through ENC


                This is somewhat unrelated, but... I realized that we need to provide a configuration option for JDBCCacheLoader to retrieve the DataSource from JNDI (preconfigured DS), in addition to creating a JDBC connection.
                This allows us to be good citizens and participate in the container's connection pooling.
                I added this to the roadmap for 1.3.

                Bela

                • 5. Re: JBossCache inside EJB
                  Norbert von Truchsess Newbie

                  If you use JBossCache as MBean-Service and put Objects into it that have been loaded by the EJB-classloader from the ejb-jar, than you'l get a ClassNotFoundException as soon you try to access the previously stored objects after redeployment of your ejb-jar. This is because classes being loaded by the previous deployment are no longer accessible from the new EJB-classloader after redeployment.

                  If this is an issue for you, you better go with a startupservlet that stops the local cache-instance on undeployment of your EAR.

                  Or you put the classes in question somewhere in all/lib or system-classpath or so they don't get redeployed.

                  Or you implement a treecachelistener that is notified by some startupservlet from destroy() so it can remove all Objects in question before shuting down the app.

                  (I'm still searching for a clean solution of this issue, will be tricky though).