net.sf.mmm.util.event.base
Class AbstractEventSource<E extends Event,L extends EventListener<E>>

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.event.base.AbstractEventSource<E,L>
Type Parameters:
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.
All Implemented Interfaces:
EventSource<E,L>
Direct Known Subclasses:
AbstractSynchronizedEventSource

public abstract class AbstractEventSource<E extends Event,L extends EventListener<E>>
extends AbstractLoggableComponent
implements EventSource<E,L>

This is the abstract base implementation of the EventListener interface.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  Collection<L> listeners
          the registered listeners
 
Constructor Summary
  AbstractEventSource()
          The constructor.
protected AbstractEventSource(CollectionFactory<? extends Collection> collectionFactory)
          The constructor.
 
Method Summary
 void addListener(L listener)
          This method registers a listener that is interested in Events.
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.
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
doInitialize, getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

private final Collection<L extends EventListener<E>> listeners
the registered listeners

Constructor Detail

AbstractEventSource

public AbstractEventSource()
The constructor.


AbstractEventSource

protected AbstractEventSource(CollectionFactory<? extends Collection> collectionFactory)
The constructor.

Parameters:
collectionFactory - is the collection factory used to create the internal Collection for the listeners.
Method Detail

addListener

public void addListener(L listener)
This method registers a listener that is interested in Events.

Specified by:
addListener in interface EventSource<E extends Event,L extends EventListener<E>>
Parameters:
listener - is the listener to add.

removeListener

public boolean removeListener(L listener)
This method removes a listener. If the listener was not registered before this method does not do any change.

Specified by:
removeListener in interface EventSource<E extends Event,L extends EventListener<E>>
Parameters:
listener - is the listener to remove.
Returns:
true if the given listener has successfully been removed, false if the listener was NOT registered.

fireEvent

protected void fireEvent(E event)
This method sends the given event to all registered listeners.

Parameters:
event - the event to set.

fireEvent

protected void fireEvent(E event,
                         L listener)
This method sends the given event to the given listener.

Parameters:
event - the event to set.
listener - the listener that should receive the event.

handleListenerError

protected void handleListenerError(L listener,
                                   E event,
                                   Throwable error)
This method is called if a listener throws something while handling an event.
The default implementation is log the error. Override this method to change the behaviour (e.g. ignore the problem, remove the "evil" listener, throw the error anyways).

Parameters:
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-2010 mmm-Team. All Rights Reserved.