FileDocCategorySizeDatePackage
AsynchAspect.javaAPI DocJBoss 4.2.14785Fri Jul 13 21:02:26 BST 2007org.jboss.aspects.asynch

AsynchAspect

public class AsynchAspect extends Object
Comment
author
Bill Burke
version
$Revision: 57186 $

Fields Summary
public static final String
FUTURE
private static org.jboss.util.id.GUID
futureClassGUID
private static Class[]
futureIntf
private static Class[]
futureDynamicIntf
private org.jboss.aop.Advisor
advisor
protected ExecutorAbstraction
executor
private boolean
generateFutureProxy
Constructors Summary
Methods Summary
public java.lang.Objectexecute(org.jboss.aop.joinpoint.MethodInvocation invocation)

      RemotableFuture future = executor.execute(invocation);

      InvokerLocator locator = (InvokerLocator) invocation.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR);

      // this is a remote invocation so just stuff the future within the response
      if (locator != null)
      {
         setupRemoteFuture(invocation, future, locator);
      }
      else
      {
         setupLocalFuture(invocation, future);
      }

      return NullOrZero.nullOrZero(invocation.getMethod().getReturnType());
   
protected booleangenerateProxy()
Default behaviour is to generate a proxy using aop. This can be overridden, e.g. by the EJB3 AsynchronousInterceptor to avoid dependencies on javassist for EJB3 clients

      return generateFutureProxy;
   
public org.jboss.aop.AdvisorgetAdvisor()

   
     
   
      return advisor;
   
public voidsetAdvisor(org.jboss.aop.Advisor advisor)

      this.advisor = advisor;
      Class executorClass = null;
      AsynchExecutor executorAnnotation = (AsynchExecutor) advisor.resolveAnnotation(AsynchExecutor.class);
      if (executorAnnotation == null)
      {
         executorClass = ThreadPoolExecutor.class;
      }
      else
      {
         executorClass = executorAnnotation.value();
      }

      try
      {
         executor = (ExecutorAbstraction) executorClass.newInstance();
      }
      catch (InstantiationException e)
      {
         throw new RuntimeException(e);
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);
      }
      executor.setAdvisor(advisor);

   
public voidsetGenerateDynamicProxy(boolean gen)

       this.generateFutureProxy = gen;
   
protected voidsetupLocalFuture(org.jboss.aop.joinpoint.MethodInvocation invocation, Future future)

      FutureHolder provider = (FutureHolder) invocation.getTargetObject();
      provider.setFuture(future);
      invocation.addResponseAttachment(FUTURE, future);
   
protected voidsetupRemoteFuture(org.jboss.aop.joinpoint.MethodInvocation invocation, RemotableFuture future, org.jboss.remoting.InvokerLocator locator)

      GUID futureGUID = new GUID();
      Dispatcher.singleton.registerTarget(futureGUID, future);
      InstanceAdvised ia = (generateProxy()) ? 
    		  ProxyFactory.createInterfaceProxy(futureClassGUID, Future.class.getClassLoader(), futureIntf) :
    		     (InstanceAdvised)FutureInvocationHandler.createFutureProxy(futureClassGUID, Future.class.getClassLoader(), futureDynamicIntf);
      Remoting.makeRemotable(ia, locator, futureGUID);
      future.setRemoteObjectID(futureGUID);
      invocation.addResponseAttachment(FUTURE, ia);