Source Code Cross Referenced for JStatefulContext.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_ejb » container » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_ejb.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 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: JStatefulContext.java 7525 2005-10-19 10:43:24Z durieuxp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas_ejb.container;
025:
026:        import java.rmi.RemoteException;
027:        import java.util.List;
028:
029:        import javax.ejb.RemoveException;
030:        import javax.ejb.SessionBean;
031:        import javax.ejb.SessionSynchronization;
032:        import javax.ejb.TimerService;
033:        import javax.naming.Context;
034:        import javax.naming.NamingException;
035:        import javax.transaction.Status;
036:        import javax.transaction.Synchronization;
037:        import javax.xml.rpc.handler.MessageContext;
038:
039:        import org.objectweb.jonas.naming.NamingManager;
040:        import org.objectweb.jonas_lib.naming.ContainerNaming;
041:        import org.objectweb.util.monolog.api.BasicLevel;
042:
043:        /**
044:         * This class extends JSessionContext in case of Stateful Session Bean.
045:         * @author Philippe Coq, Philippe Durieux
046:         */
047:        public class JStatefulContext extends JSessionContext implements 
048:                Synchronization {
049:
050:            /**
051:             * the bean instance implements SessionSynchronization interface
052:             * @serial
053:             */
054:            boolean synchro = false;
055:
056:            boolean timedout = false;
057:
058:            // ------------------------------------------------------------------
059:            // constructors
060:            // ------------------------------------------------------------------
061:
062:            /**
063:             * Constructs a JStatefulContext
064:             * @param bf - the Session Factory
065:             * @param sb - the Enterprise Bean instance
066:             * @param sync - True if implements SessionSymchronization.
067:             */
068:            public JStatefulContext(JSessionFactory bf, SessionBean sb,
069:                    boolean sync) {
070:                super (bf, sb);
071:                if (TraceEjb.isDebugIc()) {
072:                    TraceEjb.interp.log(BasicLevel.DEBUG, "");
073:                }
074:                synchro = sync;
075:                // Register this Context in java:comp (used by JTimerHandle)
076:                try {
077:                    ContainerNaming naming = NamingManager.getInstance();
078:                    Context c = naming.getComponentContext();
079:                    c.rebind("MY_SF_CONTEXT", this );
080:                } catch (NamingException ne) {
081:                    TraceEjb.logger.log(BasicLevel.ERROR,
082:                            "Cannot bind EJBContext", ne);
083:                }
084:            }
085:
086:            /**
087:             * set instance. Used for passivation/activation.
088:             * @param sb
089:             */
090:            public void setInstance(SessionBean sb) {
091:                TraceEjb.logger.log(BasicLevel.DEBUG, "Set to " + sb);
092:                myinstance = sb;
093:            }
094:
095:            // ------------------------------------------------------------------
096:            // EJBContext implementation
097:            // ------------------------------------------------------------------
098:
099:            /**
100:             * Get access to the EJB Timer Service.
101:             * @return the EJB Timer Service
102:             * @throws IllegalStateException Thrown if the instance is not allowed to
103:             *         use this method
104:             */
105:            public TimerService getTimerService() throws IllegalStateException {
106:                throw new IllegalStateException(
107:                        "getTimerService Not Allowed on Stateful Session Beans");
108:            }
109:
110:            /**
111:             * Obtain a reference to the JAX-RPC MessageContext.
112:             * @return The MessageContext for this web service invocation.
113:             * @throws java.lang.IllegalStateException - the instance is in a state that
114:             *         does not allow access to this method.
115:             */
116:            public MessageContext getMessageContext()
117:                    throws java.lang.IllegalStateException {
118:                throw new IllegalStateException(
119:                        "getMessageContext Not Allowed on Stateful Session Beans");
120:            }
121:
122:            // -------------------------------------------------------------------
123:            // Synchronization implementation
124:            // -------------------------------------------------------------------
125:
126:            /**
127:             * This beforeCompletion method is called by the transaction manager prior
128:             * to the start of the transaction completion process. This method executes
129:             * in the transaction context of the calling thread.
130:             */
131:            public void beforeCompletion() {
132:                if (TraceEjb.isDebugTx()) {
133:                    TraceEjb.tx.log(BasicLevel.DEBUG, "");
134:                }
135:
136:                if (synchro) {
137:                    // Set classloader for getting the right component context
138:                    ClassLoader old = Thread.currentThread()
139:                            .getContextClassLoader();
140:                    Thread.currentThread().setContextClassLoader(
141:                            bf.myClassLoader());
142:                    Context bnctx = bf.setComponentContext();
143:                    try {
144:                        SessionSynchronization ss = (SessionSynchronization) getInstance();
145:                        ss.beforeCompletion();
146:                    } catch (RemoteException e) {
147:                        TraceEjb.logger.log(BasicLevel.ERROR, "exception:", e);
148:                    } finally {
149:                        bf.resetComponentContext(bnctx);
150:                        Thread.currentThread().setContextClassLoader(old);
151:                    }
152:                }
153:            }
154:
155:            /**
156:             * The afterCompletion method is called by the transaction manager after the
157:             * transaction is committed or rolled back. This method executes without a
158:             * transaction context.
159:             * @param status The status of the transaction completion.
160:             */
161:            public void afterCompletion(int status) {
162:                if (TraceEjb.isDebugTx()) {
163:                    TraceEjb.tx.log(BasicLevel.DEBUG, "");
164:                }
165:
166:                if (synchro) {
167:                    // Set classloader for getting the right component context
168:                    ClassLoader old = Thread.currentThread()
169:                            .getContextClassLoader();
170:                    Thread.currentThread().setContextClassLoader(
171:                            bf.myClassLoader());
172:                    Context bnctx = bf.setComponentContext();
173:                    try {
174:                        SessionSynchronization ss = (SessionSynchronization) getInstance();
175:                        setState(3);
176:                        ss.afterCompletion(status == Status.STATUS_COMMITTED);
177:                        setState(2);
178:                    } catch (RemoteException e) {
179:                        TraceEjb.logger.log(BasicLevel.ERROR, "exception:", e);
180:                    } finally {
181:                        bf.resetComponentContext(bnctx);
182:                        Thread.currentThread().setContextClassLoader(old);
183:                    }
184:                }
185:
186:                // Let the StatefulSwitch now that transaction is over and that it can
187:                // now dispose of this Context for another transaction.
188:                // no need to be in the correct component context ?
189:                JStatefulSwitch jss = (JStatefulSwitch) bs;
190:                jss.txCompleted();
191:
192:                // The timeout has expired during the transaction. We can now remove
193:                // this session.
194:                if (timedout) {
195:                    TraceEjb.logger.log(BasicLevel.WARN,
196:                            "timeout expired during the transaction");
197:                    timedout = false;
198:                    // TODO
199:                    // ((JStatefulSession)ejbObject).forceSessionRemove();
200:                }
201:            }
202:
203:            // ------------------------------------------------------------------
204:            // Other methods
205:            // ------------------------------------------------------------------
206:
207:            /**
208:             * set this instance as removed
209:             */
210:            public void setRemoved() throws RemoteException, RemoveException {
211:                if (TraceEjb.isDebugIc()) {
212:                    TraceEjb.interp.log(BasicLevel.DEBUG, "");
213:                }
214:
215:                // Cannot remove a stateful session inside a transaction
216:                JStatefulSwitch jss = (JStatefulSwitch) bs;
217:                if (jss.isInTransaction()) {
218:                    throw new RemoveException(
219:                            "Cannot remove a statefull session inside a transaction");
220:                }
221:
222:                // Call ejbRemove on instance
223:                // Assume that if this method is transacted (container transaction
224:                // only), this
225:                // transaction will be committed by the container (always true normally)
226:                SessionBean sb = (SessionBean) myinstance;
227:                if (sb != null) {
228:                    sb.ejbRemove();
229:                } else {
230:                    TraceEjb.interp.log(BasicLevel.WARN,
231:                            "remove a passivated instance ?");
232:                }
233:
234:                // Set a flag to finish remove at postInvoke.
235:                // getEJBObject should work in ejbRemove.
236:                // => we do this only after ejbRemove call.
237:                ismarkedremoved = true;
238:            }
239:
240:            /**
241:             * Set the connection list for this instance.
242:             */
243:            public void setConnectionList(List conlist) {
244:                JStatefulSwitch jss = (JStatefulSwitch) bs;
245:                jss.setConnectionList(conlist);
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.