1 25 26 package org.objectweb.jonas_ejb.container; 27 28 import java.rmi.RemoteException ; 29 import java.util.List ; 30 31 import javax.ejb.RemoveException ; 32 import javax.ejb.SessionBean ; 33 import javax.ejb.SessionSynchronization ; 34 import javax.ejb.TimerService ; 35 import javax.naming.Context ; 36 import javax.naming.NamingException ; 37 import javax.transaction.Status ; 38 import javax.transaction.Synchronization ; 39 import javax.xml.rpc.handler.MessageContext ; 40 41 import org.objectweb.jonas.naming.NamingManager; 42 import org.objectweb.jonas_lib.naming.ContainerNaming; 43 import org.objectweb.util.monolog.api.BasicLevel; 44 45 49 public class JStatefulContext extends JSessionContext implements Synchronization { 50 51 55 boolean synchro = false; 56 57 boolean timedout = false; 58 59 63 69 public JStatefulContext(JSessionFactory bf, SessionBean sb, boolean sync) { 70 super(bf, sb); 71 if (TraceEjb.isDebugIc()) { 72 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 73 } 74 synchro = sync; 75 try { 77 ContainerNaming naming = NamingManager.getInstance(); 78 Context c = naming.getComponentContext(); 79 c.rebind("MY_SF_CONTEXT", this); 80 } catch (NamingException ne) { 81 TraceEjb.logger.log(BasicLevel.ERROR, "Cannot bind EJBContext", ne); 82 } 83 } 84 85 89 public void setInstance(SessionBean sb) { 90 instance = sb; 91 } 92 93 97 103 public TimerService getTimerService() throws IllegalStateException { 104 throw new IllegalStateException ("getTimerService Not Allowed on Stateful Session Beans"); 105 } 106 107 113 public MessageContext getMessageContext() throws java.lang.IllegalStateException { 114 throw new IllegalStateException ("getMessageContext Not Allowed on Stateful Session Beans"); 115 } 116 117 121 126 public void beforeCompletion() { 127 if (TraceEjb.isDebugTx()) { 128 TraceEjb.tx.log(BasicLevel.DEBUG, ""); 129 } 130 131 if (synchro) { 132 ClassLoader old = Thread.currentThread().getContextClassLoader(); 134 Thread.currentThread().setContextClassLoader(bf.myClassLoader()); 135 Context bnctx = bf.setComponentContext(); 136 try { 137 SessionSynchronization ss = (SessionSynchronization ) getInstance(); 138 ss.beforeCompletion(); 139 } catch (RemoteException e) { 140 TraceEjb.logger.log(BasicLevel.ERROR, "exception:", e); 141 } finally { 142 bf.resetComponentContext(bnctx); 143 Thread.currentThread().setContextClassLoader(old); 144 } 145 } 146 } 147 148 154 public void afterCompletion(int status) { 155 if (TraceEjb.isDebugTx()) { 156 TraceEjb.tx.log(BasicLevel.DEBUG, ""); 157 } 158 159 if (synchro) { 160 ClassLoader old = Thread.currentThread().getContextClassLoader(); 162 Thread.currentThread().setContextClassLoader(bf.myClassLoader()); 163 Context bnctx = bf.setComponentContext(); 164 try { 165 SessionSynchronization ss = (SessionSynchronization ) getInstance(); 166 setState(3); 167 ss.afterCompletion(status == Status.STATUS_COMMITTED); 168 setState(2); 169 } catch (RemoteException e) { 170 TraceEjb.logger.log(BasicLevel.ERROR, "exception:", e); 171 } finally { 172 bf.resetComponentContext(bnctx); 173 Thread.currentThread().setContextClassLoader(old); 174 } 175 } 176 177 JStatefulSwitch jss = (JStatefulSwitch) bs; 181 jss.txCompleted(); 182 183 if (timedout) { 186 TraceEjb.logger.log(BasicLevel.WARN, "timeout expired during the transaction"); 187 timedout = false; 188 } 191 } 192 193 197 200 public void setRemoved() throws RemoteException , RemoveException { 201 if (TraceEjb.isDebugIc()) { 202 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 203 } 204 205 JStatefulSwitch jss = (JStatefulSwitch) bs; 207 if (jss.isInTransaction()) { 208 throw new RemoveException ("Cannot remove a statefull session inside a transaction"); 209 } 210 211 SessionBean sb = (SessionBean ) instance; 216 sb.ejbRemove(); 217 218 ismarkedremoved = true; 222 } 223 224 227 public void setConnectionList(List conlist) { 228 JStatefulSwitch jss = (JStatefulSwitch) bs; 229 jss.setConnectionList(conlist); 230 } 231 232 } 233 | Popular Tags |