Source Code Cross Referenced for ManagedConnectionImpl.java in  » EJB-Server-resin-3.1.5 » examples » example » 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 » EJB Server resin 3.1.5 » examples » example 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package example;
002:
003:        import java.io.*;
004:        import java.util.*;
005:
006:        import javax.resource.spi.ManagedConnection;
007:        import javax.resource.spi.ConnectionRequestInfo;
008:        import javax.resource.spi.ConnectionEventListener;
009:        import javax.resource.spi.ConnectionEvent;
010:
011:        import javax.resource.spi.ManagedConnectionMetaData;
012:        import javax.resource.spi.LocalTransaction;
013:
014:        import javax.transaction.xa.XAResource;
015:
016:        import javax.security.auth.Subject;
017:
018:        /**
019:         * ManagedConnectionImpl represents the underlying (SPI) connection to the
020:         * resource.  Resin will manage this ManagedConnection in its pool.
021:         *
022:         * The user will see the ConnectionImpl facade and may not even know
023:         * that the ManagedConnectionImpl exists.
024:         */
025:        public class ManagedConnectionImpl implements  ManagedConnection {
026:            private ManagedConnectionFactoryImpl _factory;
027:
028:            // Identifier for the ManagedConnectionImpl
029:            private String _name;
030:
031:            // Resin needs to listen for close events
032:            private ArrayList _listeners = new ArrayList();
033:
034:            /**
035:             * Creates a new ManagedConnection with its id.
036:             * ManagedConnectionFactoryImpl will create the ManagedConnectionImpl
037:             * in response to a Resin request.
038:             */
039:            ManagedConnectionImpl(String name,
040:                    ManagedConnectionFactoryImpl factory) {
041:                _name = name;
042:                _factory = factory;
043:            }
044:
045:            /**
046:             * Creates a new application connection.  The application connection
047:             * will be in use until its <code>close()</code> method is called.
048:             * It's <code>close</code> method will call the ConnectionEventListener
049:             * registered with this ManagedConnectionImpl instance.
050:             *
051:             * It is important for the connection's close to be called and for the
052:             * connection to call the close listeners, because Resin needs to
053:             * know when the application is done with the connection and Resin
054:             * can return the ManagedConnection to the pool.
055:             *
056:             * @param subject the subject for the connection
057:             * @param info the connection information for the connection
058:             *
059:             * @return the application-view of the connection
060:             */
061:            public Object getConnection(Subject subject,
062:                    ConnectionRequestInfo info) {
063:                return new ConnectionImpl(_factory.generateConnectionName(),
064:                        this );
065:            }
066:
067:            /**
068:             * XXX:???
069:             *
070:             * In some cases, Resin can associate an old application connection
071:             * with the ManagedConnection.  (I'm not sure when this can happen.)
072:             *
073:             * @param conn the application view of the connection
074:             */
075:            public void associateConnection(Object conn) {
076:            }
077:
078:            /**
079:             * Resin will register a listener with the ManagedConnection so it
080:             * will know when a connection closes or has a fatal error.
081:             *
082:             * @param listener Resin's listener to receive notice of a close.
083:             */
084:            public void addConnectionEventListener(
085:                    ConnectionEventListener listener) {
086:                _listeners.add(listener);
087:            }
088:
089:            /**
090:             * Resin can remove it's listener when it removes the managed connection
091:             * from the pool.
092:             *
093:             * @param listener Resin's listener to receive notice of a close.
094:             */
095:            public void removeConnectionEventListener(
096:                    ConnectionEventListener listener) {
097:                _listeners.remove(listener);
098:            }
099:
100:            /**
101:             * Implementation method to allow the <code>ConnectionImpl</code> to
102:             * trigger Resin's listeners when the connection closes.
103:             *
104:             * @param conn the user connection which is closing.
105:             */
106:            void close(ConnectionImpl conn) {
107:                ConnectionEvent evt;
108:                evt = new ConnectionEvent(this ,
109:                        ConnectionEvent.CONNECTION_CLOSED);
110:
111:                for (int i = 0; i < _listeners.size(); i++) {
112:                    ConnectionEventListener listener;
113:                    listener = (ConnectionEventListener) _listeners.get(i);
114:
115:                    listener.connectionClosed(evt);
116:                }
117:            }
118:
119:            /**
120:             * This example isn't returning any meta data.  In general,
121:             * providing the meta data is nice for the applications.
122:             */
123:            public ManagedConnectionMetaData getMetaData() {
124:                return null;
125:            }
126:
127:            /**
128:             * Transaction-aware resources will return the XAResource for the
129:             * managed connection.
130:             */
131:            public XAResource getXAResource() {
132:                return null;
133:            }
134:
135:            /**
136:             * Transaction-aware resources will return the LocalTransaction for the
137:             * managed connection.  LocalTransaction is a lightweight interface
138:             * for transactions that don't need the full XA transactions.
139:             */
140:            public LocalTransaction getLocalTransaction() {
141:                return null;
142:            }
143:
144:            /**
145:             * Called when Resin returns a connection to the idle pool.
146:             */
147:            public void cleanup() {
148:            }
149:
150:            /**
151:             * Called when Resin is closing the connection.  Any sockets, etc,
152:             * would be closed here.
153:             */
154:            public void destroy() {
155:            }
156:
157:            /**
158:             * Logging should use JDK 1.4 java.util.logging.
159:             */
160:            public PrintWriter getLogWriter() {
161:                return null;
162:            }
163:
164:            /**
165:             * Logging should use JDK 1.4 java.util.logging.
166:             */
167:            public void setLogWriter(PrintWriter log) {
168:            }
169:
170:            public String toString() {
171:                return "ManagedConnectionImpl[" + _name + "]";
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.