at.spardat.xma.monitoring.TimeingEvent Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2003, 2007 s IT Solutions AT Spardat GmbH .
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* s IT Solutions AT Spardat GmbH - initial API and implementation
*******************************************************************************/
/*
* @(#) $Id: TimeingEvent.java 2644 2008-08-25 12:18:56Z webok $
*
*
*
*
*
*/
package at.spardat.xma.monitoring;
import at.spardat.xma.plugins.PluginManagerServer;
/**
* Wrapper class for sITSolutions monitoring, now working with the monitoring plugin, for independence and
* extendability to other monitoring solutions. If no monitoring plugin is configured, all its method do nothing.
*
* Each instance of this class constitutes one time measurement. The measurement is started by calling the
* constructor and ended by calling either {@link #success()} or {@link #failure()}.
*
* Example for using TimingEvent without having to do explicit Exception handling:
TimingEvent event = new TimingEvent("myvariable");
try {
//do something
event.success(); //end event, record success
} finally { //end event, record failure: only the first call to an event should be recorded
event.failure();
}
*
* @author s2877
*/
public class TimeingEvent {
private static IMonitoring plugin;
private Object event;
// get the optional monitoring plugin.
static {
PluginManagerServer pluginManager = PluginManagerServer.getInstance();
if(pluginManager.isPluginDeclared(IMonitoring.class)) {
plugin = (IMonitoring) pluginManager.getPlugin(IMonitoring.class);
}
}
/**
* Constructor, starts a new measurement.
* @param varName name of the variable to measure.
*/
public TimeingEvent (String varName) {
if (plugin!=null) event = plugin.startTiming(varName);
}
/**
* Ends the measurement with a success status.
*/
public void success () {
if (plugin!=null) plugin.endTiming(event, true);
}
/**
* Ends the measusuremnt with a failure status.
* This is used by the runtime to indicate exceptions.
*/
public void failure () {
if (plugin!=null) plugin.endTiming(event, false);
}
/**
* Reports observations like the size of an RPC to the monitoring system.
* It is reported with a success status.
* @param variable the name of the parameter to report
* @param value the value of the parameter to report.
*/
public static void success (String variable, int value) {
if (plugin!=null) plugin.reportValue(variable, value, true);
}
/**
* Reports observations like the size of an RPC to the monitoring system.
* It is reprorted with a failure status; e.g. the RPC ended in an exception.
* @param variable the name of the parameter to report
* @param value the value of the parameter to report.
*/
public static void failure (String variable, int value) {
if (plugin!=null) plugin.reportValue(variable, value, false);
}
}