Java Reference
In-Depth Information
Using Multiple Timeout Interceptors
Multiple timeout interceptors may be defined for a given target class by specifying the
interceptor classes containing @AroundTimeout interceptor methods in an @Inter-
ceptors annotation at the class level.
If a target class specifies timeout interceptors in an interceptor class, and also has a
@AroundTimeout interceptor method within the target class itself, the timeout inter-
ceptors in the interceptor classes are called first, followed by the timeout interceptors
defined in the target class. For example, in the following example, assume that both the
PrimaryInterceptor and SecondaryInterceptor classes have timeout inter-
ceptor methods.
Click here to view code image
@Interceptors({PrimaryInterceptor.class, SecondaryIntercept-
or.class})
@Stateful
public class OrderBean {
...
@AroundTimeout
private void last(InvocationContext ctx) { ... }
...
}
The timeout interceptor in PrimaryInterceptor will be called first, followed by
the timeout interceptor in SecondaryInterceptor , and finally the last method
defined in the target class.
The interceptor Example Application
The interceptor example demonstrates how to use an interceptor class, containing an
@AroundInvoke interceptor method, with a stateless session bean.
The HelloBean stateless session bean is a simple enterprise bean with two business
methods, getName and setName , to retrieve and modify a string. The setName busi-
ness method has an @Interceptors annotation that specifies an interceptor class,
HelloInterceptor , for that method.
@Interceptors(HelloInterceptor.class)
public void setName(String name) {
this.name = name;
}
Search WWH ::




Custom Search