/** * Wraps the invocation with a JAMon Monitor and writes the current * performance statistics to the log (if enabled). * @see com.jamonapi.MonitorFactory#start * @see com.jamonapi.Monitor#stop */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); MonKey key = new MonKeyImp(name, name, "ms."); Monitor monitor = MonitorFactory.start(key); try { return invocation.proceed(); } catch (Throwable ex) { trackException(key, ex); throw ex; } finally { monitor.stop(); if (!this.trackAllInvocations || isLogEnabled(logger)) { writeToLog(logger, "JAMon performance statistics for method [" + name + "]:\n" + monitor); } } }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @param trackAllInvocations whether to track all invocations that go through * this interceptor, or just invocations with trace logging enabled * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger, boolean trackAllInvocations) { setUseDynamicLogger(useDynamicLogger); setTrackAllInvocations(trackAllInvocations); }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); Monitor monitor = MonitorFactory.start(name); try { return invocation.proceed(); } finally { monitor.stop(); logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor); } }
/** * Always applies the interceptor if the "trackAllInvocations" flag has been set; * else just kicks in if the log is enabled. * @see #setTrackAllInvocations * @see #isLogEnabled */ @Override protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { return (this.trackAllInvocations || isLogEnabled(logger)); }
@Test public void testInvokeUnderTraceWithNormalProcessing() throws Throwable { given(mi.getMethod()).willReturn(String.class.getMethod("toString")); interceptor.invokeUnderTrace(mi, log); assertTrue("jamon must track the method being invoked", MonitorFactory.getNumRows() > 0); assertTrue("The jamon report must contain the toString method that was invoked", MonitorFactory.getReport().contains("toString")); }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }
/** * Always applies the interceptor if the "trackAllInvocations" flag has been set; * else just kicks in if the log is enabled. * @see #setTrackAllInvocations * @see #isLogEnabled */ @Override protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { return (this.trackAllInvocations || isLogEnabled(logger)); }
@Test public void testInvokeUnderTraceWithExceptionTracking() throws Throwable { given(mi.getMethod()).willReturn(String.class.getMethod("toString")); given(mi.proceed()).willThrow(new IllegalArgumentException()); try { interceptor.invokeUnderTrace(mi, log); fail("Must have propagated the IllegalArgumentException"); } catch (IllegalArgumentException expected) { } assertEquals("Monitors must exist for the method invocation and 2 exceptions", 3, MonitorFactory.getNumRows()); assertTrue("The jamon report must contain the toString method that was invoked", MonitorFactory.getReport().contains("toString")); assertTrue("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL, MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL)); assertTrue("The jamon report must contain the specific exception: IllegalArgumentException'", MonitorFactory.getReport().contains("IllegalArgumentException")); }
/** * Wraps the invocation with a JAMon Monitor and writes the current * performance statistics to the log (if enabled). * @see com.jamonapi.MonitorFactory#start * @see com.jamonapi.Monitor#stop */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); MonKey key = new MonKeyImp(name, name, "ms."); Monitor monitor = MonitorFactory.start(key); try { return invocation.proceed(); } catch (Throwable ex) { trackException(key, ex); throw ex; } finally { monitor.stop(); if (!this.trackAllInvocations || isLogEnabled(logger)) { writeToLog(logger, "JAMon performance statistics for method [" + name + "]:\n" + monitor); } } }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @param trackAllInvocations whether to track all invocations that go through * this interceptor, or just invocations with trace logging enabled * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger, boolean trackAllInvocations) { setUseDynamicLogger(useDynamicLogger); setTrackAllInvocations(trackAllInvocations); }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }
/** * Always applies the interceptor if the "trackAllInvocations" flag has been set; * else just kicks in if the log is enabled. * @see #setTrackAllInvocations * @see #isLogEnabled */ @Override protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { return (this.trackAllInvocations || isLogEnabled(logger)); }
/** * Wraps the invocation with a JAMon Monitor and writes the current * performance statistics to the log (if enabled). * @see com.jamonapi.MonitorFactory#start * @see com.jamonapi.Monitor#stop */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); MonKey key = new MonKeyImp(name, name, "ms."); Monitor monitor = MonitorFactory.start(key); try { return invocation.proceed(); } catch (Throwable ex) { trackException(key, ex); throw ex; } finally { monitor.stop(); if (!this.trackAllInvocations || isLogEnabled(logger)) { writeToLog(logger, "JAMon performance statistics for method [" + name + "]:\n" + monitor); } } }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @param trackAllInvocations whether to track all invocations that go through * this interceptor, or just invocations with trace logging enabled * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger, boolean trackAllInvocations) { setUseDynamicLogger(useDynamicLogger); setTrackAllInvocations(trackAllInvocations); }
/** * Create a new JamonPerformanceMonitorInterceptor with a dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @see #setUseDynamicLogger */ public JamonPerformanceMonitorInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }