de.jaetzold.util
Class EventQueue

java.lang.Object
  |
  +--de.jaetzold.util.EventQueue

public class EventQueue
extends Object

A class for passing events from one Thread to another. Usually there is only one thread on one end, which retrieves the posted events by calling getNextEvent(). However there can be more than one Thread calling getNextEvent() but then, each event will always be returned only to one of them.


Constructor Summary
EventQueue()
           
 
Method Summary
 boolean contains(Event event)
           
 Event getNextEvent()
          Returns and deletes the next event in the queue.
 Event getNextEvent(int timeout)
          Returns and deletes the next event in the queue if there is any before the specified timeout.
 Event getNextEventEqual(Event event, int timeout)
           
 boolean isEmpty()
          Tells whether there are any events in the queue.
 Event peekNextEvent(int timeout)
          Return but not delete.
 void post(Event theEvent)
          Adds the given event-object to the end of the queue.
 boolean remove(Event theEvent)
          Removes the first occurence of an element equal to the given Event from this queue if there is any.
 int removeAll(Event theEvent)
          Removes the all elements equal to the given Event from this queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventQueue

public EventQueue()
Method Detail

isEmpty

public boolean isEmpty()
Tells whether there are any events in the queue. This only ensures that the next call to getNextEvent() does not block if both calls are in the same block, synchronized to this queue. #see #getNextEvent()

peekNextEvent

public Event peekNextEvent(int timeout)
                    throws InterruptedException
Return but not delete.

getNextEvent

public Event getNextEvent()
                   throws InterruptedException
Returns and deletes the next event in the queue. If the queue is already empty, this method blocks until a new event gets added with post(de.jaetzold.util.Event).
See Also:
post(de.jaetzold.util.Event), getNextEvent(int)

getNextEvent

public Event getNextEvent(int timeout)
                   throws InterruptedException
Returns and deletes the next event in the queue if there is any before the specified timeout. If the queue is empty, this method blocks until a new event gets added with post(de.jaetzold.util.Event) or until after timeout milliseconds have elapsed. In this case it is possible that this method returns null.
Returns:
the next Event in the Queue if there is any before the timeout, null otherwise.
See Also:
post(de.jaetzold.util.Event), getNextEvent()

post

public void post(Event theEvent)
Adds the given event-object to the end of the queue. This method notifies all Threads currently waiting on this queues monitor.

remove

public boolean remove(Event theEvent)
Removes the first occurence of an element equal to the given Event from this queue if there is any. It calls theEvent.equals() to determine equality. Implementation note: It relies on the underlying List to do it that way.
Returns:
false if there didn't exit such an element in this Queue, true otherwise

removeAll

public int removeAll(Event theEvent)
Removes the all elements equal to the given Event from this queue. All occurrences of such elements are removed by this method. It calls theEvent.equals() to determine equality. Implementation note: It relies on the underlying List to do it that way.

contains

public boolean contains(Event event)

getNextEventEqual

public Event getNextEventEqual(Event event,
                               int timeout)