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

org.javasimon.source.AbstractStopwatchSource Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
package org.javasimon.source;

import org.javasimon.Manager;
import org.javasimon.Split;
import org.javasimon.Stopwatch;

/**
 * Base implementation for {@link MonitorSource} producings stopwatches.
 *
 * @author gquintana
 */
public abstract class AbstractStopwatchSource implements StopwatchSource {
	/**
	 * Simon manager used for producing Stopwatches.
	 */
	private final Manager manager;

	/**
	 * Constructor with {@link Manager}.
	 *
	 * @param manager Simon manager used for producing Stopwatches
	 */
	public AbstractStopwatchSource(Manager manager) {
		this.manager = manager;
	}

	@Override
	public Manager getManager() {
		return manager;
	}

	/**
	 * Default implementation returns always true.
	 *
	 * @return always true
	 */
	@Override
	public boolean isMonitored(T location) {
		return true;
	}

	/**
	 * Get monitor name for the given location.
	 */
	protected abstract String getMonitorName(T location);

	/**
	 * Provide a Stopwatch for given location.
	 *
	 * @param location Location
	 * @return Stopwatch
	 */
	@Override
	public Stopwatch getMonitor(T location) {
		return manager.getStopwatch(getMonitorName(location));
	}

	@Override
	public Split start(T location) {
		if (isMonitored(location)) {
			return getMonitor(location).start();
		}
		return Split.DISABLED;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy