7 Replies Latest reply on Jun 10, 2013 7:23 PM by pruivo

    Interceptor issue with Infinispan

    sri2

      Hi,

       

      I created an interceptor extending from BasicCustomInterceptor implementing with MBean with simple methods.

      Initialized/Uninitiazed in start and stop overrided methods. It accesses these methods when creating and destroying bean.

      Somehow it has not accessed to visitDistributedExecuteCommand override method where my logic reside to compute something in distributed mode with numOwners=2. If I override other methods like visitPutKeyValueCommand then it accesses those methods only.

      To find the issue, I added some couple of methods by putting print out statement along return invokeNextInterceptor(ctx, command) Just for testing purpose. These methods are :

       

      1)//Not Accessed

      @Override

          public Object visitSizeCommand(InvocationContext ctx, SizeCommand command)  throws Throwable {

             

              System.out.println("Inside visitSizeCommand");

              return invokeNextInterceptor(ctx, command);       

          }

      2) //Not Accessed

      @Override

      public void visitCollection(InvocationContext ctx,  Collection<? extends VisitableCommand> toVisit) throws Throwable {

              System.out.println("Inside visitCollection");

      //        debug("Collection Size: " + toVisit.size() );

      }

       

      3) //Not Accessed

      @Override

      public  <V> Object visitDistributedExecuteCommand(InvocationContext ctx, DistributedExecuteCommand<V> command) throws Throwable {

              System.out.println("++++++++++++Inside visitDistributedExecuteCommand()");

              Object o = invokeNextInterceptor(ctx, command);

              // Some logic here

              return o;

          }

       

      4) // Accessed

      @Override

             public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand cmd) throws Throwable {

                System.out.println("Ignoring this call to enforce read-only behavior");

                return invokeNextInterceptor(ctx, cmd);

       

             }

       

      5) // Accessed

      @Override

             visitRemoveCommand(InvocationContext ctx, RemoveCommand cmd) throws Throwable {

                System.out.println("Visited::::visitRemoveCommand");

               return invokeNextInterceptor(ctx, cmd);

             }

       

      I'm using 5.3.0.Beta1 version with JDK 1.7.0_04. Interceptor added in config file. Testing with PiApproximationDemo and also with SimpleCache ( book, pay and list ) Infinispan book example.

       

      Please advice how do I make it access to visitDistributedExecuteCommand override method.

      And also advice how do I access to individual statistics from each node in distributed environment and show it on RHQ monitor/JConsole/JVisualVM by using MBeans or MXBeans.

      Do I have to write a plug in for RHQ? Or Do I have to write purely JMX code? I have to see each node info in addition to  these statistics from URL http://docs.jboss.org/infinispan/5.1/apidocs/jmxComponents.html#Statistics.

      Any input and code examples are appreciated. Thanks in Advance.

       

      Moderator: I posted the same question in wrong forum(Beginner's corner) in jboss few minutes ago, please ignore the other one.

       

      Sri

       

      Partial Config file:

       

          <global>

                 <transport>        

                  <properties>            

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

                  </properties>      

              </transport>

          </global> 

         <default>     

             <clustering mode="distribution">      

             <sync/>      

             <hash numOwners="2"/>   

            </clustering>

       

            <customInterceptors>

               <interceptor class="com.xxx.xxx.TestInterceptor" position="FIRST" />

            </customInterceptors>     

         </default>

       

      Output from SimpleCache Example:

       

      May 30, 2013 3:31:11 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport start

      INFO: ISPN000078: Starting JGroups Channel

      May 30, 2013 3:31:11 PM org.jgroups.logging.JDKLogImpl warn

      WARNING: [JGRP00014] TP.discard_incompatible_packets has been deprecated: incompatible packets are discarded anyway

      May 30, 2013 3:31:11 PM org.jgroups.logging.JDKLogImpl warn

      WARNING: [JGRP00014] TP.enable_bundling has been deprecated: will be ignored as bundling is on by default

      May 30, 2013 3:31:11 PM org.jgroups.logging.JDKLogImpl warn

      WARNING: [JGRP00014] UNICAST.setTimeout has been deprecated: not used anymore

      May 30, 2013 3:31:14 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport viewAccepted

      INFO: ISPN000094: Received new cluster view: [xxxx]

      May 30, 2013 3:31:14 PM org.infinispan.remoting.transport.jgroups.JGroupsTransport startJGroupsChannelIfNeeded

      INFO: ISPN000079: Cache local address is xxxx, physical addresses are [xxx]

      May 30, 2013 3:31:14 PM org.infinispan.factories.GlobalComponentRegistry start

      INFO: ISPN000128: Infinispan version: Infinispan 'Tactical Nuclear Penguin' 5.3.0.Beta1

      *************registering MBean: com.xxx.xxx:type=TestInterceptor

      ********* Printing Interceptors from interceptorChain

      ********* Interceptor name: com.xxx.xxx.TestInterceptor

      ********* Interceptor name: org.infinispan.interceptors.InvocationContextInterceptor

      ********* Interceptor name: org.infinispan.statetransfer.StateTransferInterceptor

      ********* Interceptor name: org.infinispan.statetransfer.TransactionSynchronizerInterceptor

      ********* Interceptor name: org.infinispan.interceptors.NotificationInterceptor

      ********* Interceptor name: org.infinispan.interceptors.locking.NonTransactionalLockingInterceptor

      ********* Interceptor name: org.infinispan.interceptors.EntryWrappingInterceptor

      ********* Interceptor name: org.infinispan.interceptors.distribution.NonTxConcurrentDistributionInterceptor

      ********* Interceptor name: org.infinispan.interceptors.CallInterceptor

      May 30, 2013 3:31:14 PM org.infinispan.jmx.CacheJmxRegistration start

      INFO: ISPN000031: MBeans were successfully registered to the platform MBean server.

      Ticket booking system

      =====================

      Commands: book, pay, list

      > book

      Enter name aaa

      Enter show 111

      Visited::::visitPutKeyValueCommand

      Booked ticket Ticket{name='aaa', show='111'}

      > book

      Enter name bbb

      Enter show 222

      Visited::::visitPutKeyValueCommand

      Booked ticket Ticket{name='bbb', show='222'}

      > list

      Ticket{name='aaa', show='111'}

      Ticket{name='bbb', show='222'}

      > pay

      Enter ticketid 1

      Visited::::visitRemoveCommand

      Checked out ticket Ticket{name='aaa', show='111'}

      >

        • 1. Re: Interceptor issue with Infinispan
          wdfink

          Hello Sri2,

          welcome to the forum.

           

          Please do not cross post and continue here.

          • 2. Re: Interceptor issue with Infinispan
            pruivo

            Hi Sri2,

            sri2 wrote:

             

            Please advice how do I make it access to visitDistributedExecuteCommand override method.

            Your CustomInterceptor looks good. Some notes about the "not accessed" methods:

             

            visitDistributedExecuteCommand: the DistributedExecuteCommand is not longer visited by the interceptor chain. So, you are not able to intercept it.

            visitSizeCommand: the SizeCommand is visited when you invoke cache.size(). Are you sure that size() is invoked in yours example?

            visitCollection: this is an helper method that loops in each VisitableCommand and tries to visit them. This is not supposed to be overriden and it will never be invoked.

             

            sri2 wrote:

             

             

            And also advice how do I access to individual statistics from each node in distributed environment and show it on RHQ monitor/JConsole/JVisualVM by using MBeans or MXBeans.

            Do I have to write a plug in for RHQ? Or Do I have to write purely JMX code? I have to see each node info in addition to  these statistics from URL http://docs.jboss.org/infinispan/5.1/apidocs/jmxComponents.html#Statistics.

            About the statistics, you have to annotate you class with @MBean, your attributes with @ManagedAttribute and your operations with @ManagerdOperation. Infinispan takes care of the rest. Your MBean should be visible with JConsole and JVisualVM without any problem.

             

            Please make sure you have the jmx enabled in configuration:

             

            <global>
              <globalJmxStatistics enabled="true" jmxDomain="org.infinispan" />
              ...
            </global>
            <default>
              <jmxStatistics enabled="true"/>
              ...
            </default>
            

             

            About RHQ I don't know how it works. In your distribution, you should have a jar named infinispan-rhq-plugin.jar. If I'm not mistaken, you have to install it in RHQ server. However, I believe that your annotated methods may not be visible. I believe you have to update the xml file rhq-plugin.xml that is inside the jar, to add manually yours operations and metrics.

             

            I hope this would help you. If you have more question let me know.

             

            Cheers,

            Pedro

            • 3. Re: Interceptor issue with Infinispan
              cotton.ben

              Please advice how do I make it access to visitDistributedExecuteCommand override method.

              And also advice how do I access to individual statistics from each node in distributed environment and show it on RHQ monitor/JConsole/JVisualVM by using MBeans or MXBeans.

               

              Great questions.

              • 4. Re: Interceptor issue with Infinispan
                nadirx

                 

                About RHQ I don't know how it works. In your distribution, you should have a jar named infinispan-rhq-plugin.jar. If I'm not mistaken, you have to install it in RHQ server. However, I believe that your annotated methods may not be visible. I believe you have to update the xml file rhq-plugin.xml that is inside the jar, to add manually yours operations and metrics.

                 

                Indeed, the rhq-plugin.xml descriptor is the only way in which the statistics and operations can be exposed to the RHQ server.

                • 5. Re: Interceptor issue with Infinispan
                  sri2

                  Thanks for your repy Pedro and Tristan. The information you guys provided helpful to me.

                   

                  • In my case I have to collect statistics for about 100 nodes in couple of clusters at run time.  Please advice is there anyway I can access to each node statistics in Mapper/Reducer paradigm at run time if visitDistributedExecuteCommand doesn't work. As per Infinispan design, cache operation is encapsulated by commands which are processed by visitors and interceptors are special types of visitors.  Custom Interceptors should extend BaseCustomInterceptor to access to Cache, EmbeddedCacheManager and life cycle methods.  Means one has to trap statistics only through custom Interceptor by passing values or operations to JMX MXBeans I think, please correct if I'm wrong.

                   

                   

                  • RHQ: - For every version upgrade rhq-plugin.xml has to customize with my operations. If it is like calling xml file inside another xml resource (like in Spring )then it is ok otherwise maintenance is painful. Invoking plugin from another plugin then it is ok.

                   

                   

                  • Pedro: I added those other methods visitCollection(...) and visitSizeCommand(...) just for testing purpose whether they were invoking or not as I mentioned in my first posting above. I'm not interested in those methods at this moment. But one method has not invoked after calling cache.size() method after your suggestion fyi. 

                       Partial code from SimpleCache book example :

                   

                   

                  DefaultCacheManager manager = null;

                   

                  Cache<Integer, Ticket> cache =null;

                  ...

                  manager = new DefaultCacheManager("custom-interceptors.xml"

                  );

                  cache = manager.getCache();

                  ...

                  ...

                   

                   

                   

                  if

                  (command.equals("list"

                  )) {

                   

                  System.out.println("Cache size: "+ cache.size());

                  Set <Integer> set = cache.keySet();

                   

                  for

                  (Integer ticket: set) {

                  System.out.println(cache.get(ticket));

                  }

                   

                   

                  output:

                      

                   

                  Ticket booking system

                  =====================

                  Commands: book, pay, list

                  > book

                  Enter name

                  aaa

                  Enter show

                  111

                  Visited::::visitPutKeyValueCommand

                  Booked ticket Ticket{name='aaa', show='111'}

                  > book

                  Enter name

                  bbb

                  Enter show

                  222

                  Visited::::visitPutKeyValueCommand

                  Booked ticket Ticket{name='bbb', show='222'}

                  > list

                  Cache size: 2

                  Ticket{name='aaa', show='111'}

                  Ticket{name='bbb', show='222'}

                  > pay

                  Enter ticketid

                  1

                  Visited::::visitRemoveCommand

                  Checked out ticket Ticket{name='aaa', show='111'}

                  >

                   

                   

                  Thanks,

                  Sri2

                   

                  • 6. Re: Interceptor issue with Infinispan
                    cotton.ben

                    is there anyway I can access to each node statistics in Mapper/Reducer paradigm at run time if visitDistributedExecuteCommand doesn't work?

                     

                    Infinispan team -- Please consider responding to this question.

                    • 7. Re: Interceptor issue with Infinispan
                      pruivo

                      Hi Sri2.

                      sri2 wrote:

                       

                      • In my case I have to collect statistics for about 100 nodes in couple of clusters at run time.  Please advice is there anyway I can access to each node statistics in Mapper/Reducer paradigm at run time if visitDistributedExecuteCommand doesn't work. As per Infinispan design, cache operation is encapsulated by commands which are processed by visitors and interceptors are special types of visitors.  Custom Interceptors should extend BaseCustomInterceptor to access to Cache, EmbeddedCacheManager and life cycle methods.  Means one has to trap statistics only through custom Interceptor by passing values or operations to JMX MXBeans I think, please correct if I'm wrong.

                      which kind of statistics do you need? The DistributedExecuteCommand only wraps the Callable<?> and invokes the call() method.

                       

                      Cheers,

                      Pedro