|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
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).
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.
AroundInvoke,
Interceptors| Method Summary | |
|---|---|
Object |
intercept(InvocationContext ctx)
Intercepts an invocation. |
| Method Detail |
|---|
Object intercept(InvocationContext ctx)
throws Exception
Intercepts an invocation.
Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||