org.javasimon.source.AbstractMethodStopwatchSource Maven / Gradle / Ivy
package org.javasimon.source;
import java.lang.reflect.Method;
import org.javasimon.Manager;
/**
* Base class for Stopwatch sources working on method locations.
*
* @author gquintana
*/
public abstract class AbstractMethodStopwatchSource extends AbstractStopwatchSource {
/**
* Constructor using specific simon manager.
*
* @param manager Simon manager
*/
public AbstractMethodStopwatchSource(Manager manager) {
super(manager);
}
/**
* Get target class from location.
*
* @param location Location
* @return Target class
*/
protected abstract Class> getTargetClass(T location);
/**
* Get target method from location.
*
* @param location Location
* @return Target method
*/
protected abstract Method getTargetMethod(T location);
/**
* Wraps this data source in a cache.
*
* @return Cache monitor source
*/
public CachedStopwatchSource cache() {
return newCacheStopwatchSource(this);
}
/**
* Wraps given stopwatch source in a cache.
*
* @param stopwatchSource Stopwatch source
* @return Cached stopwatch source
*/
private static CachedStopwatchSource newCacheStopwatchSource(final AbstractMethodStopwatchSource stopwatchSource) {
return new CachedStopwatchSource(stopwatchSource) {
@Override
protected Method getLocationKey(T location) {
return stopwatchSource.getTargetMethod(location);
}
};
}
}