title: Knowing caller class with AspectJ
body: <p>I'm trying to imitate Spring's <a href="http://static.springsource.org/spring/docs/3.0.0.RELEASE/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-async" rel="nofollow">AspectJ @Async support</a> but with a message bus.</p>
  
  <p>The issue is I need to know if my Message Bus (RabbitMQ MessageListener) is calling the method  or a normal (all others) caller where the method will return instantly.</p>
  
  <p><em>My annotation is called @MQAsync instead of Springs @Async.</em></p>
  
  <pre><code>package com.snaphop.mqueue;
  
  import org.apache.log4j.Logger;
  import com.snaphop.mqueue.MQAsync;
  
  public aspect MQAsyncAspect {
  
      //pointcut asyncTypeMarkedMethod() : execution(@MQAsync void *(..));
      pointcut asyncTypeMarkedMethod() : call(@MQAsync void *(..));
  
      private static final Logger log = Logger.getLogger("MQAsync");
  
      Object around() : asyncTypeMarkedMethod() {     
          if (listenerIsCaller) {
              return proceed();
          }
          //Send the method parameters to the message bus.
          //this logic isn't here for brevity.
          return null;
      }
  }
  </code></pre>
  
  <p>The <em>call</em> pointcut will get me the caller context but that will not work as I will be calling the method with my message listener through reflection. The <em>execution</em> pointcut (commented out) will not tell me who is calling the method.</p>
  
  <p><strong>Is there a way to determine the caller class maybe through some sort of stack dump analysis?</strong></p>