01: package com.jamonapi;
02:
03: import com.jamonapi.utils.*;
04: import java.util.*;
05:
06: /** The MonitorLeafFactory is an important class in that it determines how to create Monitor objects. It uses the Gang of 4's
07: * decorator pattern to create the Monitors
08: **/
09:
10: public class MonitorLeafFactory extends java.lang.Object implements
11: MonitorLeafFactoryInterface {
12: public static final String DEFAULT = "def";
13: public static final String PRIMARY = "primary";
14:
15: /** Get the header used in the monitor html report. Each Monitor in the decorator chain will provide its own header value **/
16: public String[] getHeader() {
17: ArrayList header = new ArrayList();// the arraylist will be created by the called routine.
18: TimingMonitor mon = (TimingMonitor) createInstance(DEFAULT);
19: header.add("Monitor Label");
20: mon.getHeader(header); // appends monitor data to the arraylist
21:
22: String[] headerArray = new String[0];
23: return (String[]) header.toArray(headerArray);
24:
25: }
26:
27: /** This is the method that creates monitors. Note the decorator chaing. If the Monitor is of type 'Primary' then the monitor
28: * is marked as such. To change the type of Monitors that are returned simply change this routine. For example if one of the
29: * new statements is removed in this code then that Monitor will no longer be created.
30: */
31: public LeafNode createInstance(String monitorType) {
32: TimingMonitor mon = new TimingMonitor(new TimeStatsMonitor(
33: new ActiveStatsMonitor(new LastAccessMonitor(
34: new TimeStatsDistMonitor()))));
35:
36: if (PRIMARY.equalsIgnoreCase(monitorType))
37: mon.setPrimary(true);
38:
39: return mon;
40:
41: }
42: }
|