com.jamonapi
Class AccumulateMonitor

java.lang.Object
  extended bycom.jamonapi.AccumulateMonitor
All Implemented Interfaces:
AccumulateMonitorInterface, MinimalMonitor
Direct Known Subclasses:
ActiveStatsMonitor, LastAccessMonitor, TimeStatsDistMonitor, TimeStatsMonitor

public class AccumulateMonitor
extends java.lang.Object
implements AccumulateMonitorInterface

AccumulateMonitors represent Monitors that increase in value. AccumulateMonitors use the Gang of 4's decorator pattern to pass method invocations to the next Monitor in the chain. Note many of the public methods such as start(), stop() and reset() call the same method of next Monitor in the decorator chain. Any classes that inherit from AccumulateMonitor implement the protected methods startThis(), stopThis(), and resetThis() and leave the public methods as is. In general the various ...This() (startThis(), stopThis(), resetThis()) methods perform the action on that instance and the methods without ...This() (start(), stop(), reset()) take care of passing the command down the decorator chain.


Field Summary
protected  long accrued
           
protected static java.lang.String ACTIVE
           
protected static java.lang.String AVG
           
protected static java.lang.String AVGACTIVE
           
protected static java.lang.String HITS
           
protected static java.lang.String MAX
           
protected static java.lang.String MAXACTIVE
           
protected static java.lang.String MILLISECONDS
           
protected static java.lang.String MIN
           
protected static java.lang.String NONE
           
protected static java.lang.String STANDARD_DEVIATION
           
protected static java.lang.String TOTAL
           
 
Constructor Summary
AccumulateMonitor()
          Default constructor.
AccumulateMonitor(AccumulateMonitorInterface childMonitor)
          Monitors use the Gang of 4 decorator pattern where each monitor points to and calls the next monitor in the chain.
 
Method Summary
protected static java.lang.String convertToString(double value)
          Convert a float value to a String Sample Call: String number=AccumulateMonitor.convertToString(1234.5); // returns 1,234.5
 long getAccrued()
          Get the value of the monitor.
 java.lang.String getAccruedString()
          Return the accrued value in String format
 void getData(java.util.ArrayList rowData)
          Populate the ArrayList with data from this Monitor as well as all other Monitors in the decorator chain
protected  void getDataThis(java.util.ArrayList rowData)
          Add this Monitor's accrued value in string format to an ArrayList.
protected  java.lang.String getDisplayString(java.lang.String type, java.lang.String value, java.lang.String units)
           
 void getHeader(java.util.ArrayList header)
          Add the display header that is associated with this Monitor to the header (as an ArrayList entry).
protected  void getHeaderThis(java.util.ArrayList header)
           
 java.lang.String getType()
          Display this Monitors type
 java.lang.String getUnits()
          Dispay the units appropriate for this monitor
 void increase()
          Increase the monitors accrued value by 1 unit.
 void increase(long increaseValue)
          Increase the monitors accrued value by the ammount specified in the parameter, and call increase on all monitors in the decorator chain.
protected  void increaseThis(long increase)
          Add the value passed to this method to the Monitor's accrued value
 boolean isPrimary()
          Indicates whether or not this Monitor is primary.
static void main(java.lang.String[] args)
          Method that calls test code for this class.
 void reset()
          Erase/wipe out any accrued statistics for this monitor, and call reset on all monitors in the decorator chain Sample Call: monitor.reset();
protected  void resetThis()
          Erase/wipe out any accrued statistics for this monitor
 void setPrimary(boolean primary)
          Specify whether or not this Monitor is primary.
 void start()
          Start gathering statistics for this Monitor.
protected  void startThis()
          Contains any logic that this Monitor must perform when it is started
 void stop()
          Stop gathering statistics for the Monitor.
protected  void stopThis()
          Contains any logic that this Monitor must perform when it is stopped
 java.lang.String toString()
          Display this Monitor as well as all Monitor's in the decorator chain as Strings
protected  java.lang.String toStringChild()
          Display Monitor's in the Decorator chain in String format
protected  java.lang.String toStringThis()
          Display this Monitor in String format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TOTAL

protected static final java.lang.String TOTAL
See Also:
Constant Field Values

MIN

protected static final java.lang.String MIN
See Also:
Constant Field Values

MAX

protected static final java.lang.String MAX
See Also:
Constant Field Values

HITS

protected static final java.lang.String HITS
See Also:
Constant Field Values

AVG

protected static final java.lang.String AVG
See Also:
Constant Field Values

STANDARD_DEVIATION

protected static final java.lang.String STANDARD_DEVIATION
See Also:
Constant Field Values

ACTIVE

protected static final java.lang.String ACTIVE
See Also:
Constant Field Values

AVGACTIVE

protected static final java.lang.String AVGACTIVE
See Also:
Constant Field Values

MAXACTIVE

