1 Reply Latest reply on Jan 25, 2011 10:20 AM by bbarin

    Cannot intercept a method

    bbarin

      Hi

       

      I've developed a simple aspect to measure the performance of my application, but althogh the deployment of the aspect in JBoss looks correct, the method that's aimed is not intercepted. I used the following approach:

       

      - I have a performance.jar which contains the following aspect:

       

       

      package com.agfa.ogpc.performance.aspects;
      
      import com.agfa.ogpc.performance.dao.NeoDatisMessageProcessingDAO;
      import com.agfa.ogpc.performance.dao.PerformanceDAO;
      import org.jboss.aop.joinpoint.MethodInvocation;
      
      import com.agfa.ogpc.performance.model.TimeElapsed;
      
      public class MessageProcessingAspect {
      
          public Object intercept(final MethodInvocation invocation) throws Throwable {
              long startTime = System.currentTimeMillis();
              try {
                  return invocation.invokeNext();
              } finally {
                  long endTime = System.currentTimeMillis();
                              store(new TimeElapsed(startTime,endTime));
              }
          }
      
              private void store(final TimeElapsed timeElapsed) {
                  PerformanceDAO<TimeElapsed> dao = new NeoDatisMessageProcessingDAO();
                  dao.persist(timeElapsed);
              }
      }
      

       

      - I also have several .ears which are part of my application

      - I deployed a file named performance-aop.xml in the deploy folder, that looks like:

      <?xml version="1.0" encoding="UTF-8"?>
      <aop>
      <aspect class="com.agfa.ogpc.performance.aspects.MessageProcessingAspect"/>
      <bind pointcut="execution(* com.agfa.hap.bpe.components.db.BasicStatelessDBComponent->*(..))">
          <around aspect="com.agfa.ogpc.performance.aspects.MessageProcessingAspect" name="intercept" />
      </bind>    
      </aop>
      

       

      The application is deployed correctly and the -aop.xml is wellformed, but the application is not intercepted and I'm sure the method is being called (I debugged the code).

       

      Then I have changed the syntax to intercept any method:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <aop>
      <aspect class="com.agfa.ogpc.performance.aspects.MessageProcessingAspect"/>
      <bind pointcut="execution(* *->*(..))">
          <around aspect="com.agfa.ogpc.performance.aspects.MessageProcessingAspect" name="intercept" />
      </bind>    
      </aop>
      

       

      But even after this change the aspect is not being called. I also tried to change the performance.jar to performance.aop and include a jboss-aop.xml within the META-INF folder, but without any success.

       

      So, to summarize: I want to do some measures in an existing application running on JBoss 4.2.2. I couldn't find any example on that.

      I suppose I have to enable the load time weaving mode, but turning on that option crashes the JBoss.

       

      Any idea would be very appreciated.

       

      Thanks,

       

      Bruno

        • 1. Cannot intercept a method
          bbarin

          Hi,

           

          After some digging around the information spread over the web, I have found the solution:

           

          • Enable load time weaving in the file JBOSS_HOME\server\production\deploy\jboss-aop-jdk50.deployer\META-INF\jboss-service.xml
          • Copy JBOSS_HOME\server\production\deploy\jboss-aop-jdk50.deployer\pluggable-instrumentor.jar to JBOSS_HOME\lib\endorsed folder
          • Enable the agent in run.bat adding the following line:

                         set JAVA_OPTS=%JAVA_OPTS% -javaagent:%JBOSS_ENDORSED_DIRS%\pluggable-instrumentor.jar

           

           

          Be sure you have:

          - Your aspects deployed in the "deploy" folder either a .jar or .aop file

          - In case of .jar: You must have a <filename>-aop.xml in the "deploy" folder (preferred, more flexible)

          - In case of .aop: Only be sure there is META-INF/jboss-aop.xml containing the aspect definition in your package

           

          Cheers,

           

          Bruno