E
- is the templated type of the events to send.L
- is the templated type of the listeners that can be registered
here and
that will receive
the sent events.public abstract class AbstractEventSource<E extends Event,L extends EventListener<E>> extends AbstractLoggableComponent implements EventSource<E,L>
EventListener
interface.Modifier and Type | Field and Description |
---|---|
private Collection<L> |
listeners
the registered listeners
|
Modifier | Constructor and Description |
---|---|
|
AbstractEventSource()
The constructor.
|
protected |
AbstractEventSource(CollectionFactory<? extends Collection> collectionFactory)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(L listener)
This method registers a listener that is interested in
Event s. |
protected void |
fireEvent(E event)
This method sends the given
event to all registered listeners. |
protected void |
fireEvent(E event,
L listener)
This method sends the given
event to the given listener . |
protected void |
handleListenerError(L listener,
E event,
Throwable error)
This method is called if a listener throws something while handling an event.
|
boolean |
removeListener(L listener)
This method removes a listener.
|
createLogger, doInitialize, getLogger
doInitialized, getInitializationState, initialize
private final Collection<L extends EventListener<E>> listeners
public AbstractEventSource()
protected AbstractEventSource(CollectionFactory<? extends Collection> collectionFactory)
collectionFactory
- is the collection factory used to create the internal Collection
for the
listeners.public void addListener(L listener)
EventSource
Event
s.addListener
in interface EventSource<E extends Event,L extends EventListener<E>>
listener
- is the listener to add.public boolean removeListener(L listener)
EventSource
removeListener
in interface EventSource<E extends Event,L extends EventListener<E>>
listener
- is the listener to remove.true
if the given listener
has successfully been removed, false
if the
listener
was NOT registered
.protected void fireEvent(E event)
event
to all registered
listeners.event
- the event to set.protected void fireEvent(E event, L listener)
event
to the given listener
.event
- the event to set.listener
- the listener that should receive the event
.protected void handleListenerError(L listener, E event, Throwable error)
listener
- is the listener that caused the error.event
- is the event that could not be handled.error
- is the throwable caused by the listener
while handling the event
.Copyright © 2001–2016 mmm-Team. All rights reserved.