BEA Systems, Inc.

com.connecterra.util.event
Class AbstractEventProcessor

java.lang.Object
  extended by com.connecterra.util.event.AbstractEventProcessor
All Implemented Interfaces:
EventProcessor
Direct Known Subclasses:
AbstractPhysicalDevice, AbstractWorkflowModulePlugin

public class AbstractEventProcessor
extends Object
implements EventProcessor

This class encapsulates a common pattern of use of EventReceiver and EventProcessor. This class optionally creates and then holds an EventReceiver instance, and implements the EventProcessor interface. It provides a set of protected methods for queueing Event instances on the receiver which are then handled, either one at a time and in order, or scheduled for the future, on threads in the Scheduler.


Nested Class Summary
protected static class AbstractEventProcessor.PeriodicEventHandle
          This class contains the state for a periodic event.
 
Method Summary
protected  void doASAP(Event task)
          Queues an Event immediately.
protected  void doASAPOrBlock(Event task)
          Queues an Event immediately.
protected  void doASAPOrDrop(Event task)
          Queues an Event immediately.
protected  void doASAPOrThrow(Event task)
          Queues an Event immediately.
protected  void doLater(long delay, Event task)
          Queues an event to be handled after delay milliseconds.
protected  void doPeriodic(AbstractEventProcessor.PeriodicEventHandle handle, long interval, PeriodicEvent task)
          Queues an event whose handler will be invoked every interval milliseconds until cancelled, by calling the PeriodicEvent.stop() method on the event or by calling doPeriodic again with the same handle.
protected  EventReceiver getEventReceiver()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.connecterra.util.event.EventProcessor
handleEvent
 

Method Detail

getEventReceiver

protected EventReceiver getEventReceiver()
Returns:
the EventReceiver which handles queued events.

doASAP

protected void doASAP(Event task)
Queues an Event immediately. Because this method queues the event event if the queue is over the high water mark, it should be avoided except when necessary. Instead, AbstractEventProcessor.doASAPOrBlock(com.connecterra.util.event.Event), AbstractEventProcessor.doASAPOrThrow(com.connecterra.util.event.Event), or AbstractEventProcessor.doASAPOrDrop(com.connecterra.util.event.Event) should be used, depending on the appropriate behavior for that event.

Parameters:
task - the Event to be queued

doASAPOrBlock

protected void doASAPOrBlock(Event task)
                      throws InterruptedException
Queues an Event immediately. If the queue is at or above the high water mark, then the method blocks until the queue shrinks below the high water mark.

Parameters:
task - the Event to be queued
Throws:
InterruptedException - if the thread is interrupted while the call is blocked waiting for the queue to shrink below the high water mark.

doASAPOrDrop

protected void doASAPOrDrop(Event task)
Queues an Event immediately. If the queue is at or above the high water mark, then the event is silently dropped.

Parameters:
task - the Event to be queued

doASAPOrThrow

protected void doASAPOrThrow(Event task)
                      throws QueueFullException
Queues an Event immediately. If the queue is at or above the high water mark, then QueueFullException is thrown.

Parameters:
task - the Event to be queued
Throws:
QueueFullException - if the queue is at or above the high water mark

doLater

protected void doLater(long delay,
                       Event task)
Queues an event to be handled after delay milliseconds. The AlarmClock instance passed to the constructor or AbstractEventProcessor.initialize(com.connecterra.util.event.EventReceiver, com.connecterra.util.event.AlarmClock) method is used to perform the delay.

Parameters:
delay - the number of milliseconds in the future after which the event will be queued.
task - the Event to be handled later
Throws:
IllegalStateException - if the AbstractEventProcessor was created with no AlarmClock.

doPeriodic

protected void doPeriodic(AbstractEventProcessor.PeriodicEventHandle handle,
                          long interval,
                          PeriodicEvent task)
Queues an event whose handler will be invoked every interval milliseconds until cancelled, by calling the PeriodicEvent.stop() method on the event or by calling doPeriodic again with the same handle.

The interval specifies the time between the start of each successive invocation. For example, if the interval is 100 ms and the handler takes 12 ms to run, then the next invocation will occur 88 ms after the previous one finishes. If an invocation takes longer than the interval, then the next invocation is queued immediately.

Parameters:
handle - a PeriodicEventHandle instance
interval - the time in milliseconds between invocations of the event handler.
task - a PeriodicEvent value

Documentation is available at
${DOCSWEBROOT}
Copyright 2007 BEA Systems Inc.