KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ejb > container > JSessionSwitch


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JSessionSwitch.java,v 1.15 2005/04/28 16:52:59 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas_ejb.container;
27
28 import java.rmi.RemoteException JavaDoc;
29
30 import javax.transaction.Transaction JavaDoc;
31
32 import org.objectweb.jonas_timer.TimerEvent;
33 import org.objectweb.jonas_timer.TimerEventListener;
34 import org.objectweb.jonas_timer.TimerManager;
35
36 import org.objectweb.util.monolog.api.BasicLevel;
37
38 /**
39  * JSessionSwitch holds all the code that is common to EJBObject and
40  * EJBLocalObject for session beans. It mainly keep a reference on the
41  * SessionContext and is used to manage the timeout for the session. This class
42  * has 2 subclasses, depending if session is stateless or stateful.
43  * @author Philippe Durieux
44  */

45 public abstract class JSessionSwitch implements TimerEventListener {
46
47     protected JSessionFactory bf;
48
49     protected JSessionLocal local = null;
50
51     protected JSessionRemote remote = null;
52
53     protected TimerEvent mytimer = null;
54
55     /**
56      * constructor. a new object is build when the pool managed by
57      * JSessionFactory becomes empty.
58      * @param bf The Bean Factory
59      */

60     public JSessionSwitch(JSessionFactory bf) throws RemoteException JavaDoc {
61         if (TraceEjb.isDebugIc()) {
62             TraceEjb.interp.log(BasicLevel.DEBUG, "");
63         }
64         this.bf = bf;
65
66         // Create EJBObject if bean has a Remote Interface
67
if (bf.getHome() != null) {
68             remote = ((JSessionHome) bf.getHome()).createRemoteObject();
69             remote.setSessionSwitch(this);
70         }
71
72         // Create EJBLocalObject if bean has a Local Interface
73
if (bf.getLocalHome() != null) {
74             local = ((JSessionLocalHome) bf.getLocalHome()).createLocalObject();
75             local.setSessionSwitch(this);
76         }
77     }
78
79     /**
80      * @return the underlaying EJBLocalObject
81      */

82     public JSessionLocal getLocal() {
83         return local;
84     }
85
86     /**
87      * @return the underlaying EJBObject
88      */

89     public JSessionRemote getRemote() {
90         return remote;
91     }
92
93     /**
94      * @return the BeanFactory
95      */

96     public JSessionFactory getBeanFactory() {
97         return bf;
98     }
99
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, null, false);
109     }
110
111     /**
112      * Stop the Timer associated to the Session
113      */

114     public void stopTimer() {
115         if (TraceEjb.isDebugIc()) {
116             TraceEjb.interp.log(BasicLevel.DEBUG, "");
117         }
118         if (mytimer != null) {
119             mytimer.unset();
120         }
121     }
122
123     public abstract JSessionContext getICtx(Transaction JavaDoc tx) throws RemoteException JavaDoc;
124     public abstract void releaseICtx(Transaction JavaDoc tx);
125     public abstract void discardICtx(Transaction JavaDoc tx);
126     public abstract void setMustCommit(boolean mc);
127     public abstract void saveBeanTx();
128
129     public abstract void pushConnectionList();
130     public abstract void popConnectionList();
131     public abstract void enlistConnections(Transaction JavaDoc tx);
132     public abstract void delistConnections(Transaction JavaDoc tx);
133 }
134
135
Popular Tags