10 Replies Latest reply on Oct 24, 2011 5:30 AM by renzos

    Getting Commits/Rollbacks stats from TxInterceptor

    renzos

      Good evening, I'm using infinispan 4.2.1 FINAL and at some point of my app I would like to print some stats on the number of commits and rollbacks of the executed transactions using the TxInterceptor methods. The problem is that in standard infinispan configuration TxInterceptor is automatically loaded in the chain so I can't use the AdvancedCache.addInterceptor(CacheMgmtInterceptor cmi, int position) command to add the Interceptor to my cache and use the cmi methods as I do with the CacheMgmtInterceptor. What should I declare in order to use the TxInterceptor methods on my cache?

      Hope I've explained the problem correctly, thanks a lot.

        • 1. Re: Getting Commits/Rollbacks stats from TxInterceptor
          dan.berindei
          • 2. Re: Getting Commits/Rollbacks stats from TxInterceptor
            renzos

            Thanks Dan for your answer but maybe I need few more tips as I'm new to JMX and I couldn't find step-by-step tutorials. Here an example of what I mean:

             

            First of all I declare:

             

            manager = new DefaultCacheManager("ConfigFile.xml");

            Cache<Object, Object> cache = manager.getCache("myCache");

             

            then I declare the TM:

             

            TransactionManager tm = cache.getAdvancedCache().getTransactionManager();

             

            Now what I would like to do is getting TxInterceptor stats on that TM. Using the example you suggested me I tried to put in my code the following code lines:

             

            private static final String JMX_DOMAIN = MYCLASSNAME.class.getSimpleName();

            private ObjectName txInterceptor;

            private MBeanServer threadMBeanServer;

            etc...

             

            But even adding all the "imports" needed I get many errors

            • 3. Re: Getting Commits/Rollbacks stats from TxInterceptor
              dan.berindei

              What errors are you getting?

               

              Keep in mind that the test depends on method getCacheObjectName() of class TestingUtil which is not in infinispan-core.jar since it's used only by the test suite.

              • 4. Re: Getting Commits/Rollbacks stats from TxInterceptor
                renzos

                On the statement

                 

                "txInterceptor = getCacheObjectName(JMX_DOMAIN, "myCache(repl_sync)", "Transactions");

                 

                I get "cannot find symbol, method getCacheObjectName" and maybe that's the missing TestingUtil class, I hoped it was enough to put "import org.infinispan.test.TestingUtil.getCacheObjectName;" but if infinispan-core doesn't contain it... Do you know where I can download that library from?

                • 5. Re: Getting Commits/Rollbacks stats from TxInterceptor
                  sannegrinovero

                  Hi Renzo,

                   

                  I hoped it was enough to put "import org.infinispan.test.TestingUtil.getCacheObjectName;" but if infinispan-core doesn't contain it... Do you know where I can download that library from?

                       <dependency>

                           <groupId>org.infinispan</groupId>

                           <artifactId>infinispan-core</artifactId>

                           <version>${infinispan.version}</version>

                           <type>test-jar</type>

                           <scope>test</scope>

                        </dependency>

                  • 6. Re: Getting Commits/Rollbacks stats from TxInterceptor
                    renzos

                    <dependency>

                             <groupId>org.infinispan</groupId>

                             <artifactId>infinispan-core</artifactId>

                             <version>${infinispan.version}</version>

                             <type>test-jar</type>

                             <scope>test</scope>

                          </dependency>

                     

                     

                    Thanks but I do not use Maven

                    • 7. Re: Getting Commits/Rollbacks stats from TxInterceptor
                      sannegrinovero

                      It's just a way to identify the jar;

                      you can download it manually from the Maven repository:

                       

                      https://repository.jboss.org/nexus/index.html#nexus-search;gav~org.infinispan~infinispan-core~~~~kw,versionexpand

                       

                      select on the version you need, in the "Download" column (right most) download test.jar

                      • 8. Re: Getting Commits/Rollbacks stats from TxInterceptor
                        renzos

                        Thanks a lot, downloaded,  imported but I can't manage it to work, the error I get is as follows:

                         

                        javax.management.InstanceNotFoundException: Node:type=Cache,manager="DefaultCacheManager",name="manager",component=cache

                            at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)

                            at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)

                            at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)

                            at infinispantest.RunnableImpl.run(RunnableImpl.java:107)

                            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)

                            at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)

                            at java.util.concurrent.FutureTask.run(FutureTask.java:138)

                            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:680)

                        • 9. Re: Getting Commits/Rollbacks stats from TxInterceptor
                          sannegrinovero

                          Did you enable JMX and transactions on the Infinispan configuration?

                           

                          http://docs.jboss.org/infinispan/4.2/apidocs/config.html#ce_global_globalJmxStatistics

                          • 10. Re: Getting Commits/Rollbacks stats from TxInterceptor
                            renzos

                            Sure, transactions already worked before, what I'm trying ti do is getting stats on the number of commits. Here my config file:

                             

                            <infinispan

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

                                  xsi:schemaLocation="urn:infinispan:config:4.2 http://www.infinispan.org/schemas/infinispan-config-4.2.xsd"

                                  xmlns="urn:infinispan:config:4.2">

                             

                                   <global> <!--contains System wide local settings-->

                                       <globalJmxStatistics enabled="true" />

                                       <transport clusterName="infinispan-cluster" transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport">

                                           <properties>

                                               <property name="configurationFile" value="jgroups-udp.xml" />

                                           </properties>

                                       </transport>

                               </global>

                             

                               <default> <!--refers to configuration which is used by all Infinispan caches-->

                                       <deadlockDetection enabled="false"/>

                                    <transaction

                                        transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"

                                        syncRollbackPhase="false"

                                        syncCommitPhase="false"

                                        useEagerLocking="false"/>

                                    <locking isolationLevel="REPEATABLE_READ"

                                             writeSkewCheck="false"

                                             concurrencyLevel="500"

                                             useLockStriping="false"

                                             lockAcquisitionTimeout="100" />

                                    <clustering mode="replication">

                                           <sync/>

                                          <stateRetrieval fetchInMemoryState="false"/> <!--updates the cache state on the current node (REPLICATION only) -->

                                    </clustering>

                               </default>

                            </infinispan>