Source Code Cross Referenced for ConnectionPoolManager.java in  » Database-JDBC-Connection-Pool » proxool » org » logicalcobwebs » proxool » 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 » Database JDBC Connection Pool » proxool » org.logicalcobwebs.proxool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This software is released under a licence similar to the Apache Software Licence.
003:         * See org.logicalcobwebs.proxool.package.html for details.
004:         * The latest version is available at http://proxool.sourceforge.net
005:         */
006:        package org.logicalcobwebs.proxool;
007:
008:        import org.apache.commons.logging.Log;
009:        import org.apache.commons.logging.LogFactory;
010:
011:        import java.util.HashMap;
012:        import java.util.HashSet;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:        import java.util.Set;
016:
017:        /**
018:         *
019:         * @version $Revision: 1.16 $, $Date: 2006/01/18 14:40:01 $
020:         * @author billhorsman
021:         * @author $Author: billhorsman $ (current maintainer)
022:         */
023:        class ConnectionPoolManager {
024:            private static final Object LOCK = new Object();
025:
026:            private Map connectionPoolMap = new HashMap();
027:
028:            private Set connectionPools = new HashSet();
029:
030:            private static ConnectionPoolManager connectionPoolManager = null;
031:
032:            private static final Log LOG = LogFactory
033:                    .getLog(ProxoolFacade.class);
034:
035:            public static ConnectionPoolManager getInstance() {
036:                if (connectionPoolManager == null) {
037:                    synchronized (LOCK) {
038:                        if (connectionPoolManager == null) {
039:                            connectionPoolManager = new ConnectionPoolManager();
040:                        }
041:                    }
042:                }
043:                return connectionPoolManager;
044:            }
045:
046:            private ConnectionPoolManager() {
047:            }
048:
049:            /**
050:             * Get the pool by the alias
051:             * @param alias identifies the pool
052:             * @return the pool
053:             * @throws ProxoolException if it couldn't be found
054:             */
055:            protected ConnectionPool getConnectionPool(String alias)
056:                    throws ProxoolException {
057:                ConnectionPool cp = (ConnectionPool) connectionPoolMap
058:                        .get(alias);
059:                if (cp == null) {
060:                    throw new ProxoolException(getKnownPools(alias));
061:                }
062:                return cp;
063:            }
064:
065:            /**
066:             * Convenient method for outputing a message explaining that a pool couldn't
067:             * be found and listing the ones that could be found.
068:             * @param alias identifies the pool
069:             * @return a description of the wht the pool couldn't be found
070:             */
071:            protected String getKnownPools(String alias) {
072:                StringBuffer message = new StringBuffer(
073:                        "Couldn't find a pool called '" + alias
074:                                + "'. Known pools are: ");
075:                Iterator i = connectionPoolMap.keySet().iterator();
076:                while (i.hasNext()) {
077:                    message.append((String) i.next());
078:                    message.append(i.hasNext() ? ", " : ".");
079:                }
080:                return message.toString();
081:            }
082:
083:            /**
084:             * Whether the pool is already registered
085:             * @param alias how we identify the pool
086:             * @return true if it already exists, else false
087:             */
088:            protected boolean isPoolExists(String alias) {
089:                return connectionPoolMap.containsKey(alias);
090:            }
091:
092:            /** @return an array of the connection pools */
093:            protected ConnectionPool[] getConnectionPools() {
094:                return (ConnectionPool[]) connectionPools
095:                        .toArray(new ConnectionPool[connectionPools.size()]);
096:            }
097:
098:            protected ConnectionPool createConnectionPool(
099:                    ConnectionPoolDefinition connectionPoolDefinition)
100:                    throws ProxoolException {
101:                ConnectionPool connectionPool = new ConnectionPool(
102:                        connectionPoolDefinition);
103:                connectionPools.add(connectionPool);
104:                connectionPoolMap.put(connectionPoolDefinition.getAlias(),
105:                        connectionPool);
106:                return connectionPool;
107:            }
108:
109:            protected void removeConnectionPool(String name) {
110:                ConnectionPool cp = (ConnectionPool) connectionPoolMap
111:                        .get(name);
112:                if (cp != null) {
113:                    connectionPoolMap.remove(cp.getDefinition().getAlias());
114:                    connectionPools.remove(cp);
115:                } else {
116:                    LOG
117:                            .info("Ignored attempt to remove either non-existent or already removed connection pool "
118:                                    + name);
119:                }
120:            }
121:
122:            public String[] getConnectionPoolNames() {
123:                return (String[]) connectionPoolMap.keySet().toArray(
124:                        new String[connectionPoolMap.size()]);
125:            }
126:        }
127:
128:        /*
129:         Revision history:
130:         $Log: ConnectionPoolManager.java,v $
131:         Revision 1.16  2006/01/18 14:40:01  billhorsman
132:         Unbundled Jakarta's Commons Logging.
133:
134:         Revision 1.15  2003/03/11 14:51:51  billhorsman
135:         more concurrency fixes relating to snapshots
136:
137:         Revision 1.14  2003/03/10 23:43:09  billhorsman
138:         reapplied checkstyle that i'd inadvertently let
139:         IntelliJ change...
140:
141:         Revision 1.13  2003/03/10 15:26:45  billhorsman
142:         refactoringn of concurrency stuff (and some import
143:         optimisation)
144:
145:         Revision 1.12  2003/03/03 11:11:57  billhorsman
146:         fixed licence
147:
148:         Revision 1.11  2003/03/01 15:27:24  billhorsman
149:         checkstyle
150:
151:         Revision 1.10  2003/02/28 10:42:59  billhorsman
152:         ConnectionPoolManager now passes ProxoolFacade an
153:         array of ConnectionPools rather than a Collection
154:         to avoid a ConcurrentModificationException during
155:         shutdown.
156:
157:         Revision 1.9  2003/02/07 10:27:47  billhorsman
158:         change in shutdown procedure to allow re-registration
159:
160:         Revision 1.8  2003/02/06 17:41:04  billhorsman
161:         now uses imported logging
162:
163:         Revision 1.7  2003/01/27 18:26:36  billhorsman
164:         refactoring of ProxyConnection and ProxyStatement to
165:         make it easier to write JDK 1.2 patch
166:
167:         Revision 1.6  2003/01/23 11:08:26  billhorsman
168:         new setConfiguratorListener method (and remove from optional
169:         parameter when registering pool)
170:
171:         Revision 1.5  2003/01/17 00:38:12  billhorsman
172:         wide ranging changes to clarify use of alias and url -
173:         this has led to some signature changes (new exceptions
174:         thrown) on the ProxoolFacade API.
175:
176:         Revision 1.4  2002/12/15 19:21:42  chr32
177:         Changed @linkplain to @link (to preserve JavaDoc for 1.2/1.3 users).
178:
179:         Revision 1.3  2002/11/09 15:49:36  billhorsman
180:         add method to get the name of every pool
181:
182:         Revision 1.2  2002/10/13 13:39:03  billhorsman
183:         fix when removing pools (credit to Dan Milstein)
184:
185:         Revision 1.1.1.1  2002/09/13 08:13:04  billhorsman
186:         new
187:
188:         Revision 1.8  2002/07/10 16:14:47  billhorsman
189:         widespread layout changes and move constants into ProxoolConstants
190:
191:         Revision 1.7  2002/07/04 09:05:36  billhorsman
192:         Fixes
193:
194:         Revision 1.6  2002/07/02 11:19:08  billhorsman
195:         layout code and imports
196:
197:         Revision 1.5  2002/07/02 08:47:31  billhorsman
198:         you can now access a pool by alias or full url
199:
200:         Revision 1.4  2002/06/28 11:19:47  billhorsman
201:         improved doc
202:
203:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.