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.admin;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.logicalcobwebs.proxool.ProxoolException;
011: import org.logicalcobwebs.proxool.ProxoolFacade;
012: import org.logicalcobwebs.proxool.ResultMonitor;
013:
014: /**
015: * A ResultMonitor specifically for Snapshots
016: *
017: * @version $Revision: 1.10 $, $Date: 2006/01/18 14:40:06 $
018: * @author bill
019: * @author $Author: billhorsman $ (current maintainer)
020: * @since Proxool 0.8
021: */
022: public class StatisticsResultMonitor extends ResultMonitor {
023:
024: private static final Log LOG = LogFactory
025: .getLog(StatisticsResultMonitor.class);
026:
027: private StatisticsIF statistics;
028:
029: private StatisticsIF oldStatistics;
030:
031: private String alias;
032:
033: private String token;
034:
035: /**
036: * @param alias so we can lookup the latest {@link StatisticsIF statistics}
037: * @param token so we can lookup the latest {@link StatisticsIF statistics}
038: */
039: public StatisticsResultMonitor(String alias, String token) {
040: this .alias = alias;
041: this .token = token;
042: setDelay(2000);
043: }
044:
045: /**
046: * waits for statistics
047: * @return {@link #SUCCESS} or {@link #TIMEOUT}
048: * @throws Exception if anything goes wrong
049: */
050: public boolean check() throws Exception {
051: statistics = ProxoolFacade.getStatistics(alias, token);
052: if (statistics == null) {
053: return false;
054: } else if (oldStatistics == null) {
055: return check(statistics);
056: } else {
057: if (!statistics.getStartDate().equals(
058: oldStatistics.getStartDate())) {
059: return check(statistics);
060: } else {
061: return false;
062: }
063: }
064: }
065:
066: /**
067: * This gets called when we get new statistics. By overriding this
068: * method you get the option of rejecting these new statistics and
069: * waiting for the next set
070: * @param statistics the newly created statistics
071: * @return true if we accept them, false if we want to wait for the next set
072: * (if you don't override this it will return true)
073: */
074: protected boolean check(StatisticsIF statistics) {
075: return true;
076: }
077:
078: public int getResult() throws ProxoolException {
079: oldStatistics = statistics;
080: return super .getResult();
081: }
082:
083: /**
084: * Get the statistics used in the most recent {@link #check check}
085: * @return snapshot
086: */
087: public StatisticsIF getStatistics() {
088: return statistics;
089: }
090: }
091:
092: /*
093: Revision history:
094: $Log: StatisticsResultMonitor.java,v $
095: Revision 1.10 2006/01/18 14:40:06 billhorsman
096: Unbundled Jakarta's Commons Logging.
097:
098: Revision 1.9 2003/03/06 22:39:05 billhorsman
099: fix
100:
101: Revision 1.8 2003/03/06 22:28:32 billhorsman
102: another go at statistics threading (in tests)
103:
104: Revision 1.7 2003/03/04 10:24:41 billhorsman
105: removed try blocks around each test
106:
107: Revision 1.6 2003/03/03 11:12:06 billhorsman
108: fixed licence
109:
110: Revision 1.5 2003/03/01 18:17:50 billhorsman
111: arrffgh. fix,
112:
113: Revision 1.4 2003/03/01 16:53:07 billhorsman
114: fix
115:
116: Revision 1.3 2003/03/01 16:38:40 billhorsman
117: fix
118:
119: Revision 1.2 2003/03/01 16:18:31 billhorsman
120: fix
121:
122: Revision 1.1 2003/03/01 16:07:26 billhorsman
123: helper
124:
125: Revision 1.3 2003/03/01 15:27:24 billhorsman
126: checkstyle
127:
128: Revision 1.2 2003/03/01 15:22:50 billhorsman
129: doc
130:
131: Revision 1.1 2003/03/01 15:14:14 billhorsman
132: new ResultMonitor to help cope with test threads
133:
134: */
|