AOP Asynchronous Method Invocation

This aspect can run outside of JBoss application server

Goal

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

Features

Example

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 (timeout=5000)*/ 
	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
{...}
}

Implementation

Few pointers regarding the implementation . The implementation is broken down in 4 components :

/org/jboss/aspects/asynchronous\\ /org/jboss/aspects/asynchronous/common\\

/org/jboss/aspects/asynchronous/concurrent\\

/org/jboss/aspects/asynchronous/aspects\\

/org/jboss/aspects/asynchronus/aspects/jboss\\ The Asynchronous Aspect is composed of one Mixin class (AsynchronousFacade.java) and one method interceptor.(AsynchronousAspect.java)

Configuration

If not running within JBoss you'll need this binding:
<?xml version="1.0" encoding="UTF-8"?>
<aop>

<aspect class="org.jboss.aspects.asynchronous.aspects.jboss.AsynchronousAspect" scope="PER_VM"/>
   
<bind pointcut="execution(* *->@org.jboss.aspects.asynchronous.aspects.jboss.Asynchronous(..))">
   <advice name="execute" aspect="org.jboss.aspects.asynchronous.aspects.jboss.AsynchronousAspect"/>
</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>

Author