protected static final java.lang.String MAXACTIVE
See Also:
Constant Field Values

accrued

protected long accrued

MILLISECONDS

protected static final java.lang.String MILLISECONDS
See Also:
Constant Field Values

NONE

protected static final java.lang.String NONE
See Also:
Constant Field Values
Constructor Detail

AccumulateMonitor

public AccumulateMonitor()
Default constructor. Note Monitors use the Gang of 4 decorator pattern where each monitor points to and calls the next monitor in the chain. With the default constructor there is no need for a next Monitors in the chain, but to keep the logic identical to when there is a next Monitor in the chain a NullMonitor (that does nothing) is used as the next Monitor to call in the decorator pattern. Martin Fowler's Refactoring book discusses NullMonitor's.


AccumulateMonitor

public AccumulateMonitor(AccumulateMonitorInterface childMonitor)
Monitors use the Gang of 4 decorator pattern where each monitor points to and calls the next monitor in the chain. This constructor as its argument takes the next AccumulateMonitor in the chain. Sample Call: AccumulateMonitor mon=new AccumulateMonitor(new AccumulateMonitor(new AccumulateMonitor()));

Method Detail

getAccrued

public long getAccrued()
Get the value of the monitor. What this value means depends on what the monitor does. In the case of a Timing monitor it would be the elapsed time since the monitor was started. Sample call: long accrued=monitor.getAccrued();

Specified by:
getAccrued in interface MinimalMonitor

resetThis

protected void resetThis()
Erase/wipe out any accrued statistics for this monitor


increase

public void increase(long increaseValue)
Increase the monitors accrued value by the ammount specified in the parameter, and call increase on all monitors in the decorator chain. Sample Call: monitor.increase(100);

Specified by:
increase in interface MinimalMonitor

increase

public void increase()
Increase the monitors accrued value by 1 unit. Sample Call: monitor.increase();

Specified by:
increase in interface AccumulateMonitorInterface

reset

public void reset()
Erase/wipe out any accrued statistics for this monitor, and call reset on all monitors in the decorator chain Sample Call: monitor.reset();

Specified by:
reset in interface MinimalMonitor

toString

public java.lang.String toString()
Display this Monitor as well as all Monitor's in the decorator chain as Strings


getUnits

public java.lang.String getUnits()
Dispay the units appropriate for this monitor


getType

public java.lang.String getType()
Display this Monitors type


getData

public void getData(java.util.ArrayList rowData)
Populate the ArrayList with data from this Monitor as well as all other Monitors in the decorator chain

Specified by:
getData in interface MinimalMonitor

start

public void start()
Start gathering statistics for this Monitor. The Monitor will run until the stop() method is called. start() will also call the start() method for all other Monitors in the decorator chain.

Specified by:
start in interface AccumulateMonitorInterface

startThis

protected void startThis()
Contains any logic that this Monitor must perform when it is started


stop

public void stop()
Stop gathering statistics for the Monitor. stop() is called after a Monitor has been started with the start() method. stop() will also call the stop() method for all Monitors in the decorator chain.

Specified by:
stop in interface AccumulateMonitorInterface

stopThis

protected void stopThis()
Contains any logic that this Monitor must perform when it is stopped


getAccruedString

public java.lang.String getAccruedString()
Return the accrued value in String format


getDataThis

protected void getDataThis(java.util.ArrayList rowData)
Add this Monitor's accrued value in string format to an ArrayList.


toStringThis

protected java.lang.String toStringThis()
Display this Monitor in String format


toStringChild

protected java.lang.String toStringChild()
Display Monitor's in the Decorator chain in String format


convertToString

protected static java.lang.String convertToString(double value)
Convert a float value to a String Sample Call: String number=AccumulateMonitor.convertToString(1234.5); // returns 1,234.5


getDisplayString

protected java.lang.String getDisplayString(java.lang.String type,
                                            java.lang.String value,
                                            java.lang.String units)

increaseThis

protected void increaseThis(long increase)
Add the value passed to this method to the Monitor's accrued value


getHeader

public void getHeader(java.util.ArrayList header)
Add the display header that is associated with this Monitor to the header (as an ArrayList entry). Also give all Monitors in the decorator chain the opportunity to add their header entries.

Specified by:
getHeader in interface MinimalMonitor

getHeaderThis

protected void getHeaderThis(java.util.ArrayList header)

isPrimary

public boolean isPrimary()
Indicates whether or not this Monitor is primary. See www.jamonapi.com for an explanation of primary Monitors.

Specified by:
isPrimary in interface AccumulateMonitorInterface

setPrimary

public void setPrimary(boolean primary)
Specify whether or not this Monitor is primary. See www.jamonapi.com for an explanation of primary Monitors. Call setPrimary() for all Monitors in the decorator chain

Specified by:
setPrimary in interface AccumulateMonitorInterface

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Method that calls test code for this class.

Throws:
java.lang.Exception