FileDocCategorySizeDatePackage
AsynchronousAspect.javaAPI DocJBoss 4.2.13488Fri Jul 13 21:02:30 BST 2007org.jboss.aspects.asynchronous.aspects.jboss

AsynchronousAspect

public class AsynchronousAspect extends Object
author
{Claude Hussenet Independent Consultant}.
version
$Revision: 57186 $

Fields Summary
private AsynchronousInvokeTask
asynchronousInvokeTask
Constructors Summary
public AsynchronousAspect()


     
Methods Summary
public java.lang.Objectexecute(org.jboss.aop.joinpoint.MethodInvocation invocation)

      AsynchronousFacade asynchronousResult = null;
      if (invocation.getTargetObject() != null)
         asynchronousResult = (AsynchronousFacade) invocation.getTargetObject();
      else
      {
         Object[] tObject = invocation.getArguments();
         for (int i = 0; i < tObject.length; i++)
         {
            Object object = tObject[i];
            if (object instanceof AsynchronousFacade)
            {
               asynchronousResult = (AsynchronousFacade) object;
               break;
            }
         }
         if (asynchronousResult == null)
            asynchronousResult = new AsynchronousFacadeImpl();
      }
      Asynchronous asynchronous = (Asynchronous) AnnotationElement.getAnyAnnotation(invocation.getMethod(), Asynchronous.class);
      if (asynchronous!=null)
      {
      	if (asynchronousResult.getTimeout() == 0)
         asynchronousResult.setTimeout(asynchronous.timeout());

        if ((asynchronousResult.getId()!=null) && (asynchronousResult.getId().equals("None"))
       	                                       &&
       	              (asynchronous.id()!=null)&&(asynchronous.id().length()!=0) )
      	 asynchronousResult.setId(asynchronous.id());
	  }
      asynchronousResult.setAsynchronousTask(ThreadManagerFactory.getThreadManager().process(ThreadManagerFactory.createNewThreadManagerRequest(asynchronousResult.getId(),
      new InvokeTaskInputParameters((MethodInvocation) invocation.copy()),
      asynchronousInvokeTask,
      asynchronousResult.getTimeout())));
      Class returnType = invocation.getActualMethod().getReturnType();
      return Utils.returnInitObject(returnType);