org.beanlet
Interface Interceptor


public interface Interceptor

Classes implementing this interface can configured to intercept invocations. These classes are constructed by their (typically implicit) public accessible constructor. Example (A) shows how to implement an interceptor using this interface. A more sophisticated interceptor is listed at example (B).

Examples

(A) Example of an interceptor implementing the Interceptor interface:
 public class ExampleInterceptor implements Interceptor {

     public Object intercept(InvocationContext ctx) throws Exception {
         try {
             // Run code before the invocation...
             return ctx.proceed();
         } finally {
             // Run code after the invocation...
         }
     }
 }
 
(B) Example of an interceptor that provides some very basic fail-over functionality:
 public class ExampleInterceptor implements Interceptor {
     
     public Object intercept(InvocationContext ctx) throws Exception {
         try {
             return ctx.proceed();
         } catch (IOException e) {
             // Re-establish the connection.
             ((Foo) ctx.getTarget()).connect();

             // Retry invocation.
             return ctx.proceed();
         }
     }
 }
 

A more powerful alternative to this interface is the AroundInvoke annotation.

See Also:
AroundInvoke, Interceptors

Method Summary
 Object intercept(InvocationContext ctx)
          Intercepts an invocation.
 

Method Detail

intercept

Object intercept(InvocationContext ctx)
                 throws Exception

Intercepts an invocation.

Throws:
Exception


Copyright © 2006-2012. All Rights Reserved.