Package org.jboss.profiler.aop.monitoring.control

Source Code of org.jboss.profiler.aop.monitoring.control.MonitoringController

/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.profiler.aop.monitoring.control;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

import org.jboss.profiler.aop.monitoring.model.MeasureAggregation;
import org.jboss.profiler.aop.monitoring.model.MonitoringMeasure;
import org.jboss.profiler.aop.monitoring.model.TimeValue;

/**
* @author Clebert Suconic
*/
public class MonitoringController {
    public static HashMap measuresMap = new HashMap();
    public static HashMap aggregationsMap = new HashMap();

    /** The grade we are going to divide the time, in milliseconds. */
    static int grade=60000;

    /**
     * @return Returns the grade.
     */
    public static int getGrade() {
        return grade;
    }

    /**
     * Clear all values existing on this MonitoringClass
     */
    public static void clear() {
        synchronized (measuresMap) {
            measuresMap.clear();
        }
        synchronized (aggregationsMap) {
            aggregationsMap.clear();
        }
    }

    /**
     * This method requires a clear before executed
     * @param grade
     *            The grade to set.
     */
    public static void setGrade(int grade) {
        clear();
        MonitoringController.grade = grade;
    }

    public static void openStack(String aggregation, String measure, long eventTime) {
        MonitoringMeasure monitoringMeasure = findMeasure(aggregation, measure);
        TimeValue value = findTimeValue(monitoringMeasure, eventTime);
        value.openStack();
        monitoringMeasure.getRootValue().openStack();
    }

    /**
     * @param measure
     * @param eventTime
     * @return
     */
    public static TimeValue findTimeValue(MonitoringMeasure monitoringMeasure, long eventTime) {
        TimeValue value = monitoringMeasure.findValue(eventTime/grade,grade);
        return value;
    }

    public static TimeValue findCurrentTimeValue(MonitoringMeasure monitoringMeasure) {
        long time = System.currentTimeMillis();
        TimeValue value = monitoringMeasure.findValue(time/grade,grade);
        return value;
    }

    public static Collection getAggregationsSet() {
        return aggregationsMap.values();
    }

    public static Collection getMeasuresSet() {
        return measuresMap.values();
    }

    public static MeasureAggregation findAggregation(String aggregationName) {
        MeasureAggregation aggregation = (MeasureAggregation) aggregationsMap.get(aggregationName);
        if (aggregation==null) {
            synchronized (aggregationsMap) {
                aggregation = (MeasureAggregation) aggregationsMap.get(aggregationName);
                if (aggregation==null) {
                    aggregation = new MeasureAggregation(aggregationName);
                    aggregationsMap.put(aggregationName,aggregation);
                }
            }
        }

        return aggregation;
    }

    public static void closeStack(String aggregation, String measure, long eventTime,long time, long cpuTime) {
        MonitoringMeasure monitoringMeasure = findMeasure(aggregation, measure);
        TimeValue value = findTimeValue(monitoringMeasure, eventTime);
        value.closeStack(time,cpuTime);
        monitoringMeasure.getRootValue().closeStack(time,cpuTime);
    }

    /** Finds the Measure. Does not create if not found */
    public static MonitoringMeasure findMeasureByName(String measure) {
        return (MonitoringMeasure)measuresMap.get(measure);
    }

    /** Finds the measure and creates it if not found */
    protected static MonitoringMeasure findMeasure(String aggregation, String measure) {
        MonitoringMeasure monitoringMeasure = (MonitoringMeasure)measuresMap.get(measure);
        if (monitoringMeasure==null) {
            synchronized (measuresMap) {
                monitoringMeasure = (MonitoringMeasure)measuresMap.get(measure);
                if (monitoringMeasure==null) {
                  monitoringMeasure = new MonitoringMeasure(measure);
                  measuresMap.put(measure,monitoringMeasure);
                  MeasureAggregation aggregationObject = findAggregation(aggregation);
                  aggregationObject.setMeasure(measure,monitoringMeasure);
                }
            }
        }
        return monitoringMeasure;
    }

    public static Iterator iterMeasures() {
        return measuresMap.keySet().iterator();
    }

}
TOP

Related Classes of org.jboss.profiler.aop.monitoring.control.MonitoringController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.