@SuppressWarnings("unchecked") public static <T> T newProxy(T proxied, Class<?>... classes) { MetricInvocationHandler<T> handler = new MetricInvocationHandler<T>(proxied); return (T) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), classes, handler); }
protected Stopwatch getStopwatch(Method m, Object[] parms) { String name = formatName(m, parms); Stopwatch stopwatch = SimonManager.getStopwatch(name); stopwatch.setNote(formatNote(m, parms)); return stopwatch; }
protected String formatNote(Method m, Object[] parms) { return String.format("%s#%s(%s)", m.getDeclaringClass().getSimpleName(), m.getName(), formatParms(parms)); }
@Override public Mapper newMapper(PathResolver pathResolver, boolean useInvalidations) { return MetricInvocationHandler.newProxy(wrapped.newMapper(pathResolver, useInvalidations), Mapper.class); }
@Override public Object invoke(Object proxy, Method m, Object[] parms) throws Throwable { Split split = getStopwatch(m, parms).start(); try { return m.invoke(proxied, parms); } catch (InvocationTargetException e) { throw e.getTargetException(); } finally { split.stop(); } }
@Override public void activate(ComponentContext context) { super.activate(context); if (Boolean.valueOf(Framework.getProperty(BinaryMetadataConstants.BINARY_METADATA_MONITOR, Boolean.toString(log.isTraceEnabled())))) { metadataService = MetricInvocationHandler.newProxy(metadataService, BinaryMetadataService.class); } }