8 Replies Latest reply on Mar 18, 2011 5:42 PM by susnet

    JBoss cache isolation between wars in an ear?

    susnet

      I have 2 war in one ear and I use JBoss cache with seam.

      In a.war I use seam cache to cache page fragments. In b.war I would like to remove this cached fragment (because I want it to create a new one because I changed data in the database). Is that possible?

      I tested it and it does not seem to work. I get a warn message like this:

      WARN  [TreeCache] node /myDefinedFragments not found

      So it seems that the cache are isolated between wars in an ear. Is that so? Is there any way to configure the cache so that the caching is not isolated?

        • 1. JBoss cache isolation between wars in an ear?
          mp911de

          Hi there,

          this depends on your Config. Usually you would define your JBoss Cache as MBean. When your MBean is defined in your EAR (something like

           

          <mbean code="org.jboss.cache.TreeCache"

                              name="some.service:service=TreeCache,name=MyTreeCache">

                              <depends>jboss:service=Naming</depends>

                              <depends>jboss:service=TransactionManager</depends>

                              .....

          </mbean>) you got one Instance (additionally check for Class-Loader-Isolation). When you now use this MBean you have one Cache which should be fine. Have you browsed your Cache to see, what's in it (JMX-Console)?

           

          Best regards,

          Mark

          • 2. JBoss cache isolation between wars in an ear?
            susnet

            Thanks for your answer!

             

            Where do I define this mbean? I tried in my cache-configuration.xml but nothing happend.

             

            I looked into the jmx-console and I see all the cache configuration, but I did not find the nodes with data that should be in the cache. Where do I find it?

             

            I use Seam 2.2.1  and on my xhtml-pages  I use the <s:cache> tag.

            The ear contains 2 wars and one jar-ejbmodule.

             

            My cache-configuration.xml looks like this:

             

            <server>

             

              <mbean code="org.jboss.cache.jmx.CacheJmxWrapper" name="jboss.cache:service=Cache,name=MyCache">

              <!-- Configure the TransactionManager -->

              <attribute name="TransactionManagerLookupClass">

                                          org.jboss.cache.JBossTransactionManagerLookup

                  </attribute>

             

              <!--

                                          Node locking level : SERIALIZABLE REPEATABLE_READ (default) READ_COMMITTED READ_UNCOMMITTED NONE

                                -->

                                <attribute name="IsolationLevel">READ_COMMITTED</attribute>

             

              <!-- Lock parent before doing node additions/removes -->

              <attribute name="LockParentForChildInsertRemove">false</attribute>

             

              <!--

                                          Valid modes are LOCAL (default) REPL_ASYNC REPL_SYNC INVALIDATION_ASYNC INVALIDATION_SYNC

                                -->

              <attribute name="CacheMode">LOCAL</attribute>

             

              <!-- Max number of milliseconds to wait for a lock acquisition -->

              <attribute name="LockAcquisitionTimeout">10000</attribute>

             

              <!-- Specific eviction policy configurations. This is LRU -->

              <attribute name="EvictionConfig">

              <config>

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

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

             

              <!-- Cache wide default -->

              <region name="/_default_">

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

              </region>

              <region name="/sidebarLeftFragments">

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

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

              </region>

            ...

             

             

            Should I replace CacheJmxWrapper with org.jboss.cache.TreeCache ?

            • 3. JBoss cache isolation between wars in an ear?
              mp911de

              My example was for JBoss Cache 1. When you use JBoss Cache >= Release 2 your Config-File is ok (more Reference see http://docs.jboss.org/jbosscache/2.0.0.GA/JBossCache-UserGuide/en/html_single/index.html#sample_xml_file)

               

              It sound like your Cache isn't used anyway. I suppose, Seam creates for each WAR a Cache (MBean) Instance. Try different MBean names for your two Caches, then you should be able to see the Cache-Entries. With Eh-Cache, there is an static Impl, so that different Cache-Instances are merged to one Cache. That could be one possible Solution. The other could be, to flush two JBoss Caches.

               

              Best regards,

              Mark

              • 4. JBoss cache isolation between wars in an ear?
                susnet

                Thanks again for replying!

                 

                Well I do use JBoss Cache 1. But now it occured to me that my config file is not read at all. In components.xml that is put in WEB-INF I define the cache and if I put

                 

                <cache:jboss-cache-provider configuration="META-INF/cache-configuration.xml" />

                 

                The cache works but I don't think this file is read because my nodes timeouts does not work.

                 

                If I also add the name attribute like this:

                 

                <cache:jboss-cache-provider name="myCache" configuration="META-INF/cache-configuration.xml" />

                 

                then I get org.jboss.cache.ConfigureException: input stream is null for property xml.

                 

                I also tried using JBoss Cache 2 but get the same exception.

                org.jboss.cache.ConfigureException: input stream is null for property xml

                I guess this means that the config-file is not found although I put this file like everywhere, both in ejb jar META-INF and in ear/META-INF war/META-INF so that it really should be found.

                 

                I thought that having  the name attribute set then I can get hold of it via  @In (value="myCache") CacheProvider .

                 

                From the Seam manual I read

                 

                If you want to have multiple cache configurations in your application, use components.xml to configure multiple cache providers:

                <components xmlns="http://jboss.com/products/seam/components" 
                            xmlns:cache="http://jboss.com/products/seam/cache">
                   <cache:jboss-cache-provider name="myCache" configuration="myown/cache.xml"/>
                   <cache:jboss-cache-provider name="myOtherCache" configuration="myother/cache.xml"/>
                </components>

                 

                So I guess this is how it should be done but my problem is that my cache-configuration.xml could not be read? Do you have any ideas?

                 

                 

                 


                • 5. JBoss cache isolation between wars in an ear?
                  mp911de

                  According to Seam Docs, te cache config xml is needed on the classpath (

                  You'll also need to provide a configuration file for JBossCache. Place treecache.xml with an appropriate cache configuration into the classpath (e.g. the ejb jar or WEB-INF/classes). JBossCache has many scary and confusing configuration settings, so we won't discuss them here. Please refer to the JBossCache documentation for more information.)

                   

                  Try to put your cache-configuration.xml to META-INF in some of your Jars that are used by your war.

                  • 6. JBoss cache isolation between wars in an ear?
                    susnet

                    Thank you again for your answer!

                     

                    Yes I put the cache-configuration.xml file in that place (in META-INF in my ejb jar module), and I also tried all other META-INF places in the ear and in the war and I double checked spellings and also checked the deployed files on JBoss and the file is there and the jgroups.jar and jboss-cache.jar is also there so there are no build-deployment errors. So I have no idea why it is not found. Maybe I should report this as a bug in seam? I use seam 2.2.1.final and the jboss-cache.jar and jgroups.jar I use are those that are included in the seam 2.2.1.final download.

                    There has been a lot of bugs with seam and ear deployment before, I believe they mainly test single war deployments.

                    • 7. JBoss cache isolation between wars in an ear?
                      mp911de

                      Hi,

                      sounds like a Bug, but try to ask the guys in http://community.jboss.org/en/seam?view=discussions

                       

                      Best regards,

                      Mark

                      • 8. JBoss cache isolation between wars in an ear?
                        susnet

                        Thank you again!

                         

                        Actually I managed to solve the exception problem with the name. I solved it by adding the attribute

                        cacheProvider="#{rmyCache}" to the s:cache tag.

                         

                        But still, requests for cacheProvider from b.war will not find the cache from a.war even though I gave them the same name (myCache).

                        And also the cache-configuration.xml I'm really unsure if it is read since my nodes lives forever even though I configured it to only live for one hour.

                         

                        But I guess this is also a question for the seam guys. I have asked my question here in the seam forum: http://seamframework.org/Community/SeamJBossCachePossibleToHaveOneCacheSharedBetweenAllWarsInAnEar

                         

                        Thank you again for responding! Have a great weekend!

                        /Susanne