001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2004 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: JSessionSwitch.java 7933 2006-01-25 15:15:08Z durieuxp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas_ejb.container;
025:
026: import java.rmi.RemoteException;
027:
028: import javax.transaction.Transaction;
029:
030: import org.objectweb.jonas_timer.TimerEvent;
031: import org.objectweb.jonas_timer.TimerEventListener;
032: import org.objectweb.jonas_timer.TimerManager;
033:
034: import org.objectweb.util.monolog.api.BasicLevel;
035:
036: /**
037: * JSessionSwitch holds all the code that is common to EJBObject and
038: * EJBLocalObject for session beans. It mainly keep a reference on the
039: * SessionContext and is used to manage the timeout for the session. This class
040: * has 2 subclasses, depending if session is stateless or stateful.
041: * @author Philippe Durieux
042: */
043: public abstract class JSessionSwitch implements TimerEventListener {
044:
045: protected JSessionFactory bf;
046:
047: protected JSessionLocal mylocal = null;
048:
049: protected JSessionRemote myremote = null;
050:
051: protected TimerEvent mytimer = null;
052:
053: /**
054: * constructor. a new object is build when the pool managed by
055: * JSessionFactory becomes empty.
056: * @param bf The Bean Factory
057: */
058: public JSessionSwitch(JSessionFactory bf) throws RemoteException {
059: if (TraceEjb.isDebugIc()) {
060: TraceEjb.interp.log(BasicLevel.DEBUG, "");
061: }
062: this .bf = bf;
063:
064: // Create EJBObject if bean has a Remote Interface
065: if (bf.getHome() != null) {
066: myremote = ((JSessionHome) bf.getHome())
067: .createRemoteObject();
068: myremote.setSessionSwitch(this );
069: }
070:
071: // Create EJBLocalObject if bean has a Local Interface
072: if (bf.getLocalHome() != null) {
073: mylocal = ((JSessionLocalHome) bf.getLocalHome())
074: .createLocalObject();
075: mylocal.setSessionSwitch(this );
076: }
077: }
078:
079: /**
080: * @return the underlaying EJBLocalObject
081: */
082: public JSessionLocal getLocal() {
083: return mylocal;
084: }
085:
086: /**
087: * @return the underlaying EJBObject
088: */
089: public JSessionRemote getRemote() {
090: return myremote;
091: }
092:
093: /**
094: * @return the BeanFactory
095: */
096: public JSessionFactory getBeanFactory() {
097: return bf;
098: }
099:
100: /**
101: * Start a timer for this Session.
102: * @param timeout nb of milliseconds max this Session should live.
103: */
104: public void startTimer(int timeout) {
105: if (TraceEjb.isDebugIc()) {
106: TraceEjb.interp.log(BasicLevel.DEBUG, "");
107: }
108: mytimer = TimerManager.getInstance().addTimerMs(this , timeout,
109: null, false);
110: }
111:
112: /**
113: * Stop the Timer associated to the Session
114: */
115: public void stopTimer() {
116: if (TraceEjb.isDebugIc()) {
117: TraceEjb.interp.log(BasicLevel.DEBUG, "");
118: }
119: if (mytimer != null) {
120: mytimer.unset();
121: mytimer = null;
122: }
123: }
124:
125: public abstract JSessionContext getICtx(Transaction tx)
126: throws RemoteException;
127:
128: public abstract void releaseICtx(RequestCtx req, boolean discard);
129:
130: public abstract void setMustCommit(boolean mc);
131:
132: public abstract void saveBeanTx();
133:
134: public abstract void pushConnectionList();
135:
136: public abstract void popConnectionList();
137:
138: public abstract void enlistConnections(Transaction tx);
139:
140: public abstract void delistConnections(Transaction tx);
141:
142: public abstract void noLongerUsed();
143: }
|