Announcement Announcement Module
No announcement yet.
How to find methods matching pointcut at startup Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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:
    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:
    @Controller LoginController {
       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.
    @Aspect public class JmxTrackingAspect {
        public void incrementCount() {...}
    /** 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
    Any solution to this? I have a similar issue.


    • #3
      Nope, I never found a solution.


      • #4
        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
        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).