001package org.javasimon.proxy;
002
003import java.lang.reflect.Method;
004
005import org.javasimon.Manager;
006import org.javasimon.SimonManager;
007import org.javasimon.source.AbstractMethodStopwatchSource;
008
009/**
010 * Stopwatch source for use with proxy.
011 *
012 * @author gquintana
013 */
014public class ProxyStopwatchSource<T> extends AbstractMethodStopwatchSource<DelegatingMethodInvocation<T>> {
015
016        /** Prefix used for simon name. */
017        private String prefix = "org.javasimon.proxy";
018
019        public ProxyStopwatchSource() {
020                super(SimonManager.manager());
021        }
022
023        public ProxyStopwatchSource(Manager manager) {
024                super(manager);
025        }
026
027        public String getPrefix() {
028                return prefix;
029        }
030
031        public void setPrefix(String prefix) {
032                this.prefix = prefix;
033        }
034
035        @Override
036        protected String getMonitorName(DelegatingMethodInvocation<T> location) {
037                final String className = getTargetClass(location).getSimpleName();
038                final String methodName = location.getMethod().getName();
039                return prefix + Manager.HIERARCHY_DELIMITER + className + Manager.HIERARCHY_DELIMITER + methodName;
040        }
041
042        @Override
043        protected final Class<?> getTargetClass(DelegatingMethodInvocation<T> location) {
044                return location.getDelegate().getClass();
045        }
046
047        @Override
048        protected final Method getTargetMethod(DelegatingMethodInvocation<T> location) {
049                return location.getMethod();
050        }
051}