FileDocCategorySizeDatePackage
AsynchronousInterceptor.javaAPI DocJBoss 4.2.14812Fri Jul 13 20:53:54 BST 2007org.jboss.ejb3.asynchronous

AsynchronousInterceptor

public class AsynchronousInterceptor extends org.jboss.aspects.asynch.AsynchAspect implements org.jboss.aop.advice.Interceptor
author
Kabir Khan
version
$Revision: 57207 $

Fields Summary
private static final Logger
log
public static final String
ASYNCH
public static final String
INVOKE_ASYNCH
public static final String
FUTURE_HOLDER
Constructors Summary
public AsynchronousInterceptor()


    
   
      try
      {
         super.executor = (org.jboss.aspects.asynch.ExecutorAbstraction)ThreadPoolExecutor.class.newInstance();
      }
      catch (InstantiationException e)
      {
         throw new RuntimeException(e);
      }
      catch (IllegalAccessException e)
      {
         throw new RuntimeException(e);
      }
   
Methods Summary
protected booleangenerateProxy()
We don't want to generate proxies for ejb 3 clients, to avoid dependencies on javassist. Use a dynamic proxy to the future instead

      return false;
   
public java.lang.StringgetName()

      return "AsynchronousInterceptor";
   
public java.lang.Objectinvoke(org.jboss.aop.joinpoint.Invocation invocation)

      MethodInvocation mi = (MethodInvocation) invocation;

      if (invocation.getMetaData(ASYNCH, INVOKE_ASYNCH) != null)
      {
         //TODO This should maybe go somewhere nicer
         InvokerLocator locator = (InvokerLocator) invocation.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR);
         if (locator == null)
         {
            //We are a local invocation. Add security and current transaction info to the invocation
            // (for remote invocations this is done by the client side interceptors)
            TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
            if (tpcFactory != null)
            {
               Object tpc = tpcFactory.getTransactionPropagationContext();
               if (tpc != null)
               {
                  invocation.getMetaData().addMetaData(ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT,
                                                       ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT, tpc);
               }
            }

            Principal principal = SecurityAssociation.getPrincipal();
            if (principal != null) invocation.getMetaData().addMetaData("security", "principal", principal);

            Object credential = SecurityAssociation.getCredential();
            if (credential != null) invocation.getMetaData().addMetaData("security", "credential", credential);
         }

         return super.execute(mi);
      }
      return mi.invokeNext();
   
protected voidsetupLocalFuture(org.jboss.aop.joinpoint.MethodInvocation invocation, org.jboss.aspects.asynch.Future future)

      FutureHolder provider = (FutureHolder) invocation.getMetaData(ASYNCH, FUTURE_HOLDER);
      provider.setFuture(future);