ptolemy.domains.de.kernel
Class DECQEventQueue

java.lang.Object
  extended byptolemy.domains.de.kernel.DECQEventQueue
All Implemented Interfaces:
Debuggable, DEEventQueue

public class DECQEventQueue
extends java.lang.Object
implements DEEventQueue

A calendar queue implementation of the DE event queue. This stores DE events in the order of their time stamps, microstep and the depth of the destination actor. One DEEvent is said to be earlier than another if it has a smaller time stamp, or when the time stamps are identical and it has a smaller microstep, or when both time stamps and microsteps are identical and it has a smaller depth.

Its complexity is theoretically O(1) for both enqueue and dequeue operations, assuming a reasonable distribution of time stamps.

Since:
Ptolemy II 0.2
Version:
$Id: DECQEventQueue.java,v 1.40 2004/04/13 03:28:56 cxh Exp $
Author:
Lukito Muliadi, Edward A. Lee, Jie Liu
See Also:
DEReceiver, CalendarQueue, DEEventQueue, DEDirector
Accepted Rating:
Green (cxh)
Proposed Rating:
Green (liuj)

Constructor Summary
DECQEventQueue()
          Construct an empty event queue.
DECQEventQueue(int minBinCount, int binCountFactor, boolean isAdaptive)
          Construct an empty event queue with a minimum bin number a bin count factor, and a boolean indicating whether the queue is adaptive.
 
Method Summary
 void addDebugListener(DebugListener listener)
          Append a listener to the current set of debug listeners.
 void clear()
          Empty the event queue.
 DEEvent get()
          Return the earliest event in the queue without removing the event from the queue.
 boolean isEmpty()
          Return true if this event queue is empty.
 void put(DEEvent event)
          Enqueue an event into the event queue and notify all threads that are stalled waiting for an event to be put in the queue.
 void removeDebugListener(DebugListener listener)
          Unregister a debug listener.
 DEEvent take()
          Dequeue the earliest event in this event queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DECQEventQueue

public DECQEventQueue()
Construct an empty event queue. The calendar queue takes its default parameter, i.e. minBinCount is 2, binCountFactor is 2, and isAdaptive is true.


DECQEventQueue

public DECQEventQueue(int minBinCount,
                      int binCountFactor,
                      boolean isAdaptive)
Construct an empty event queue with a minimum bin number a bin count factor, and a boolean indicating whether the queue is adaptive.

Parameters:
minBinCount - The minimum number of bins.
binCountFactor - The factor when changing the bin count.
isAdaptive - If the queue changes its number of bins at run time.
Method Detail

addDebugListener

public void addDebugListener(DebugListener listener)
Append a listener to the current set of debug listeners. If the listener is already in the set, do nothing.

Specified by:
addDebugListener in interface Debuggable
Parameters:
listener - A listener to which to send debug messages.

clear

public void clear()
Empty the event queue. This method is synchronized since there may be actors running under different threads in the DE domain.

Specified by:
clear in interface DEEventQueue

get

public final DEEvent get()
Return the earliest event in the queue without removing the event from the queue. This method is synchronized since there may be actors running under different threads in the DE domain.

Specified by:
get in interface DEEventQueue
Returns:
The smallest event in the queue.
Throws:
InvalidStateException - If the queue is empty.

isEmpty

public final boolean isEmpty()
Return true if this event queue is empty. This method is synchronized since there may be actors running under different threads in the DE domain.

Specified by:
isEmpty in interface DEEventQueue
Returns:
True if there are no event in the queue.

put

public final void put(DEEvent event)
Enqueue an event into the event queue and notify all threads that are stalled waiting for an event to be put in the queue. This method is synchronized since there may be actors running under different threads in the DE domain.

Specified by:
put in interface DEEventQueue
Parameters:
event - The event to enqueue.

removeDebugListener

public void removeDebugListener(DebugListener listener)
Unregister a debug listener. If the specified listener has not been previously registered, then do nothing.

Specified by:
removeDebugListener in interface Debuggable
Parameters:
listener - The listener to remove from the list of listeners to which debug messages are sent.

take

public final DEEvent take()
Dequeue the earliest event in this event queue. This method is synchronized since there may be actors running under different threads in the DE domain.

Specified by:
take in interface DEEventQueue
Returns:
The earliest event in the queue.
Throws:
InvalidStateException - If the queue is empty.