JStatelessSwitch.java

00001 
00026 package org.objectweb.jonas_ejb.container;
00027 
00028 import java.rmi.NoSuchObjectException;
00029 import java.rmi.RemoteException;
00030 
00031 import javax.ejb.RemoveException;
00032 import javax.transaction.SystemException;
00033 import javax.transaction.Transaction;
00034 import javax.xml.rpc.handler.MessageContext;
00035 
00036 import org.objectweb.util.monolog.api.BasicLevel;
00037 
00043 public class JStatelessSwitch extends JSessionSwitch {
00044 
00045     private JStatelessContext bctx = null;
00046     
00047     private JServiceEndpoint se = null;
00048 
00053     public JStatelessSwitch(JStatelessFactory bf) throws RemoteException {
00054         super(bf);
00055         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00056         
00057         // Create ServiceEndpoint if defined in the bean descriptor
00058         if (bf.getSEHome() != null) {
00059             se = ((JServiceEndpointHome) bf.getSEHome()).createServiceEndpointObject();
00060             se.setSessionSwitch(this);
00061         }
00062     }
00063 
00064     // ===============================================================
00065     // TimerEventListener implementation
00066     // ===============================================================
00067 
00072     public synchronized void timeoutExpired(Object arg) {
00073         TraceEjb.logger.log(BasicLevel.WARN, "stateless session timeout expired");
00074         mytimer = null;
00075         if (bctx != null) {
00076             try {
00077                 bctx.setRemoved();
00078                 ((JStatelessFactory) bf).releaseJContext(bctx);
00079                 bctx = null;
00080             } catch (RemoteException e) {
00081                 TraceEjb.logger.log(BasicLevel.WARN, "timeout expired:" + e);
00082             } catch (RemoveException e) {
00083                 TraceEjb.logger.log(BasicLevel.WARN, "timeout expired:" + e);
00084             }
00085         }
00086         noLongerUsed();
00087     }
00088 
00089     // ===============================================================
00090     // other public methods
00091     // ===============================================================
00092 
00096     public JServiceEndpoint getServiceEndpoint() {
00097         return se;
00098     }
00099     
00103     public MessageContext getMsgContext() {
00104         if (se == null) {
00105             TraceEjb.logger.log(BasicLevel.ERROR, "No ServiceEndpoint for this bean");
00106             return null;
00107         }
00108         return se.getMessageContext();
00109     }
00110     
00116     public JSessionContext getICtx(Transaction tx) throws RemoteException {
00117         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00118         bctx = (JStatelessContext) ((JStatelessFactory) bf).getJContext(this);
00119         return bctx;
00120     }
00121 
00127     public void releaseICtx(Transaction tx) {
00128         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00129 
00130         if (bctx == null) {
00131             return;
00132         }
00133         if (bctx.isMarkedRemoved()) {
00134             stopTimer();
00135             noLongerUsed();
00136         }
00137         ((JStatelessFactory) bf).releaseJContext(bctx);
00138         bctx = null;
00139     }
00140 
00146     public void discardICtx(Transaction tx) {
00147         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00148 
00149         // In case getICtx failed, bctx may be null.
00150         if (bctx == null) {
00151             return;
00152         }
00153 
00154         stopTimer();
00155         noLongerUsed();
00156 
00157         ((JStatelessFactory) bf).releaseJContext(bctx);
00158         bctx = null;
00159 
00160     }
00161 
00165     public void noLongerUsed() {
00166         TraceEjb.interp.log(BasicLevel.DEBUG, "");
00167 
00168         // Unexport the EJBObject from the Orb
00169         if (remote != null) {
00170             try {
00171                 remote.unexportObject();
00172             } catch (NoSuchObjectException e) {
00173                 TraceEjb.logger.log(BasicLevel.ERROR, "exception: " + e);
00174             }
00175         }
00176 
00177         // return the SessionSwitch in the pool.
00178         // will be reused for another Session.
00179         bf.removeEJB(this);
00180     }
00181 
00186     public void setMustCommit(boolean mc) {
00187     }
00188 
00192     public void pushConnectionList() {
00193     }
00194 
00198     public void popConnectionList() {
00199     }
00200 
00204     public void enlistConnections(Transaction tx) {
00205     }
00209     public void delistConnections(Transaction tx) {
00210     }
00214     public void saveBeanTx() {
00215     }
00216 }

Generated on Tue Feb 15 15:05:43 2005 for JOnAS by  doxygen 1.3.9.1