|
Copyright © 2000, 2009, Oracle and/or its affiliates. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface EventListener
Event Listener. Implementations of this interface can handle events dispatched to an EventHandler.
An Event Listener expresses interest in handling some set of Event types by implementing getTypes() to return the Event type names that it should handle. The EventHandler is responsible for dispatching incoming Events to registered listeners based on the Event type. The default implementation of the EventHandler is the EventService EJB Session Bean.
Any Events dispatched to the EventHandler are sent to registered EventListeners handleEvent() method. Implement this method to do the action required when the event occurs. The EventService implementation notifies all EventListeners synchronously (although in no particular order) calling handleEvent() upon each EventListener on the same thread.
An AsychronousEvenService may be configured with (the same) EventListeners, as an alternative. The only difference is in this case a separate thread from a thread pool is used. One thread per event (not per EventListener).
Thus, every effort should still be made to have the handleEvent methods as efficient as possible. If some action is to take a significant amount of time or other resources, consider making handleEvent asynchronous via some service such as JMS.
NOTE: All implementations of EventListener are required to
have a no-args constructor - i.e. so that new EventListener()
will work.
EventListener implementations should implement equals() is such a way that multiple listeners will not be added to the same handler. Simple listeners (where any instance of the class is equivalent to any other) may want to use the following implementaion.
public boolean equals( Object theOther ) { // Consider listeners of the same class as equivalent return theOther != null && theOther.getClass() == this.getClass(); }
Event
,
for description of how to register listeners with the
EventService.
Method Summary | |
---|---|
String[] |
getTypes()
This method lets the EventListener advertise what types it is interested in. |
void |
handleEvent(Event theEvent)
Implement this method to "do the action" that is required when an event is dispatched to the EventHandler. |
Method Detail |
---|
String[] getTypes()
void handleEvent(Event theEvent)
theEvent
- the event that happened.
|
Copyright © 2000, 2009, Oracle and/or its affiliates. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |