All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jamonapi.JAMonBufferListener Maven / Gradle / Ivy

There is a newer version: 2.82
Show newest version
package com.jamonapi;

import com.jamonapi.utils.BufferList;
import com.jamonapi.utils.BufferListDetailData;
import com.jamonapi.utils.DetailData;
import com.jamonapi.utils.ToArray;

import java.util.ArrayList;
import java.util.List;

/** JAMonListener that puts jamon data into a buffer that allows you to display the last N configurable
 * detail events.  The buffer will have the detail label, value and invocation date for the monitor that
 * was fired.
 * 
 * @author steve souza
 *
 */

public  class JAMonBufferListener implements JAMonListener, CopyJAMonListener {

    private static final long serialVersionUID = 278L;
    private BufferList list;
    private String name;
    static final String[] DEFAULT_HEADER=getDefaultHeaderInfo().getHeader();
    static final int VALUE_COL=getDefaultHeaderInfo().getLastValueIndex();
    static final int DATE_COL=getDefaultHeaderInfo().getDateIndex();

    public JAMonBufferListener() {
        this("JAMonBufferListener");
    }

    /** Pass in the jamonListener name */

    public JAMonBufferListener(String name){
        this(name, new BufferList(DEFAULT_HEADER,50));
    }

    /** Name the listener and pass in the jamon BufferList to use */
    public JAMonBufferListener(String name, BufferList list) {
        this.name=name;
        this.list=list;
    }

    /** When this event is fired the monitor will be added to the rolling buffer */
    public void processEvent(Monitor mon) {
        list.addRow(mon.getJAMonDetailRow());
    }

    /** Add a row to the buffer */
    public void addRow(ToArray row) {
        list.addRow(row);
    }

    /** Add a row to the buffer */
    public void addRow(Object[] row) {
        list.addRow(row);
    }

    /** get the underlying bufferList which can then be used to display its contents */
    public BufferList getBufferList() {
        return list;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name=name;

    }

    /** Make a copy of this instance */
    public JAMonListener copy() {
        return new JAMonBufferListener(getName(), list.copy());
    }


    public DetailData getDetailData() {
        return new BufferListDetailData(list);
    }

    public int getRowCount() {
        return list.getRowCount();
    }

    public boolean hasData() {
        return list.hasData();
    }

    public boolean isEmpty() {
        return list.isEmpty();
    }


    public static HeaderInfo getDefaultHeaderInfo() {
        return getHeaderInfo(new String[]{"Label"});

    }

    public static HeaderInfo getHeaderInfo(String[] firstPart) {
        return new HeaderInfo(firstPart);
    }

    // class makes sure header always returns lastvalue, active and date.
    public static class HeaderInfo {
        private String[] header;
        private int lastValueIndex;
        private int dateIndex;
        private int activeIndex;

        public HeaderInfo(String[] firstPart)  {
            header=makeHeader(firstPart);
            for (int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy