|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Interceptor
This interface is a marker that interceptor objects must implement. Interceptor classes are expected to defined methods that correspond to the event types (or classes) they expect. Events are objects that encapsulate state and are handled to the call back interceptor methods.
For example, suppose we define a given "event", through the
LogEvent class (note that the "event" string does not need to
appear in the class name). To intercept instances of this event, an
interceptor needs to be implemented, which will have the following
method:
public void onLogEvent(LogEvent evt);
As shown below, the method's signature must have the following pattern:
onEventClassName(EventClass)
Once an interceptor class has been designed, it can be registered with a dispatcher to intercept events of the specified class:
SingleDispatcher disp = new SingleDispatcher(); LogInterceptor it = new LogInterceptor(); disp.registerInterceptor(LogEvent.class, it); // the following event will be intercepted by our interceptor. disp.dispatch(new LogEvent());
As one might have guessed, Java's introspection capabilities are used to match the event class to the proper interceptor method at registration time. This one-event-per-method scheme allows one interceptor to register for multiple event types.
Dispatching behavior and event registration policies can vary from one dispatcher to another.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||