1 22 package org.jboss.ejb3.stateless; 23 24 import org.jboss.aop.advice.Interceptor; 25 import org.jboss.aop.joinpoint.Invocation; 26 import org.jboss.ejb3.*; 27 import org.jboss.ejb3.stateful.StatefulInstanceInterceptor; 28 import org.jboss.ejb3.tx.Ejb3TxPolicy; 29 import org.jboss.logging.Logger; 30 31 import javax.ejb.EJBException ; 32 import java.rmi.RemoteException ; 33 34 40 public class StatelessInstanceInterceptor implements Interceptor 41 { 42 private static final Logger log = Logger.getLogger(StatelessInstanceInterceptor.class); 43 44 public String getName() 45 { 46 return "StatelessInstanceInterceptor"; 47 } 48 49 public Object invoke(Invocation invocation) throws Throwable 50 { 51 EJBContainerInvocation ejb = (EJBContainerInvocation) invocation; 52 EJBContainer container = (EJBContainer)ejb.getAdvisor(); 53 Pool pool = container.getPool(); 54 BeanContext ctx = pool.get(); 55 ejb.setTargetObject(ctx.getInstance()); 56 ejb.setBeanContext(ctx); 57 58 boolean discard = false; 59 60 try 61 { 62 return ejb.invokeNext(); 63 } 64 catch (Exception ex) 65 { 66 discard = (ex instanceof EJBException ) || 67 ((ex instanceof RuntimeException || ex instanceof RemoteException ) && !StatefulInstanceInterceptor.isApplicationException(ex.getClass(), container)); 68 throw ex; 69 } 70 finally 71 { 72 ejb.setTargetObject(null); 73 ejb.setBeanContext(null); 74 if (discard) pool.discard(ctx); 75 else pool.release(ctx); 76 } 77 } 78 } 79 | Popular Tags |