Results 1 to 4 of 4

Thread: How to find methods matching pointcut at startup

  1. #1

    Default How to find methods matching pointcut at startup

    I'm wondering if there is an easy way to find all methods that match a particular pointcut. For example, I'd like something that can return a list of Methods or JoinPoints so I can get the class name and method name. For example:
    Code:
    List<JoinPoint> jps = AopUtils.findMatchingJoinPoints(MyAspect.class)
    The specifics:

    I want to make it easy to expose JMX statistics on some of my public controller handler methods. For example:
    Code:
    @Controller LoginController {
       @RequestMapping("/login")
       @JmxTracked
       public String login(HttpServletRequest pReq) {...}
    To do this, I want to create a some simple @Before advice that keeps a counter of each time the login() method is invoked and then expose that counter over JMX.
    Code:
    @Aspect public class JmxTrackingAspect {
        @Before(@annotation(com.mycompany.JmxTracked))
        public void incrementCount() {...}
    }
    Code:
    /** This is will be exposed with one instance for each @JmxTracked method */
    public class Counter {
        public int getInvokationCount();
    }
    I know how to write the Aspect for this. However, I need help writing my special MBeanExporter that finds every method that matches the pointcut because I want to create one instance of my counter MBean for each method. This way I can eagerly create all of the MBeans at startup so that the advice can always know the MBean is created and available.

    Is there a way to find all of the methods that match a particular pointcut? I would like to find them all at startup and create the MBeans.

    Thanks for any tips or pointers.

  2. #2
    Join Date
    Sep 2012
    Posts
    4

    Default

    Any solution to this? I have a similar issue.

  3. #3

    Default

    Nope, I never found a solution.

  4. #4
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    Is it necessary to have a mbean for each method? Or is it sufficient to expose all the statistics to be accessible via one mbean? If so, you can collect the statistic in your aspect to a bean that looks like
    Code:
    class MethodStatistics {
      void incrementCount(String method);
      List<String> getMethods() {...}
      int getInvocationCount(String method);
    }
    All String arguments can be replaced with whatever class#method representation you want. You can then expose an mbean of the class with the two get methods. Of course this solution provides method counters on classes instead of beans (merges statistics of two beans of the same type).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •