Interceptor接口

/* 这个接口代表一个通用的拦截器。 * 通用拦截器能够拦挡在根底程序中产生的运行时事件。这些工夫具体化为Joinpint(连接点)。运行时连接点能够是调用、字段拜访、异样等等。 * 这个接口通常不会间接应用。用子接口拦挡具体的事件。 例如,上面的类实现了具体的拦截器来实现调试器。 * class DebuggingInterceptor implements MethodInterceptor, *     ConstructorInterceptor { * *   Object invoke(MethodInvocation i) throws Throwable { *     debug(i.getMethod(), i.getThis(), i.getArgs()); *     return i.proceed(); *   } * *   Object construct(ConstructorInvocation i) throws Throwable { *     debug(i.getConstructor(), i.getThis(), i.getArgs()); *     return i.proceed(); *   } *  *   void debug(AccessibleObject ao, Object this, Object value) { *     ... *   } * }  public interface Interceptor extends Advice {  }

MethodInterceptor接口

/* 在接口达到指标的途中拦挡接口上的调用。它们嵌套在指标的“顶部”。 用户应该实现 invoke(MethodInvacation) 办法,来批改原来的行为。一下的类 实现了一个跟踪拦截器 * class TracingInterceptor implements MethodInterceptor { *   Object invoke(MethodInvocation i) throws Throwable { *     System.out.println("method "+i.getMethod()+" is called on "+ *                        i.getThis()+" with args "+i.getArguments()); *     Object ret=i.proceed(); *     System.out.println("method "+i.getMethod()+" returns "+ret); *     return ret; *   } * }  @FunctionalInterfacepublic interface MethodInterceptor extends Interceptor {    @Nullable    Object invoke(@Nonnull MethodInvocation invocation) throws Throwable;}