Version 20

    AOP Asynchronous Method Invocation

    This aspect can run outside of JBoss application server

     

    It was tested using JDK 1.4 in Weblogic 8.1,Tomcat 5.0.27 ,Orion 2.0.2 and Resin 3.0.4.

     

    Goal

     

    The aim of this AOP service is to achieve asynchronous method invocation to plain old JAVA object (POJO).

     

    Features

     

    • Implemented as a standalone service (can run outside of JBOSS).

    • Ability to define Asynchronous method declaration in XML or using JDK1.5 annotations.

    • Support ONEWAY and REQUEST/REPLY asynchronous method invocation.

    • Support of instance and static asynchronous method invocation.

    • Support of public, protected, private and package method.

    • Support of concurrent invocation on same instance/static method.

    • Ability to define Timeout value for duration of asynchronous method execution.

    • Thread pooling Management (Min/Max threads, keep-alive, abort/wait policy)

     

    Usage

     

    POJO implementation using JDK1.4 or JDK1.5 annotations for Asynchronous method declaration. For JDK 1.4 you need the AnnotationCompiler

     

    JDK 1.4

    public class POJO {
    
    /** @@org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous  */
         public void processBusinessModel(){...}
    
    /** @@org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous */ 
         public long processBusinessModel(...){}
     
    }
    

     

    JDK 5.0

    import org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous;
    
    public class POJO {
         public void processBusinessModel(){...}
    
            @Asynchronous
         public long processBusinessModel(...){}
     
    }
    

     

    Asynchronous Method Invocation and result process within same thread of execution

     

    POJO pojo = new POJO(...);
    

    / Asynchronous Method Invocation /

    long result=pojo.processBusinessModel(...);
    ...
    ...
    

    / non-blocking call /

    if (((AsynchronousFacade)pojo).isDone())
    {
    AsynchronousFacade aF=(AsynchronousFacade)pojo;
    
    

    / Test response code returned /

    if (aF.getResponseCode()==OK)
    

    / get method response processed asynchronously /

    result = ((Long)aF.getReturnValue()).longValue();
    

    / Test if method timed out /

    else if (aF.getResponseCode()==TIMEOUT)
    {...}
    else
    ... 
    }
    
    else {
    

    / blocking call /

    AsynchronousResponse aR = ((AsynchronousFacade)pojo).waitForResponse();
    If (aR.getResponseCode()==OK)
    

    / get method response processed asynchronously /

    result=((Long)aR.getReturnValue()).longValue();
    

    / Test if method timed out /

    else if (aR.getReponseCode()==TIMEOUT)
    {...}
    else
    {...}
    }
    

     

    Configuration

    If not running within JBoss, you'll need a binding like this:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <aop>
      <aspect class="org.jboss.aspects.asynchronous.aspects.jboss.AsynchronousAspect" scope="PER_VM"></aspect>
       
      <bind pointcut="execution(* *->@org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous(..))">
         <advice name="execute" aspect="org.jboss.aspects.asynchronous.aspects.jboss.AsynchronousAspect"></advice>
      </bind>                                                                                
    <introduction expr="has(* *->@org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous(..)) OR class(@org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous)">
         <mixin>
            <interfaces>org.jboss.aspects.asynchronous.aspects.AsynchronousFacade</interfaces>
            <class>org.jboss.aspects.asynchronous.aspects.AsynchronousFacadeImpl</class>
            <construction>new org.jboss.aspects.asynchronous.aspects.AsynchronousFacadeImpl()</construction>
         </mixin>
      </introduction>  
    </aop>
    
    • If running JBoss AOP 1.5.0.GA or above:

    <?xml version="1.0" encoding="UTF-8"?>
    <aop>
       <aspect class="org.jboss.aspects.asynch.AsynchAspect" scope="PER_INSTANCE">
          <advisor-attribute name="Advisor"></advisor-attribute>
       </aspect>
    
       <bind pointcut="execution(!static * *->@org.jboss.aspects.asynch.Asynchronous(..))">
          <advice name="execute" aspect="org.jboss.aspects.asynch.AsynchAspect"></advice>
       </bind>
    
       <introduction expr="has(!static * *->@org.jboss.aspects.asynch.Asynchronous(..))">
          <mixin>
             <interfaces>org.jboss.aspects.asynch.AsynchProvider,org.jboss.aspects.asynch.FutureHolder</interfaces>
             <class>org.jboss.aspects.asynch.AsynchMixin</class>
          </mixin>
       </introduction>
    </aop>
    

     

    Set up

     

    Before building the final deployable archive, an instrumentation (aopc) phase is required using the binding in previous section so that pojos that might have @Asynchronous annotation are instrumented. You can further information on different options to instrument classes in the the AOP documentation

     

    Example

     

    Please find attached a Asynchronous pojo example which contains a README file explaining the example including how to deploy it and run it.

     

    Note: To run the attached example, JBoss AS/EAP 4.2 or higher is required.

     

    Implementation

    Few pointers regarding the implementation .

          

    The implementation is broken down in 4 components :

     

    • Asynchronous Engine Definition

     

      /org/jboss/aspects/asynchronous

     

      /org/jboss/aspects/asynchronous/common

     

     

    • Asynchronous Engine Implementation with the concurrent package

     

      /org/jboss/aspects/asynchronous/concurrent

     

     

    • Asynchronous Facade Definition and Implementation (Mixin Class)

     

      /org/jboss/aspects/asynchronous/aspects

     

     

    • Asynchronous Aspect Implementation with JBOSS-AOP

     

      /org/jboss/aspects/asynchronus/aspects/jboss

     

               

      The Asynchronous Aspect is composed of one Mixin class (AsynchronousFacade.java)

    and one method interceptor.(AsynchronousAspect.java)

                

    Author