Java Reference
In-Depth Information
the server. Here you'll focus on using this interceptor on the
LandingController
. The
LandingController
class backs the welcome page for ActionBazaar. If this page is
slow, users might not continue browsing the rest of the site.
The
PerformanceMonitor
annotation is defined as follows:
@InterceptorBinding
@Retention(RUNTIME)
@Target({TYPE})
public @interface PerformanceMonitor {}
This annotation is itself annotated with the
@InterceptorBinding
. When CDI re-
flects on this annotation, it'll discover that you're requesting the method or methods to be
wrapped with an interceptor. CDI will then create an instance of the inceptor. After defin-
ing the interceptor annotation, you need to define the interceptor implementation, as shown
in the following listing.
Listing 12.12. Performance interceptor implementation
In this listing the interceptor implementation is defined. The interceptor must be annotated
with the annotation to associate the interceptor with the annotation. The implement-
ation must also be annotated with the
@Interceptor
annotation to mark this class as
an interceptor . The
@AroundInvoke
annotation marks the method that will actu-
ally handle the interception. Within this method, you can get information about the method
you're intercepting along with its parameters via the
InvocationContext
. Using the
proceed method, you can invoke the method you're wrapping or you can choose not to in-
voke the method if you want.