fulmine.event.listener
Class ActiveEventListener

java.lang.Object
  extended by fulmine.AbstractLifeCycle
      extended by fulmine.event.listener.ActiveEventListener
All Implemented Interfaces:
IEventListener, ILifeCycleEventListener, IDestroyable, ILifeCycle

public final class ActiveEventListener
extends AbstractLifeCycle
implements ILifeCycleEventListener

An active event listener implementation that uses an internal EventProcessor to execute the update logic. This is a wrapper listener for a delegate IEventListener. Any listener can be made active simply by wrapping it with this.

The active listener separates the processing of the listener update(IEvent) method from the context EventProcessor. This is only required where there is heavy-weight or thread blocking operations in the update processing.

Author:
Ramon Servadei

Constructor Summary
ActiveEventListener(IFulmineContext context, IEventListener delegate)
          Wraps a delegate IEventListener and pushes all events into the delegate using an internal EventProcessor.
ActiveEventListener(IFulmineContext context, String name, IEventListener delegate)
          Wraps a delegate IEventListener and pushes all events into the delegate using an internal EventProcessor.
 
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()
          Destroy the internal EventProcessor
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)
          Add the event to the event processor's event queue.
 
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

ActiveEventListener

public ActiveEventListener(IFulmineContext context,
                           IEventListener delegate)
Wraps a delegate IEventListener and pushes all events into the delegate using an internal EventProcessor.

Parameters:
context - the context this listener should use
delegate - the delegate event listener

ActiveEventListener

public ActiveEventListener(IFulmineContext context,
                           String name,
                           IEventListener delegate)
Wraps a delegate IEventListener and pushes all events into the delegate using an internal EventProcessor.

Parameters:
context - the context this listener should use
name - the name for the internal EventProcessor
delegate - the delegate event listener
Method Detail

update

public void update(IEvent event)
Add the event to the event processor's event queue.

Specified by:
update in interface IEventListener
Parameters:
event - the event encapsulating the update.
See Also:
IEventListener.update(IEvent)

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 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

getLog

protected AsyncLog getLog()
Description copied from class: AbstractLifeCycle
Get the log to use for the object hierarchy

Overrides:
getLog in class AbstractLifeCycle
Returns:
the log to use for the object hierarchy

doDestroy

protected void doDestroy()
Destroy the internal EventProcessor

Specified by:
doDestroy in class AbstractLifeCycle

doStart

protected void doStart()
Description copied from class: AbstractLifeCycle
Overridden in subclasses to perform custom logic on activation. Any exceptions should be thrown as a RuntimeException or subclass thereof. When this method is called, the AbstractLifeCycle.isActive() method will return true.

Specified by:
doStart in class AbstractLifeCycle

toString

public String toString()
Overrides:
toString in class AbstractLifeCycle


Copyright © 2007-2009. All Rights Reserved.