The aim of this AOP service is to achieve asynchronous method invocation to plain old JAVA object (POJO).
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(...){}
}
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
{...}
}
<?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>