1 22 package org.jboss.ejb3.asynchronous; 23 24 import java.security.Principal ; 25 import org.jboss.aop.advice.Interceptor; 26 import org.jboss.aop.joinpoint.Invocation; 27 import org.jboss.aop.joinpoint.MethodInvocation; 28 import org.jboss.aspects.asynch.AsynchAspect; 29 import org.jboss.aspects.asynch.Future; 30 import org.jboss.aspects.asynch.FutureHolder; 31 import org.jboss.aspects.asynch.ThreadPoolExecutor; 32 import org.jboss.aspects.remoting.InvokeRemoteInterceptor; 33 import org.jboss.aspects.tx.ClientTxPropagationInterceptor; 34 import org.jboss.logging.Logger; 35 import org.jboss.remoting.InvokerLocator; 36 import org.jboss.security.SecurityAssociation; 37 import org.jboss.tm.TransactionPropagationContextFactory; 38 import org.jboss.tm.TransactionPropagationContextUtil; 39 40 41 45 public class AsynchronousInterceptor extends AsynchAspect implements Interceptor 46 { 47 private static final Logger log = Logger.getLogger(AsynchronousInterceptor.class); 48 49 public static final String ASYNCH = "ASYNCH"; 50 public static final String INVOKE_ASYNCH = "INVOKE_ASYNCH"; 51 public static final String FUTURE_HOLDER = "FUTURE_HOLDER"; 52 53 public AsynchronousInterceptor() 54 { 55 try 56 { 57 super.executor = (org.jboss.aspects.asynch.ExecutorAbstraction)ThreadPoolExecutor.class.newInstance(); 58 } 59 catch (InstantiationException e) 60 { 61 throw new RuntimeException (e); 62 } 63 catch (IllegalAccessException e) 64 { 65 throw new RuntimeException (e); 66 } 67 } 68 69 public String getName() 70 { 71 return "AsynchronousInterceptor"; 72 } 73 74 public Object invoke(Invocation invocation) throws Throwable 75 { 76 MethodInvocation mi = (MethodInvocation) invocation; 77 78 if (invocation.getMetaData(ASYNCH, INVOKE_ASYNCH) != null) 79 { 80 InvokerLocator locator = (InvokerLocator) invocation.getMetaData(InvokeRemoteInterceptor.REMOTING, InvokeRemoteInterceptor.INVOKER_LOCATOR); 82 if (locator == null) 83 { 84 TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide(); 87 if (tpcFactory != null) 88 { 89 Object tpc = tpcFactory.getTransactionPropagationContext(); 90 if (tpc != null) 91 { 92 invocation.getMetaData().addMetaData(ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT, 93 ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT, tpc); 94 } 95 } 96 97 Principal principal = SecurityAssociation.getPrincipal(); 98 if (principal != null) invocation.getMetaData().addMetaData("security", "principal", principal); 99 100 Object credential = SecurityAssociation.getCredential(); 101 if (credential != null) invocation.getMetaData().addMetaData("security", "credential", credential); 102 } 103 104 return super.execute(mi); 105 } 106 return mi.invokeNext(); 107 } 108 109 protected void setupLocalFuture(MethodInvocation invocation, Future future) 111 { 112 FutureHolder provider = (FutureHolder) invocation.getMetaData(ASYNCH, FUTURE_HOLDER); 113 provider.setFuture(future); 114 } 115 116 120 protected boolean generateProxy() 122 { 123 return false; 124 } 125 126 127 } 128 | Popular Tags |