001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: JStatelessSwitch.java 8375 2006-05-19 07:31:06Z durieuxp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.container;
025:
026: import java.rmi.NoSuchObjectException;
027: import java.rmi.RemoteException;
028:
029: import javax.ejb.RemoveException;
030: import javax.transaction.Transaction;
031: import javax.xml.rpc.handler.MessageContext;
032:
033: import org.objectweb.jonas_timer.TraceTimer;
034: import org.objectweb.util.monolog.api.BasicLevel;
035:
036: /**
037: * JStatelessSwitch is the implementation of JSessionSwitch dedicated to the
038: * Stateless Session Bean.
039: * @author Philippe Durieux
040: */
041: public class JStatelessSwitch extends JSessionSwitch {
042:
043: /**
044: * Service Endpoint
045: */
046: private JServiceEndpoint se = null;
047:
048: /**
049: * Keep this object alive, because it is unique.
050: */
051: private boolean keepalive;
052:
053: /**
054: * constructor.
055: * @param bf The Bean Factory
056: * @throws RemoteException if the constructor fails
057: */
058: public JStatelessSwitch(JStatelessFactory bf)
059: throws RemoteException {
060: super (bf);
061: if (TraceEjb.isDebugIc()) {
062: TraceEjb.interp.log(BasicLevel.DEBUG, "");
063: }
064:
065: // Create ServiceEndpoint if defined in the bean descriptor
066: if (bf.getSEHome() != null) {
067: se = bf.getSEHome().createServiceEndpointObject();
068: se.setSessionSwitch(this );
069: }
070: keepalive = (bf.singleSwitchOn());
071: }
072:
073: // ===============================================================
074: // TimerEventListener implementation
075: // ===============================================================
076:
077: /**
078: * The session timeout has expired, or a Timer on this bean has expired.
079: * @param arg Not Used.
080: */
081: public synchronized void timeoutExpired(Object arg) {
082: if (TraceTimer.logger.isLoggable(BasicLevel.DEBUG)) {
083: TraceTimer.logger.log(BasicLevel.DEBUG,
084: "stateless session '" + bf.getEJBName()
085: + "' : timeout expired");
086: }
087: mytimer = null;
088: noLongerUsed();
089: }
090:
091: // ===============================================================
092: // other public methods
093: // ===============================================================
094:
095: /**
096: * @return The ServiceEndpoint
097: */
098: public JServiceEndpoint getServiceEndpoint() {
099: return se;
100: }
101:
102: /**
103: * @return The JAX-RPC MessageContext
104: */
105: public MessageContext getMsgContext() {
106: if (se == null) {
107: TraceEjb.logger.log(BasicLevel.ERROR,
108: "No ServiceEndpoint for this bean");
109: return null;
110: }
111: return se.getMessageContext();
112: }
113:
114: /**
115: * get an initialized Bean Context
116: * @param tx Current transaction (not used)
117: * @return the Session Context
118: * @throws RemoteException if context cannot be obtained
119: */
120: public JSessionContext getICtx(Transaction tx)
121: throws RemoteException {
122: if (TraceEjb.isDebugIc()) {
123: TraceEjb.interp.log(BasicLevel.DEBUG, "");
124: }
125: return (JStatelessContext) ((JStatelessFactory) bf)
126: .getJContext(this );
127: }
128:
129: /**
130: * release the bean context. Assumes that only 1 Context is managed at a
131: * time. Contexts are release at each request, in case of stateless session.
132: * @param tx Current transaction (not used)
133: */
134: public void releaseICtx(RequestCtx req, boolean discard) {
135: if (TraceEjb.isDebugIc()) {
136: TraceEjb.interp.log(BasicLevel.DEBUG, "");
137: }
138: JStatelessContext bctx = (JStatelessContext) req.ejbContext;
139: if (bctx == null) {
140: TraceEjb.interp.log(BasicLevel.WARN, "No ejbContext");
141: return;
142: }
143: if ((bctx.isMarkedRemoved() || discard) && !keepalive) {
144: stopTimer();
145: noLongerUsed();
146: }
147: ((JStatelessFactory) bf).releaseJContext(bctx);
148: }
149:
150: /**
151: * This Session is no longer used.
152: */
153: public void noLongerUsed() {
154: if (TraceEjb.isDebugIc()) {
155: TraceEjb.interp.log(BasicLevel.DEBUG, "");
156: }
157:
158: // Unexport the EJBObject from the Orb
159: if (myremote != null) {
160: try {
161: myremote.unexportObject();
162: } catch (NoSuchObjectException e) {
163: TraceEjb.logger.log(BasicLevel.ERROR, "exception", e);
164: }
165: }
166:
167: // return the SessionSwitch in the pool.
168: // will be reused for another Session.
169: bf.removeEJB(this );
170: }
171:
172: /**
173: * This is not used for stateless
174: * @param mc Not Used.
175: */
176: public void setMustCommit(boolean mc) {
177: }
178:
179: /**
180: * This is not used for stateless
181: */
182: public void pushConnectionList() {
183: }
184:
185: /**
186: * This is not used for stateless
187: */
188: public void popConnectionList() {
189: }
190:
191: /**
192: * This is not used for stateless
193: * @param tx the transaction object
194: */
195: public void enlistConnections(Transaction tx) {
196: }
197:
198: /**
199: * This is not used for stateless
200: * @param tx the transaction object
201: */
202: public void delistConnections(Transaction tx) {
203: }
204:
205: /**
206: * This do nothing for stateless
207: */
208: public void saveBeanTx() {
209: }
210: }
|