001: package com.jamonapi;
002:
003: import com.jamonapi.utils.*;
004:
005: /** JAMonListener that puts jamon data into a buffer that allows you to display the last N configurble
006: * detail events. The buffer will have the detail label, value and invocation date for the monitor that
007: * was fired.
008: *
009: * @author steve souza
010: *
011: */
012:
013: //public class JAMonBufferListener implements JAMonListener, DetailData, CopyJAMonListener {
014: public class JAMonBufferListener implements JAMonListener,
015: CopyJAMonListener {
016:
017: private BufferList list;
018: private String name;
019: static final String[] DEFAULT_HEADER = new String[] { "Label",
020: "LastValue", "Active", "Date" };
021: static final int VALUE_COL = 1;
022: static final int DATE_COL = 3;
023:
024: public JAMonBufferListener() {
025: this ("JAMonBufferListener");
026: }
027:
028: /** Pass in the jamonListener name */
029:
030: public JAMonBufferListener(String name) {
031: this (name, new BufferList(DEFAULT_HEADER, 50));
032: }
033:
034: /** Name the listener and pass in the jamon BufferList to use */
035: public JAMonBufferListener(String name, BufferList list) {
036: this .name = name;
037: this .list = list;
038: }
039:
040: /** When this event is fired the monitor will be added to the rolling buffer */
041: public void processEvent(Monitor mon) {
042: list.addRow(mon.getJAMonDetailRow());
043: }
044:
045: /** Add a row to the buffer */
046: public void addRow(ToArray row) {
047: list.addRow(row);
048: }
049:
050: /** Add a row to the buffer */
051: public void addRow(Object[] row) {
052: list.addRow(row);
053: }
054:
055: /** get the underlying bufferList which can then be used to display its contents */
056: public BufferList getBufferList() {
057: return list;
058: }
059:
060: public String getName() {
061: return name;
062: }
063:
064: public void setName(String name) {
065: this .name = name;
066:
067: }
068:
069: public JAMonListener copy() {
070: return new JAMonBufferListener(getName(), list.copy());
071: }
072:
073: public DetailData getDetailData() {
074: return new BufferListDetailData(list);
075: }
076:
077: // /**
078: // * Use getDetailData() instead.
079: // * @deprecated
080: // *
081: // */
082: // public Object[][] getData() {
083: // return list.getData();
084: // }
085: //
086: //
087: // /**
088: // * Use getDetailData() instead.
089: // * @deprecated
090: // *
091: // */
092: // public String[] getHeader() {
093: // return list.getHeader();
094: // }
095:
096: public int getRowCount() {
097: return list.getRowCount();
098: }
099:
100: public boolean hasData() {
101: return list.hasData();
102: }
103:
104: public boolean isEmpty() {
105: return list.isEmpty();
106: }
107:
108: }
|