edu.vub.at.actors.eventloops
Class EventQueue

java.lang.Object
  extended byedu.vub.at.actors.eventloops.EventQueue

public final class EventQueue
extends java.lang.Object

A simple synchronized blocking FIFO queue implementation. The buffer will grow dynamically to accomodate more events when necessary.

Author:
tvcutsem

Field Summary
private static int _DEFAULT_QUEUE_SIZE_
           
private  java.util.Vector elements_
           
 
Constructor Summary
EventQueue()
           
 
Method Summary
 Event dequeue()
          Dequeue an event from the buffer.
 void enqueue(Event event)
          Enqueue an event in the buffer.
 void enqueueFirst(Event event)
          Enqueue an event as the first to be executed in the buffer.
 java.util.Vector flush()
          Clears the content of the buffer and returns the old contents.
 boolean isEmpty()
          Tests whether the event queue is empty.
 void merge(java.util.Vector contents)
          Allows for restoring the buffer's old contents by putting the elements in contents in front of the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_DEFAULT_QUEUE_SIZE_

private static final int _DEFAULT_QUEUE_SIZE_
See Also:
Constant Field Values

elements_

private final java.util.Vector elements_
Constructor Detail

EventQueue

public EventQueue()
Method Detail

enqueue

public void enqueue(Event event)
Enqueue an event in the buffer. This method wakes up any waiting consumer threads.


enqueueFirst

public void enqueueFirst(Event event)
Enqueue an event as the first to be executed in the buffer. This method wakes up any waiting consumer threads.


dequeue

public Event dequeue()
              throws java.lang.InterruptedException
Dequeue an event from the buffer. This method will block when the buffer is empty!

Returns:
the dequeued event.
Throws:
java.lang.InterruptedException - if the thread is interrupted while waiting on an empty buffer.

flush

public java.util.Vector flush()
Clears the content of the buffer and returns the old contents.

Returns:
the buffer's content at the time it was flushed

merge

public void merge(java.util.Vector contents)
Allows for restoring the buffer's old contents by putting the elements in contents in front of the buffer.


isEmpty

public boolean isEmpty()
Tests whether the event queue is empty. This test is provided to allow clients of the queue to perform synchronization on an external resource if necessary.