4 Replies Latest reply on Apr 14, 2010 8:30 AM by ducon_lajoie

    Custom eviction using JndiMultiplexedJBossCacheRegionFactory

      Hi,

       

      I'm trying to use a custom eviction policy for an ear that uses JPA (following chap. 4 of the JBoss Cache Guide). I have an exploded ear, an exploded sar. My ear contains the required files and jars used for persistence. The persistence.xml file is as such:

       

       

      <?

       

      xml version="1.0" encoding="UTF-8"?>

      <

       

      persistence xmlns="http://java.sun.com/xml/ns/persistence"

       

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       

      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence

      http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

       

      version="1.0">

       

      <persistence-unit name="HibernateTest"

       

      transaction-type="JTA">

       

      <jta-data-source>java:datasources/HibernateTest</jta-data-source>

       

      <properties>

       

      <property name="hibernate.dialect" value="com.xxx.hibernate.dialect.SQLServerUnicodeDialect" />

       

      <property name="hibernate.hbm2ddl.auto" value="none" />

       

      <property name="hibernate.show_sql" value="true" />

       

      <property name="hibernate.generate_statistics" value="true" />

       

       

      <property name="hibernate.cache.use_second_level_cache" value="true" />

       

      <property name="hibernate.cache.use_query_cache" value="true" />

       

      <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory" />

       

      <property name="hibernate.cache.region.jbc2.cachefactory" value="java:CacheManager" />

       

      <property name="hibernate.cache.region.jbc2.cfg.entity" value="mvcc-entity" />

       

      <property name="hibernate.cache.region.jbc2.cfg.query" value="local-query" />

       

      <property name="hibernate.cache.region_prefix" value="HibernateTest" />

       

      </properties>

       

      </persistence-unit>

      </

       

      persistence>

       

       

       

      My jboss-service.xml file in my sar is as such:

       

      <

       

      server>

       

      <mbean

       

      code="org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory"

       

      name="jboss.cache:service=JBossCacheManager">

       

      <attribute name="EvictionPolicyConfig">

       

      <config>

       

       

      <attribute name="wakeUpIntervalSeconds">5</attribute>

       

      <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy

       

      </attribute>

       

       

      <region name="/_default_">

       

      <attribute name="maxNodes">500</attribute>

       

      <attribute name="timeToLiveSeconds">300</attribute>

       

      <attribute name="minTimeToLiveSeconds">120</attribute>

       

      </region>

       

       

      <region name="/TS" policyClass="org.jboss.cache.eviction.NullEvictionPolicy" />

       

       

      <region name="/HibernateTest/HibernateTest">

       

      <attribute name="maxNodes">1</attribute>

       

      <attribute name="timeToLiveSeconds">10</attribute>

       

      <attribute name="minTimeToLiveSeconds">5</attribute>

       

      </region>

       

       

      <region name="/HibernateTest/com/c3/hibernate/test/dto">

       

      <attribute name="maxNodes">50000</attribute>

       

      <attribute name="timeToLiveSeconds">1200</attribute>

       

      <attribute name="minTimeToLiveSeconds">120</attribute>

       

      </region>

       

      </config>

       

      </attribute>

       

      </mbean>

      </

       

      server>

       

       

      Except that trying to deploy this results in an exception:

       

      *** DEPLOYMENTS IN ERROR: Name -> Error

      vfsfile:/T:/JBoss-Deploy/HibernateTest.sar/ -> org.jboss.deployers.spi.DeploymentException: Error deploying: jboss.cache:service=JBossCacheManager


      DEPLOYMENTS IN ERROR:
        Deployment "vfsfile:/T:/JBoss-Deploy/HibernateTest.sar/" is in error due to the following reason(s): javax.management.NotCompliantMBeanException: Class does not expose a management interface: java.lang.Object

              at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:993)
              at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:939)
              at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:873)
              at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.checkComplete(MainDeployerAdapter.java:128)
              at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:369)
              at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:255)
              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
              at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
              at java.lang.Thread.run(Thread.java:619)

       

       

      preceded by:

       

      11:23:44,001 ERROR [AbstractKernelController] Error installing to Instantiated: name=jboss.cache:service=JBossCacheManager state=Described mode=Manual requiredState=Configured
      javax.management.NotCompliantMBeanException: Class does not expose a management interface: java.lang.Object

       

       


      Does anyone have any idea how I'm supposed to configure an eviction policy in my sar for this particular factory?

       

      Thanks in advance,

       

      Greg

        • 1. Re: Custom eviction using JndiMultiplexedJBossCacheRegionFactory
          galder.zamarreno

          Your cache configurations look outdated. They seem to belong to JBoss Cache 1.x days. Since it seems that you're deploying in AS5 or higher, you might wanna check the more to up to date guide on configuring Hibernate and Jboss Cache 2LC in  http://community.jboss.org/wiki/ReferenceManualJBossCache3asaHibernate35SecondLevelCache

          • 2. Re: Custom eviction using JndiMultiplexedJBossCacheRegionFactory

            Hi,

             

            Thanks for the update. I've looked over the updated version and while I see some differences with my configuration (which I have now updated after your post), the main issue I have still holds true.

             

            I'm looking for a way to add a new eviction policy that I could ship as part of either an EAR or a SAR and have my persistence.xml in my EAR use it. In other words, I would love to keep mvcc-entity but create my own mvcc-entity-custom, without requiring to modify the jboss-cache SAR that ships with it. The reason for this is that I could have a deployment that uses a very different cache from another one and I would like to have that deployed with each application, rather than at the server level. I haven't been able to do that, it seems that the cache registry is only configured once and new entries cannot be added/used by other applications.

             

            Regards,

             

            Greg

            • 3. Re: Custom eviction using JndiMultiplexedJBossCacheRegionFactory
              galder.zamarreno

              Even thouh the jbosscache sar comes with some sample configurations such as mvcc-entity, nothing stops you from copy/pasting that file, producing a new one and adding your  mvcc-entity-custom there. Once you have the file there, you can do several things:

               

              1. Use a SharedJBossCacheRegionFactory as per docu and configure hibernate.cache.jbc.cfg.shared property with the location of the new configuration file.

               

              2. Carry on using JndiMultiplexedJBossCacheRegionFactory, in which case you need to go to the CacheManager started by the server and made the modificatioins there.

               

              If you want the cache to be deployed per application, you wanna be using option 1.

               

              Again, this is all very clearly explained in  http://www.jboss.org/file-access/default/members/jbossclustering/freezone/docs/hibernate-caching/3.5/en-US/html/configuration.html#sessionfactory-factories

              • 4. Re: Custom eviction using JndiMultiplexedJBossCacheRegionFactory

                Hi,

                 

                I'll have another look at the link you sent me, I think I had gone through it but I might have not understood it the way you have explained it.

                 

                The reason I want to use the MultiplexedCache is that it's eventually to be used on a cluster and for XA transactions and I'm pretty sure the docs were saying to use that one. The only thing I'd want to change is really the eviction policy because I'd want to configure it differently for different regions based on the deployed application (e.g. one customer would not use the same ttl for a certain region compared to another etc.).

                 

                Thanks a lot, i'll keep posting here if I can't get it to work.