edu.berkeley.psi.seda.generic
Class EventSink

java.lang.Object
  extended by seda.sandStorm.core.FiniteQueue
      extended by edu.berkeley.psi.seda.generic.EventSink
All Implemented Interfaces:
java.lang.Runnable, ProfilableIF, QueueIF, SinkIF, SourceIF

public class EventSink
extends FiniteQueue
implements java.lang.Runnable

A simple SinkIF which accepts QueueElementIFs and calls an EventHandlerIF. This is a light-weight alternative to a full Stage which can provide in-order servicing of events.


Field Summary
private  java.util.concurrent.atomic.AtomicBoolean closed
           
private static int DEBUG_LEVEL
           
protected  EventHandlerIF eh
           
private  java.util.concurrent.atomic.AtomicBoolean started
           
private  java.lang.Thread thread
           
 
Constructor Summary
EventSink(EventHandlerIF eh)
          Create an unnamed EventSink with no EnqueuePredicateIF.
EventSink(EventHandlerIF eh, EnqueuePredicateIF ep)
          Create an unnamed EventSink with an EnqueuePredicateIF.
EventSink(EventHandlerIF eh, java.lang.String name)
          Create a named EventSink with no EnqueuePredicateIF.
 
Method Summary
 void close()
          interrupts the thread and causes it to shut down immediately
private static boolean DEBUG(int n)
           
 void enqueue_many(QueueElementIF[] enqueueMe)
          Envokes the superclass enqueue_many() and makes sure we are servicing the queue.
 void enqueue(QueueElementIF enqueueMe)
          Envokes the superclass enqueue() and makes sure we are servicing the queue.
private  void jumpStart()
          Makes sure we are servicing the queue, starting a new thread otherwise.
 void run()
           
 java.lang.String toString()
           
 
Methods inherited from class seda.sandStorm.core.FiniteQueue
blocking_dequeue_all, blocking_dequeue, blocking_dequeue, blocking_dequeue, dequeue_all, dequeue, dequeue, dequeue, enqueue_abort, enqueue_commit, enqueue_lossy, enqueue_prepare, getEnqueuePredicate, getName, profileSize, setEnqueuePredicate, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG_LEVEL

private static final int DEBUG_LEVEL
See Also:
Constant Field Values

started

private java.util.concurrent.atomic.AtomicBoolean started

thread

private java.lang.Thread thread

closed

private java.util.concurrent.atomic.AtomicBoolean closed

eh

protected EventHandlerIF eh
Constructor Detail

EventSink

public EventSink(EventHandlerIF eh)
Create an unnamed EventSink with no EnqueuePredicateIF.


EventSink

public EventSink(EventHandlerIF eh,
                 java.lang.String name)
Create a named EventSink with no EnqueuePredicateIF.


EventSink

public EventSink(EventHandlerIF eh,
                 EnqueuePredicateIF ep)
Create an unnamed EventSink with an EnqueuePredicateIF.

Method Detail

DEBUG

private static final boolean DEBUG(int n)

enqueue

public void enqueue(QueueElementIF enqueueMe)
             throws SinkFullException
Envokes the superclass enqueue() and makes sure we are servicing the queue.

Specified by:
enqueue in interface SinkIF
Overrides:
enqueue in class FiniteQueue
Parameters:
enqueueMe - The QueueElementIF to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.

enqueue_many

public void enqueue_many(QueueElementIF[] enqueueMe)
                  throws SinkFullException
Envokes the superclass enqueue_many() and makes sure we are servicing the queue.

Specified by:
enqueue_many in interface SinkIF
Overrides:
enqueue_many in class FiniteQueue
Parameters:
enqueueMe - The element array to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.

jumpStart

private final void jumpStart()
Makes sure we are servicing the queue, starting a new thread otherwise.


run

public void run()
Specified by:
run in interface java.lang.Runnable

toString

public java.lang.String toString()
Overrides:
toString in class FiniteQueue

close

public void close()
interrupts the thread and causes it to shut down immediately