|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object fulmine.AbstractLifeCycle fulmine.event.listener.MultiEventListener
public class MultiEventListener
An event listener that is a composition of multiple internal
IEventListener
objects that each handle a specific type of
IEvent
. Events received by this listener are passed on to the
listener that is mapped to the event's class.
This class registers itself with event sources and then passes the events to the appropriate mapped event listener. The internal listeners are never registered directly with the event sources.
This needs to locate the listener per event by checking assignment compatibility of the event with all listeners' registered event class. This could mean that multiple internal listeners receive the event if there is an intersection between the registered event class of the listeners and the current event's class.
During the AbstractLifeCycle.start()
and AbstractLifeCycle.destroy()
methods, only listeners
that are mapped to an AbstractSystemEvent
event will cause the
multi-event listener to be registered/unregistered against the event's
'singleton' source (IEventManager.getSystemEventSource(Class)
).
Constructor Summary | |
---|---|
MultiEventListener(String name,
IEventManager context,
Map<Class<? extends IEvent>,IEventListener> listeners)
Standard constructor |
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) . |
protected void |
doDestroy()
Overridden in subclasses to perform custom logic on destruction. |
protected void |
doStart()
Overridden in subclasses to perform custom logic on activation. |
Class<? extends IEvent>[] |
getEventTypeFilter()
Get the classes of IEvent instances this listener can process. |
protected AsyncLog |
getLog()
Get the log to use for the object hierarchy |
void |
removedAsListenerFrom(IEventSource source)
The listener receives this when it has been removed as a listener from an event source via IEventSource.removeListener(IEventListener) . |
String |
toString()
|
void |
update(IEvent event)
An update has occurred that this listener is interested in. |
Methods inherited from class fulmine.AbstractLifeCycle |
---|
checkActive, destroy, finalize, isActive, start |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface fulmine.ILifeCycle |
---|
isActive, start |
Methods inherited from interface fulmine.IDestroyable |
---|
destroy |
Constructor Detail |
---|
public MultiEventListener(String name, IEventManager context, Map<Class<? extends IEvent>,IEventListener> listeners)
name
- the name for thiscontext
- the event context to uselisteners
- maps the IEvent
type to the IEventListener
object that will process events of that typeMethod Detail |
---|
protected void doDestroy()
AbstractLifeCycle
RuntimeException
or subclass
thereof.
doDestroy
in class AbstractLifeCycle
protected AsyncLog getLog()
AbstractLifeCycle
getLog
in class AbstractLifeCycle
protected void doStart()
AbstractLifeCycle
RuntimeException
or subclass
thereof. When this method is called, the AbstractLifeCycle.isActive()
method will
return true
.
doStart
in class AbstractLifeCycle
public final void update(IEvent event)
IEventListener
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.
update
in interface IEventListener
event
- the event encapsulating the update.public void addedAsListenerFor(IEventSource source)
IEventListener
IEventSource.addListener(IEventListener)
.
addedAsListenerFor
in interface IEventListener
source
- the source that this listener will receive events from.public void removedAsListenerFrom(IEventSource source)
IEventListener
IEventSource.removeListener(IEventListener)
.
removedAsListenerFrom
in interface IEventListener
source
- the source that this listener will no longer receive events
from.public Class<? extends IEvent>[] getEventTypeFilter()
IEventListener
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.
getEventTypeFilter
in interface IEventListener
Class
objects that determine the types of
IEvent
instances this listener can processpublic final String toString()
toString
in class AbstractLifeCycle
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |