01: package com.jamonapi;
02:
03: /**
04: * Class that keeps time from the Factories but does not save it. Note this object
05: *should not be reused. You should always get a new instance from MonitorFactory.
06: *
07: * Created on February 19, 2006, 9:05 AM
08: */
09:
10: import java.util.*;
11: import com.jamonapi.utils.*;
12:
13: final class TimeMon2 extends TimeMon {
14:
15: public TimeMon2() {
16: super (new MonKeyImp("timer", "ms."), new MonInternals());
17: monData.activityStats = new ActivityStats();
18: monData.isTimeMonitor = true;
19: }
20:
21: public String toString() {
22: return getLastValue() + " ms.";
23: }
24:
25: private static void testDisplay(String name, JAMonListener listener) {
26: System.out.print("\n\n***" + name);
27: Object[][] data = ((JAMonBufferListener) listener)
28: .getDetailData().getData();
29: for (int i = 0; i < data.length; i++) {
30: System.out.println();
31: for (int j = 0; j < data[i].length; j++)
32: System.out.print(data[i][j] + ", ");
33: }
34: }
35:
36: public static void main(String[] args) throws Exception {
37: TimeMon mon = new TimeMon2();
38: mon.getListenerType("value").addListener(
39: new JAMonBufferListener("first"));
40: mon.getListenerType("value").addListener(
41: new JAMonBufferListener("second"));
42:
43: mon.getListenerType("value").removeListener("first");
44: mon.getListenerType("value").removeListener("second");
45:
46: mon.add(40);
47: System.out.println(mon);
48:
49: mon.getListenerType("value").addListener(
50: new JAMonBufferListener("1"));
51: mon.getListenerType("max").addListener(
52: new JAMonBufferListener("2"));
53: mon.getListenerType("min").addListener(
54: new JAMonBufferListener("3"));
55: mon.getListenerType("maxactive").addListener(
56: new JAMonBufferListener("4"));
57:
58: for (int i = 0; i < 50; i++) {
59: mon.start();
60: Thread.sleep(i);
61: mon.stop();
62: }
63:
64: mon.start().start().start().stop().stop().stop();
65:
66: for (int i = 0; i < 50; i++) {
67: mon.start();
68: Thread.sleep(i);
69: mon.stop();
70: }
71:
72: testDisplay("value", mon.getListenerType("value").getListener());
73: testDisplay("max", mon.getListenerType("max").getListener());
74: testDisplay("min", mon.getListenerType("min").getListener());
75: testDisplay("maxactive", mon.getListenerType("maxactive")
76: .getListener());
77:
78: }
79:
80: }
|