fulmine.event
Class EventProcessor

java.lang.Object
  extended by fulmine.AbstractLifeCycle
      extended by fulmine.event.EventProcessor
All Implemented Interfaces:
IDestroyable, ILifeCycle, ITaskHandler<IEvent>

public final class EventProcessor
extends AbstractLifeCycle
implements ILifeCycle, ITaskHandler<IEvent>

A single-thread execution engine that takes IEvent objects off a task queue, finds the IEventListener instances registered against the IEventSource that generated the event, determines if the event is compatible with the events the listener can accept (see IEventListener.getEventTypeFilter()) and calls IEventListener.update(IEvent) if the event is compatible.

On shutdown via the AbstractLifeCycle.destroy() method, a special event ( shutdownEvent) is added to the processor's #events. The processor continues to process its event queue after the destroy method but when the processor encounters the shutdown event, it shuts down and the processor thread ceases execution. This technique allows the event queue to be drained before the processor terminates. There may be some situations where events that are generated during the context shutdown need to be processed (e.g. UnsubscribeEvents may need to be handled by closing external resources gracefully) and this delayed shutdown allows this to be achieved.

Author:
Ramon Servadei

Constructor Summary
EventProcessor(String name, IFulmineContext context)
          Standard constructor for an event processor backed by a standard priority thread.
EventProcessor(String name, ThreadGroup threadGroup, IFulmineContext context)
          Constructor for an event processor backed by a thread of priority equal to the maximum priority of the thread group argument
 
Method Summary
protected  void doDestroy()
          Destroy the processor.
protected  void doStart()
          Overridden in subclasses to perform custom logic on activation.
static IEventFrameExecution getCurrentFrame()
          Get the frame identifier of the event the processor is currently handling.
protected  AsyncLog getLog()
          Get the log to use for the object hierarchy
 String getStackTrace()
          Get the current stack trace for the EventProcessor
 void handleTask(IEvent task)
          Handle the task.
 void queue(IEvent event)
          Add the event onto the processor's queue
 String toString()
           
 
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

EventProcessor

public EventProcessor(String name,
                      IFulmineContext context)
Standard constructor for an event processor backed by a standard priority thread. The thread is held in the FulmineContext normal priority thread group.

Parameters:
name - the name of the thread for the processor
context - the context this processor is associated with

EventProcessor

public EventProcessor(String name,
                      ThreadGroup threadGroup,
                      IFulmineContext context)
Constructor for an event processor backed by a thread of priority equal to the maximum priority of the thread group argument

Parameters:
name - the name of the thread for the processor
threadGroup - the thread group for the thread, this also defines the priority of the thread
context - the context this processor is associated with
Method Detail

getCurrentFrame

public static final IEventFrameExecution getCurrentFrame()
Get the frame identifier of the event the processor is currently handling. This is thread-bound.

Returns:
the IEventFrameExecution of the event that is being processed.

handleTask

public void handleTask(IEvent task)
Description copied from interface: ITaskHandler
Handle the task.

Specified by:
handleTask in interface ITaskHandler<IEvent>
Parameters:
task - the task to 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 processor.

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

queue

public void queue(IEvent event)
Add the event onto the processor's queue

Parameters:
event - the event to add the queue

getStackTrace

public String getStackTrace()
Get the current stack trace for the EventProcessor

Returns:
a formatted String of the current stack trace with each stack call on a new line

toString

public String toString()
Overrides:
toString in class AbstractLifeCycle


Copyright © 2007-2009. All Rights Reserved.