1 22 package org.jboss.ejb.plugins; 23 24 import org.jboss.ejb.EnterpriseContext; 25 import org.jboss.ejb.InstancePool; 26 import org.jboss.ejb.MessageDrivenContainer; 27 import org.jboss.ejb.AllowedOperationsAssociation; 28 import org.jboss.invocation.Invocation; 29 30 import javax.ejb.EJBException ; 31 import javax.ejb.TimedObject ; 32 import javax.ejb.Timer ; 33 import java.rmi.RemoteException ; 34 import java.lang.reflect.Method ; 35 36 46 public class MessageDrivenInstanceInterceptor 47 extends AbstractInterceptor 48 { 49 50 51 protected static final Method ejbTimeout; 52 static 53 { 54 try 55 { 56 ejbTimeout = TimedObject .class.getMethod("ejbTimeout", new Class []{Timer .class}); 57 } 58 catch (Exception e) 59 { 60 throw new ExceptionInInitializerError (e); 61 } 62 } 63 64 69 public Object invokeHome(final Invocation mi) 70 throws Exception 71 { 72 throw new Error ("Not valid for MessageDriven beans"); 73 } 74 75 77 public Object invoke(final Invocation mi) 78 throws Exception 79 { 80 MessageDrivenContainer mdc = (MessageDrivenContainer) container; 82 InstancePool pool = mdc.getInstancePool(); 83 EnterpriseContext ctx = null; 84 try 85 { 86 ctx = pool.get(); 87 } 88 catch (EJBException e) 89 { 90 throw e; 91 } 92 catch (Exception e) 93 { 94 throw new EJBException ("Unable to get an instance from the pool", e); 95 } 96 97 ctx.setPrincipal(mi.getPrincipal()); 99 100 mi.setEnterpriseContext(ctx); 102 EnterpriseBeanPolicyContextHandler.setEnterpriseBean(ctx.getInstance()); 104 105 if (ejbTimeout.equals(mi.getMethod())) 106 AllowedOperationsAssociation.pushInMethodFlag(IN_EJB_TIMEOUT); 107 else 108 AllowedOperationsAssociation.pushInMethodFlag(IN_BUSINESS_METHOD); 109 110 try 113 { 114 Object obj = getNext().invoke(mi); 116 return obj; 117 } 118 catch (RuntimeException e) { 120 mi.setEnterpriseContext(null); 121 throw e; 122 } 123 catch (RemoteException e) { 125 mi.setEnterpriseContext(null); 126 throw e; 127 } 128 catch (Error e) { 130 mi.setEnterpriseContext(null); 131 throw e; 132 } 133 finally 134 { 135 AllowedOperationsAssociation.popInMethodFlag(); 136 137 if (mi.getEnterpriseContext() != null) 139 { 140 pool.free((EnterpriseContext) mi.getEnterpriseContext()); 141 } 142 else 143 { 144 pool.discard(ctx); 145 } 146 } 147 } 148 149 } 150 151 | Popular Tags |