01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 java.io.Serializable;
20:
21: import org.aopalliance.intercept.MethodInterceptor;
22: import org.aopalliance.intercept.MethodInvocation;
23:
24: import org.springframework.util.ConcurrencyThrottleSupport;
25:
26: /**
27: * Interceptor that throttles concurrent access, blocking invocations
28: * if a specified concurrency limit is reached.
29: *
30: * <p>Can be applied to methods of local services that involve heavy use
31: * of system resources, in a scenario where it is more efficient to
32: * throttle concurrency for a specific service rather than restricting
33: * the entire thread pool (e.g. the web container's thread pool).
34: *
35: * <p>The default concurrency limit of this interceptor is 1.
36: * Specify the "concurrencyLimit" bean property to change this value.
37: *
38: * @author Juergen Hoeller
39: * @since 11.02.2004
40: * @see #setConcurrencyLimit
41: */
42: public class ConcurrencyThrottleInterceptor extends
43: ConcurrencyThrottleSupport implements MethodInterceptor,
44: Serializable {
45:
46: public ConcurrencyThrottleInterceptor() {
47: setConcurrencyLimit(1);
48: }
49:
50: public Object invoke(MethodInvocation methodInvocation)
51: throws Throwable {
52: beforeAccess();
53: try {
54: return methodInvocation.proceed();
55: } finally {
56: afterAccess();
57: }
58: }
59:
60: }
|