Source Code Cross Referenced for AbandonedTrace.java in  » Database-JDBC-Connection-Pool » Connection-Pool-DBCP » org » apache » commons » dbcp » 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 » Connection Pool DBCP » org.apache.commons.dbcp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.commons.dbcp;
019:
020:        import java.text.SimpleDateFormat;
021:        import java.util.ArrayList;
022:        import java.util.Date;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        /**
027:         * Tracks db connection usage for recovering and reporting
028:         * abandoned db connections.
029:         *
030:         * The JDBC Connection, Statement, and ResultSet classes
031:         * extend this class.
032:         * 
033:         * @author Glenn L. Nielsen
034:         * @version $Revision: 482015 $ $Date: 2006-12-03 19:22:09 -0700 (Sun, 03 Dec 2006) $
035:         * @deprecated This will be removed in a future version of DBCP.
036:         */
037:        public class AbandonedTrace {
038:
039:            /** Date format */
040:            private static SimpleDateFormat format = new SimpleDateFormat(
041:                    "'DBCP object created' yyyy-MM-dd HH:mm:ss "
042:                            + "'by the following code was never closed:'");
043:
044:            /** DBCP AbandonedConfig */
045:            private AbandonedConfig config = null;
046:            /**  Parent object */
047:            private AbandonedTrace parent;
048:            /** A stack trace of the code that created me (if in debug mode) */
049:            private Exception createdBy;
050:            /** Time created */
051:            private long createdTime;
052:            /** A list of objects created by children of this object */
053:            private List trace = new ArrayList();
054:            /** Last time this connection was used */
055:            private long lastUsed = 0;
056:
057:            /**
058:             * Create a new AbandonedTrace without config and
059:             * without doing abandoned tracing.
060:             */
061:            public AbandonedTrace() {
062:                init(parent);
063:            }
064:
065:            /**
066:             * Construct a new AbandonedTrace with no parent object.
067:             *
068:             * @param config AbandonedConfig
069:             */
070:            public AbandonedTrace(AbandonedConfig config) {
071:                this .config = config;
072:                init(parent);
073:            }
074:
075:            /**
076:             * Construct a new AbandonedTrace with a parent object.
077:             *
078:             * @param parent AbandonedTrace parent object
079:             */
080:            public AbandonedTrace(AbandonedTrace parent) {
081:                this .config = parent.getConfig();
082:                init(parent);
083:            }
084:
085:            /**
086:             * Initialize abandoned tracing for this object.
087:             *
088:             * @param parent AbandonedTrace parent object
089:             */
090:            private void init(AbandonedTrace parent) {
091:                if (parent != null) {
092:                    parent.addTrace(this );
093:                }
094:
095:                if (config == null) {
096:                    return;
097:                }
098:                if (config.getLogAbandoned()) {
099:                    createdBy = new Exception();
100:                    createdTime = System.currentTimeMillis();
101:                }
102:            }
103:
104:            /**
105:             * Get the abandoned config for this object.
106:             *
107:             * @return AbandonedConfig for this object
108:             */
109:            protected AbandonedConfig getConfig() {
110:                return config;
111:            }
112:
113:            /**
114:             * Get the last time this object was used in ms.
115:             *
116:             * @return long time in ms
117:             */
118:            protected long getLastUsed() {
119:                if (parent != null) {
120:                    return parent.getLastUsed();
121:                }
122:                return lastUsed;
123:            }
124:
125:            /**
126:             * Set the time this object was last used to the
127:             * current time in ms.
128:             */
129:            protected void setLastUsed() {
130:                if (parent != null) {
131:                    parent.setLastUsed();
132:                } else {
133:                    lastUsed = System.currentTimeMillis();
134:                }
135:            }
136:
137:            /**
138:             * Set the time in ms this object was last used.
139:             *
140:             * @param time time in ms
141:             */
142:            protected void setLastUsed(long time) {
143:                if (parent != null) {
144:                    parent.setLastUsed(time);
145:                } else {
146:                    lastUsed = time;
147:                }
148:            }
149:
150:            /**
151:             * If logAbandoned=true generate a stack trace
152:             * for this object then add this object to the parent
153:             * object trace list.
154:             */
155:            protected void setStackTrace() {
156:                if (config == null) {
157:                    return;
158:                }
159:                if (config.getLogAbandoned()) {
160:                    createdBy = new Exception();
161:                    createdTime = System.currentTimeMillis();
162:                }
163:                if (parent != null) {
164:                    parent.addTrace(this );
165:                }
166:            }
167:
168:            /**
169:             * Add an object to the list of objects being
170:             * traced.
171:             *
172:             * @param trace AbandonedTrace object to add
173:             */
174:            protected void addTrace(AbandonedTrace trace) {
175:                synchronized (this ) {
176:                    this .trace.add(trace);
177:                }
178:                setLastUsed();
179:            }
180:
181:            /**
182:             * Clear the list of objects being traced by this
183:             * object.
184:             */
185:            protected synchronized void clearTrace() {
186:                if (this .trace != null) {
187:                    this .trace.clear();
188:                }
189:            }
190:
191:            /**
192:             * Get a list of objects being traced by this object.
193:             *
194:             * @return List of objects
195:             */
196:            protected List getTrace() {
197:                return trace;
198:            }
199:
200:            /**
201:             * If logAbandoned=true, print a stack trace of the code that
202:             * created this object.
203:             */
204:            public void printStackTrace() {
205:                if (createdBy != null) {
206:                    System.out.println(format.format(new Date(createdTime)));
207:                    createdBy.printStackTrace(System.out);
208:                }
209:                synchronized (this ) {
210:                    Iterator it = this .trace.iterator();
211:                    while (it.hasNext()) {
212:                        AbandonedTrace at = (AbandonedTrace) it.next();
213:                        at.printStackTrace();
214:                    }
215:                }
216:            }
217:
218:            /**
219:             * Remove a child object this object is tracing.
220:             *
221:             * @param trace AbandonedTrace object to remvoe
222:             */
223:            protected synchronized void removeTrace(AbandonedTrace trace) {
224:                if (this.trace != null) {
225:                    this.trace.remove(trace);
226:                }
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.