KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > admin > StatisticsResultMonitor


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool.admin;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10 import org.logicalcobwebs.proxool.ProxoolException;
11 import org.logicalcobwebs.proxool.ProxoolFacade;
12 import org.logicalcobwebs.proxool.ResultMonitor;
13
14 /**
15  * A ResultMonitor specifically for Snapshots
16  *
17  * @version $Revision: 1.10 $, $Date: 2006/01/18 14:40:06 $
18  * @author bill
19  * @author $Author: billhorsman $ (current maintainer)
20  * @since Proxool 0.8
21  */

22 public class StatisticsResultMonitor extends ResultMonitor {
23
24     private static final Log LOG = LogFactory.getLog(StatisticsResultMonitor.class);
25
26     private StatisticsIF statistics;
27
28     private StatisticsIF oldStatistics;
29
30     private String JavaDoc alias;
31
32     private String JavaDoc token;
33
34     /**
35      * @param alias so we can lookup the latest {@link StatisticsIF statistics}
36      * @param token so we can lookup the latest {@link StatisticsIF statistics}
37      */

38     public StatisticsResultMonitor(String JavaDoc alias, String JavaDoc token) {
39         this.alias = alias;
40         this.token = token;
41         setDelay(2000);
42     }
43
44     /**
45      * waits for statistics
46      * @return {@link #SUCCESS} or {@link #TIMEOUT}
47      * @throws Exception if anything goes wrong
48      */

49     public boolean check() throws Exception JavaDoc {
50         statistics = ProxoolFacade.getStatistics(alias, token);
51         if (statistics == null) {
52             return false;
53         } else if (oldStatistics == null) {
54             return check(statistics);
55         } else {
56             if (!statistics.getStartDate().equals(oldStatistics.getStartDate())) {
57                 return check(statistics);
58             } else {
59                 return false;
60             }
61         }
62     }
63
64     /**
65      * This gets called when we get new statistics. By overriding this
66      * method you get the option of rejecting these new statistics and
67      * waiting for the next set
68      * @param statistics the newly created statistics
69      * @return true if we accept them, false if we want to wait for the next set
70      * (if you don't override this it will return true)
71      */

72     protected boolean check(StatisticsIF statistics) {
73         return true;
74     }
75
76     public int getResult() throws ProxoolException {
77         oldStatistics = statistics;
78         return super.getResult();
79     }
80
81     /**
82      * Get the statistics used in the most recent {@link #check check}
83      * @return snapshot
84      */

85     public StatisticsIF getStatistics() {
86         return statistics;
87     }
88 }
89
90
91 /*
92  Revision history:
93  $Log: StatisticsResultMonitor.java,v $
94  Revision 1.10 2006/01/18 14:40:06 billhorsman
95  Unbundled Jakarta's Commons Logging.
96
97  Revision 1.9 2003/03/06 22:39:05 billhorsman
98  fix
99
100  Revision 1.8 2003/03/06 22:28:32 billhorsman
101  another go at statistics threading (in tests)
102
103  Revision 1.7 2003/03/04 10:24:41 billhorsman
104  removed try blocks around each test
105
106  Revision 1.6 2003/03/03 11:12:06 billhorsman
107  fixed licence
108
109  Revision 1.5 2003/03/01 18:17:50 billhorsman
110  arrffgh. fix,
111
112  Revision 1.4 2003/03/01 16:53:07 billhorsman
113  fix
114
115  Revision 1.3 2003/03/01 16:38:40 billhorsman
116  fix
117
118  Revision 1.2 2003/03/01 16:18:31 billhorsman
119  fix
120
121  Revision 1.1 2003/03/01 16:07:26 billhorsman
122  helper
123
124  Revision 1.3 2003/03/01 15:27:24 billhorsman
125  checkstyle
126
127  Revision 1.2 2003/03/01 15:22:50 billhorsman
128  doc
129
130  Revision 1.1 2003/03/01 15:14:14 billhorsman
131  new ResultMonitor to help cope with test threads
132
133  */
Popular Tags