Announcement Announcement Module
Collapse
No announcement yet.
How to find methods matching pointcut at startup Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    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
    Any solution to this? I have a similar issue.

    Comment


    • #3
      Nope, I never found a solution.

      Comment


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

        Comment

        Working...
        X