Source Code Cross Referenced for JConnectionFactory.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_jms » 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_jms 
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: JConnectionFactory.java 2563 2003-06-10 08:55:20Z danesa $
023:         * --------------------------------------------------------------------------
024:         */
025:
026:        package org.objectweb.jonas_jms;
027:
028:        import java.io.Serializable;
029:        import java.util.Iterator;
030:        import java.util.LinkedList;
031:        import javax.naming.NamingException;
032:        import javax.naming.Reference;
033:        import javax.naming.Referenceable;
034:
035:        import javax.jms.Connection;
036:        import javax.jms.ConnectionFactory;
037:        import javax.jms.JMSException;
038:        import javax.jms.XAConnectionFactory;
039:
040:        import org.objectweb.jonas_jms.api.JmsManager;
041:
042:        import org.objectweb.util.monolog.api.BasicLevel;
043:
044:        /**
045:         * @author Laurent Chauvirey, Frederic Maistre, Nicolas Tachker
046:         * Contributor(s): 
047:         * Philippe Durieux
048:         * Jeff Mesnil connection anonymous
049:         * Philippe Coq
050:         */
051:
052:        public class JConnectionFactory implements  ConnectionFactory,
053:                Referenceable, Serializable {
054:
055:            protected JmsManager jms;
056:            protected String name;
057:            protected XAConnectionFactory xacf;
058:
059:            private LinkedList connectionpool = new LinkedList();
060:
061:            /**
062:             * Constructor.
063:             * @param name - ConnectionFactory name
064:             */
065:            public JConnectionFactory(String name) {
066:                this .name = name;
067:                jms = JmsManagerImpl.getJmsManager();
068:                xacf = jms.getXAConnectionFactory();
069:            }
070:
071:            /**
072:             * Empty Constructor called by subclasses.
073:             */
074:            protected JConnectionFactory() {
075:            }
076:
077:            // -----------------------------------------------------------------------
078:            // ConnectionFactory implementation
079:            // -----------------------------------------------------------------------
080:
081:            /**
082:             * Create a connection for an anonymous user.
083:             *
084:             * @return a newly created connection.
085:             * @throws JMSException - if JMS Provider fails to create Connection 
086:             * due to some internal error. required resources for a Connection.
087:             * @throws JMSSecurityException - if client authentication fails due to 
088:             * invalid user name or password.
089:             */
090:            public Connection createConnection() throws JMSException {
091:                TraceJms.logger.log(BasicLevel.DEBUG, "");
092:                JConnection c = (JConnection) getJConnection();
093:                if (c == null) {
094:                    c = new JConnection(this , xacf);
095:                }
096:                return (Connection) c;
097:            }
098:
099:            /**
100:             * Create a connection with specified user identity. 
101:             * The connection is created in stopped mode. No messages will
102:             * be delivered until Connection.start method is explicitly called.
103:             *
104:             * @param userName - the caller's user name
105:             * @param password - the caller's password
106:             *
107:             * @throws JMSException - if JMS Provider fails to create Connection 
108:             * due to some internal error. required resources for a Connection.
109:             * @throws JMSSecurityException - if client authentication fails due to 
110:             * invalid user name or password.
111:             */
112:            public Connection createConnection(String userName, String password)
113:                    throws JMSException {
114:                TraceJms.logger.log(BasicLevel.DEBUG, "");
115:                JConnection c = (JConnection) getJConnection(userName);
116:                if (c == null) {
117:                    c = new JConnection(this , xacf, userName, password);
118:                }
119:                return (Connection) c;
120:            }
121:
122:            // -----------------------------------------------------------------------
123:            // Internal Methods
124:            // -----------------------------------------------------------------------
125:
126:            /**
127:             * Free a Connection and return it to the pool
128:             * @param con - Connection to be freed
129:             */
130:            public void freeJConnection(JConnection con) {
131:                TraceJms.logger.log(BasicLevel.DEBUG, "");
132:                synchronized (connectionpool) {
133:                    connectionpool.addLast(con);
134:                }
135:            }
136:
137:            void cleanPool() {
138:                TraceJms.logger.log(BasicLevel.DEBUG, "");
139:                JConnection con = null;
140:                synchronized (connectionpool) {
141:                    Iterator i = connectionpool.iterator();
142:                    while (i.hasNext()) {
143:                        con = (JConnection) i.next();
144:                        try {
145:                            con.finalClose();
146:                        } catch (JMSException e) {
147:                        }
148:                    }
149:                }
150:            }
151:
152:            /**
153:             * Get a Connection from the pool for an anonymous user
154:             *
155:             * @return a Connection for an anonymous user
156:             */
157:            public JConnection getJConnection() {
158:                return getJConnection(JConnection.INTERNAL_USER_NAME);
159:            }
160:
161:            /**
162:             * Get a Connection from the pool for the specified user
163:             * 
164:             * @param user User wanting a connection
165:             * @return Connection from the pool for the specified user
166:             */
167:            public JConnection getJConnection(String user) {
168:                TraceJms.logger.log(BasicLevel.DEBUG, "");
169:                JConnection con = null;
170:                synchronized (connectionpool) {
171:                    Iterator i = connectionpool.iterator();
172:                    while (i.hasNext()) {
173:                        con = (JConnection) i.next();
174:                        if (con.getUser().equals(user)) {
175:                            i.remove();
176:                            break;
177:                        }
178:                    }
179:                }
180:                return con;
181:            }
182:
183:            // -----------------------------------------------------------------------
184:            // Referenceable implementation
185:            // -----------------------------------------------------------------------
186:
187:            public Reference getReference() throws NamingException {
188:                TraceJms.logger.log(BasicLevel.DEBUG, "");
189:                return new Reference(getClass().getName(),
190:                        "org.objectweb.jonas_jms.JObjectFactory", null);
191:            }
192:
193:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.