/** * Find the bean name for the current invocation. Assumes that an ExposeBeanNameAdvisor * has been included in the interceptor chain, and that the invocation is exposed * with ExposeInvocationInterceptor. * @return the bean name (never {@code null}) * @throws IllegalStateException if the bean name has not been exposed */ public static String getBeanName() throws IllegalStateException { return getBeanName(ExposeInvocationInterceptor.currentInvocation()); }
/** * Create a new SimpleTraceInterceptor with dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @see #setUseDynamicLogger */ public SimpleTraceInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { synchronized (this) { this.count++; } return super.invoke(invocation); }
@Override public void absquatulate() { MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); assertions(invocation); super.absquatulate(); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { if (!context) { assertNoInvocationContext(); } else { assertNotNull("have context", ExposeInvocationInterceptor.currentInvocation()); } return s; } };
@Test(expected = IllegalArgumentException.class) public void testSetEmptyExceptionMessage() { // Must not be able to set empty exception message new CustomizableTraceInterceptor().setExceptionMessage(""); }
/** * 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); }
public TestAdvisor() { super(new SimpleTraceInterceptor()); } }
/** * Create a new PerformanceMonitorInterceptor 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 PerformanceMonitorInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }
/** * Create a new DebugInterceptor with dynamic or static logger, * according to the given flag. * @param useDynamicLogger whether to use a dynamic logger or a static logger * @see #setUseDynamicLogger */ public DebugInterceptor(boolean useDynamicLogger) { setUseDynamicLogger(useDynamicLogger); }
/** * 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); }
public ConcurrencyThrottleInterceptor() { setConcurrencyLimit(1); }
public StubCustomizableTraceInterceptor(Log log) { super.setUseDynamicLogger(false); this.log = log; }
@Test public void testSunnyDayPathLogsCorrectly() throws Throwable { MethodInvocation methodInvocation = mock(MethodInvocation.class); Log log = mock(Log.class); given(log.isTraceEnabled()).willReturn(true); DebugInterceptor interceptor = new StubDebugInterceptor(log); interceptor.invoke(methodInvocation); checkCallCountTotal(interceptor); verify(log, times(2)).trace(anyString()); }
/** * 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)); }
/** * Write the supplied trace message to the supplied {@code Log} instance. * <p>To be called by {@link #invokeUnderTrace} for enter/exit messages. * <p>Delegates to {@link #writeToLog(Log, String, Throwable)} as the * ultimate delegate that controls the underlying logger invocation. * @since 4.3.10 * @see #writeToLog(Log, String, Throwable) */ protected void writeToLog(Log logger, String message) { writeToLog(logger, message, null); }
/** * Determine whether the interceptor should kick in, that is, * whether the {@code invokeUnderTrace} method should be called. * <p>Default behavior is to check whether the given {@code Log} * instance is enabled. Subclasses can override this to apply the * interceptor in other cases as well. * @param invocation the {@code MethodInvocation} being traced * @param logger the {@code Log} instance to check * @see #invokeUnderTrace * @see #isLogEnabled */ protected boolean isInterceptorEnabled(MethodInvocation invocation, Log logger) { return isLogEnabled(logger); }
/** * Create a new advisor that will expose the given bean name, * with no introduction. * @param beanName bean name to expose */ public static Advisor createAdvisorWithoutIntroduction(String beanName) { return new DefaultPointcutAdvisor(new ExposeBeanNameInterceptor(beanName)); }
@Override public String getName() { MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation(); assertions(invocation); return super.getName(); }
/** * Throw an exception if there is an Invocation. */ private void assertNoInvocationContext() { try { ExposeInvocationInterceptor.currentInvocation(); fail("Expected no invocation context"); } catch (IllegalStateException ex) { // ok } }