KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > aop > interceptor > DebugInterceptor


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.aop.interceptor;
18
19 import org.aopalliance.intercept.MethodInvocation;
20
21 /**
22  * AOP Alliance <code>MethodInterceptor</code> that can be introduced in a chain
23  * to display verbose information about intercepted invocations to the logger.
24  *
25  * <p>Logs full invocation details on method entry and method exit,
26  * including invocation arguments and invocation count. This is only
27  * intended for debugging purposes; use <code>SimpleTraceInterceptor</code>
28  * or <code>CustomizableTraceInterceptor</code> for pure tracing purposes.
29  *
30  * @author Rod Johnson
31  * @author Juergen Hoeller
32  * @see SimpleTraceInterceptor
33  * @see CustomizableTraceInterceptor
34  */

35 public class DebugInterceptor extends SimpleTraceInterceptor {
36
37     private volatile long count;
38
39
40     /**
41      * Create a new DebugInterceptor with a static logger.
42      */

43     public DebugInterceptor() {
44     }
45
46     /**
47      * Create a new DebugInterceptor with dynamic or static logger,
48      * according to the given flag.
49      * @param useDynamicLogger whether to use a dynamic logger or a static logger
50      * @see #setUseDynamicLogger
51      */

52     public DebugInterceptor(boolean useDynamicLogger) {
53         setUseDynamicLogger(useDynamicLogger);
54     }
55
56
57     public Object JavaDoc invoke(MethodInvocation invocation) throws Throwable JavaDoc {
58         synchronized (this) {
59             this.count++;
60         }
61         return super.invoke(invocation);
62     }
63
64     protected String JavaDoc getInvocationDescription(MethodInvocation invocation) {
65         return invocation + "; count=" + this.count;
66     }
67
68
69     /**
70      * Return the number of times this interceptor has been invoked.
71      */

72     public long getCount() {
73         return this.count;
74     }
75
76     /**
77      * Reset the invocation count to zero.
78      */

79     public synchronized void resetCount() {
80         this.count = 0;
81     }
82
83 }
84
Popular Tags