title: AOP interceptor to intercept all applications in same JVM
body: <p>I am wondering whether it is possible to <strong>intercept all calls</strong> to say javax.persistence.EntityManager.flush(), across all applications running in <strong>same JVM</strong> (such as Glassfish domain).</p>
  
  <p>Following not helping yet ;-(</p>
  
  <pre><code>@Aspect
  public class TraceAspect {
  
      @Pointcut("within(@(@javax.persistence.PersistenceContext *) *)")
      public void entityManagers() {
      }
  
      @Pointcut("execution(@javax.persistence.EntityManager *.merge) &amp;&amp; args(object)")
      public void merge(Object o) {
      }
  
      @Pointcut("execution(@javax.persistence.EntityManager *.createQuery) &amp;&amp; args(string)")
      public void createQuery(String s) {
      }
  
      @AfterReturning("entityManagers() &amp;&amp; merge(object)")
      public void afterMerge(JoinPoint joinPoint) {
          System.out.println(joinPoint);
      }
  
      @AfterReturning("entityManagers() &amp;&amp; createQuery(string)")
      public void afterCreateQuery(JoinPoint joinPoint) {
          System.out.println(joinPoint);
      }
  }
  </code></pre>