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

com.jamonapi.MonitorComposite Maven / Gradle / Ivy

There is a newer version: 2.82
Show newest version

package com.jamonapi;


import com.jamonapi.utils.DetailData;
import com.jamonapi.utils.Misc;
import com.jamonapi.utils.SerializationUtils;

import java.util.*;

/**
 * Treats groups of monitors the same way you treat one monitor.  i.e. you can enable/disable/reset
 * etc a group of monitors.
 */
public class MonitorComposite extends Monitor implements DetailData  {

    private static final long serialVersionUID = 279L;
    private static final String LOCAL="local";
    private static final String INSTANCE_NAME_HEADER = "Instance";

    private final Monitor[] monitors;// the monitors in the composite
    private final int numRows; // rows in the composite
    private final static int TYPICAL_NUM_CHILDREN=200;// hopefully makes it so the monitor need not grow all the time
    private Map map;
    private Date dateCreated;
    private String instanceName=LOCAL;

    /** Creates a new instance of MonitorComposite */
    public MonitorComposite(Monitor[] monitors) {
        this.monitors = monitors;
        numRows = (monitors==null) ? 0 : monitors.length;
        initializeForLookUps();
        dateCreated = new Date();
    }

    private void initializeForLookUps() {
        map = new HashMap();
        if (monitors!=null) {
            for (Monitor mon : monitors) {
                map.put(mon.getMonKey(), mon);
            }
        }
    }

    MonitorComposite() {
        this(null);
    }

    public Monitor[] getMonitors() {
        return monitors;
    }

    private Monitor[] getMonitorsWithUnits(String units) {
        if (monitors==null || units==null) {
            return null;
        } else if ("AllMonitors".equalsIgnoreCase(units)) {
            return monitors;
        }

        int size=monitors.length;
        List rows=new ArrayList(monitors.length);
        for (int i=0;i\n");

        for (int i=0;i"+header[i]+"");

        html.append(""+header[0]+"");//repeat first header
        html.append("\n");

        for (int i=0;i");
            for (int j=0;j"+data[i][j]+"");
            }
            html.append(""+data[i][0]+"");// repeat first column
            html.append("\n");
        }


        html.append("");

        return html.toString();
    }

    /** Does this have data? */
    public boolean hasData() {
        return (getNumRows()==0) ? false : true;
    }

    // Various get row data methods (for full row, basic row, and display row
    private Object[] getRowData(MonitorImp mon) {
        List row=new ArrayList(TYPICAL_NUM_CHILDREN);
        mon.getRowData(row);
        return row.toArray();
    }

    private Object[] getBasicRowData(MonitorImp mon) {
        List row=new ArrayList();
        mon.getBasicRowData(row);
        return row.toArray();
    }


    private Object[] getRowDisplayData(MonitorImp mon) {
        List row=new ArrayList(TYPICAL_NUM_CHILDREN);
        mon.getRowDisplayData(row);
        return row.toArray();
    }


    @Override
    public void reset() {
        for (int i=0;i0) // thisDate>lastAccess
                lastAccess=thisDate;

        }

        return lastAccess;
    }


    @Override
    public double getLastValue() {
        Date date=getLastAccess();
        for (int i=0;i=0) // date>=getLastAccess)
                return monitors[i].getLastValue();
        }

        return 0;
    }


    @Override
    public double getMax() {
        double max=MonInternals.MAX_DOUBLE;

        for (int i=0;imax)
                max=thisMax;
        }

        return max;
    }


    @Override
    public double getMaxActive() {
        double max=MonInternals.MAX_DOUBLE;

        for (int i=0;imax)
                max=thisMax;
        }

        return max;
    }

    @Override
    public double getMin() {
        double min=MonInternals.MIN_DOUBLE;

        for (int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy