fulmine.event.listener
Class AbstractEventHandler<T extends IEvent>

java.lang.Object
  extended by fulmine.event.listener.AbstractEventHandler<T>
Type Parameters:
T - the IEvent type for this handler.
All Implemented Interfaces:
IEventListener

public abstract class AbstractEventHandler<T extends IEvent>
extends Object
implements IEventListener

Base class for an object that handles a specific type of IEvent. This is generally used by an IEventListener to delegate processing of a specific event. Handlers are not designed to maintain state so do not implement the life-cycle interface.

This class and sub-classes are thread safe if the event generic parameter is a system event (system events are bound to a single EventProcessor).

Author:
Ramon Servadei
See Also:
MultiEventListener

Constructor Summary
AbstractEventHandler()
           
 
Method Summary
 void addedAsListenerFor(IEventSource source)
          The listener receives this when it has been added as a listener to an event source via IEventSource.addListener(IEventListener).
static Map<Class<? extends IEvent>,IEventListener> getEventHandlerMappings(AbstractEventHandler<? extends IEvent>... handlers)
          Given a group of AbstractEventHandler instances, this method returns a map of the handlers indexed by the IEvent class each one handles.
 Class<? extends IEvent>[] getEventTypeFilter()
          Get the classes of IEvent instances this listener can process.
protected abstract  AsyncLog getLog()
          Get the log to use
abstract  void handle(T event)
          Handle the event.
 void removedAsListenerFrom(IEventSource source)
          The listener receives this when it has been removed as a listener from an event source via IEventSource.removeListener(IEventListener).
 void update(IEvent event)
          An update has occurred that this listener is interested in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractEventHandler

public AbstractEventHandler()
Method Detail

getEventHandlerMappings

public static Map<Class<? extends IEvent>,IEventListener> getEventHandlerMappings(AbstractEventHandler<? extends IEvent>... handlers)
Given a group of AbstractEventHandler instances, this method returns a map of the handlers indexed by the IEvent class each one handles. The event for each handler is determined from the generic type argument of the handler implementation.

Parameters:
handlers - the handlers to build an IEvent indexed map of
Returns:
a Map of the handlers, indexed by the IEvent each one handles

update

public final void update(IEvent event)
Description copied from interface: IEventListener
An update has occurred that this listener is interested in. IEventSource instances are bound to EventProcessor instances so the same thread will execute this method for events originating from the same event source. This does not mean that this method is thread safe; this method may be run by multiple EventProcessor instances and so should be thread aware as appropriate.

This method can throw any Exception and processing will not be interrupted. The EventProcessor will handle the exception.

Specified by:
update in interface IEventListener
Parameters:
event - the event encapsulating the update.

addedAsListenerFor

public void addedAsListenerFor(IEventSource source)
Description copied from interface: IEventListener
The listener receives this when it has been added as a listener to an event source via IEventSource.addListener(IEventListener).

Specified by:
addedAsListenerFor in interface IEventListener
Parameters:
source - the source that this listener will receive events from.

removedAsListenerFrom

public void removedAsListenerFrom(IEventSource source)
Description copied from interface: IEventListener
The listener receives this when it has been removed as a listener from an event source via IEventSource.removeListener(IEventListener).

Specified by:
removedAsListenerFrom in interface IEventListener
Parameters:
source - the source that this listener will no longer receive events from.

getEventTypeFilter

public final Class<? extends IEvent>[] getEventTypeFilter()
Description copied from interface: IEventListener
Get the classes of IEvent instances this listener can process. The IEventListener.update(IEvent) method will only be called with IEvent instances whose Class is assignment compatible with any contained in this array.

This is an event filtering mechanism. An IEventSource may generate many types of IEvent instances but a listener may only be interested in one type. By specifying the types of events the listener is interested in using this method, the listener effectively filters out unwanted events.

If the filter is dynamic then this method must be thread aware.

Specified by:
getEventTypeFilter in interface IEventListener
Returns:
an array of Class objects that determine the types of IEvent instances this listener can process

handle

public abstract void handle(T event)
Handle the event. This will be executed using the context's EventProcessor instance that is bound to the event's source.

Parameters:
event - the event
See Also:
IEventManager.queueEvent(IEvent)

getLog

protected abstract AsyncLog getLog()
Get the log to use

Returns:
the log to use


Copyright © 2007-2009. All Rights Reserved.