Source Code Cross Referenced for ResultMonitor.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:        /**
012:         * Waits for a set of results to become true with timeout
013:         * functionality
014:         *
015:         * @version $Revision: 1.10 $, $Date: 2006/01/18 14:40:06 $
016:         * @author bill
017:         * @author $Author: billhorsman $ (current maintainer)
018:         * @since Proxool 0.8
019:         */
020:        public abstract class ResultMonitor {
021:
022:            private static final Log LOG = LogFactory
023:                    .getLog(ResultMonitor.class);
024:
025:            /**
026:             * This monitor is still waiting for the result to come true
027:             */
028:            public static final int WAITING = 0;
029:
030:            /**
031:             * The result has happened
032:             */
033:            public static final int SUCCESS = 1;
034:
035:            /**
036:             * There was a timeout waiting for the result to happen
037:             * @see #setTimeout
038:             */
039:            public static final int TIMEOUT = 3;
040:
041:            /**
042:             * Seems awfully long, but it seems to need it. Sometimes.
043:             */
044:            private long timeout = 60000;
045:
046:            private int result = WAITING;
047:
048:            private int delay = 500;
049:
050:            /**
051:             * Override this with your specific check
052:             * @return true if the result has happened, else false
053:             * @throws Exception if anything goes wrong
054:             */
055:            public abstract boolean check() throws Exception;
056:
057:            /**
058:             * Wait for the result to happen, or for a timeout
059:             * @return {@link #SUCCESS} or {@link #TIMEOUT}
060:             * @throws ProxoolException if the {@link #check} threw an exception
061:             * @see #setTimeout
062:             */
063:            public int getResult() throws ProxoolException {
064:
065:                try {
066:                    long startTime = System.currentTimeMillis();
067:                    if (check()) {
068:                        result = SUCCESS;
069:                    }
070:                    while (true) {
071:                        if (System.currentTimeMillis() - startTime > timeout) {
072:                            result = TIMEOUT;
073:                            LOG.debug("Timeout");
074:                            break;
075:                        }
076:                        try {
077:                            Thread.sleep(delay);
078:                        } catch (InterruptedException e) {
079:                            LOG.error("Awoken", e);
080:                        }
081:                        if (check()) {
082:                            result = SUCCESS;
083:                            LOG.debug("Success");
084:                            break;
085:                        }
086:                    }
087:                    return result;
088:                } catch (Exception e) {
089:                    throw new ProxoolException("Problem monitoring result", e);
090:                }
091:            }
092:
093:            /**
094:             * Set the timeout
095:             * @param timeout milliseconds
096:             */
097:            public void setTimeout(long timeout) {
098:                this .timeout = timeout;
099:            }
100:
101:            public void setDelay(int delay) {
102:                this .delay = delay;
103:            }
104:        }
105:
106:        /*
107:         Revision history:
108:         $Log: ResultMonitor.java,v $
109:         Revision 1.10  2006/01/18 14:40:06  billhorsman
110:         Unbundled Jakarta's Commons Logging.
111:
112:         Revision 1.9  2003/03/05 18:44:10  billhorsman
113:         fix delay and timeout
114:
115:         Revision 1.8  2003/03/04 10:24:40  billhorsman
116:         removed try blocks around each test
117:
118:         Revision 1.7  2003/03/03 11:12:05  billhorsman
119:         fixed licence
120:
121:         Revision 1.6  2003/03/02 00:53:38  billhorsman
122:         increased timeout to 60 sec!
123:
124:         Revision 1.5  2003/03/01 18:17:51  billhorsman
125:         arrffgh. fix,
126:
127:         Revision 1.4  2003/03/01 16:54:20  billhorsman
128:         fix
129:
130:         Revision 1.3  2003/03/01 15:27:24  billhorsman
131:         checkstyle
132:
133:         Revision 1.2  2003/03/01 15:22:50  billhorsman
134:         doc
135:
136:         Revision 1.1  2003/03/01 15:14:15  billhorsman
137:         new ResultMonitor to help cope with test threads
138:
139:         */
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.