ptolemy.domains.de.kernel
Class DECQEventQueue

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

public class DECQEventQueue
extends java.lang.Object
implements DEEventQueue

A calendar queue implementation of the DE event queue. This queue stores DE events in the order of their timestamps, microsteps, and then depths of their destination actors. See DEEventQueue for more explanation of the order of DE events.

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

Since:
Ptolemy II 0.2
Version:
$Id: DECQEventQueue.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Lukito Muliadi, Edward A. Lee, Jie Liu, Haiyang Zheng
Accepted Rating:
Green (hyzheng)
Proposed Rating:
Green (hyzheng)

Nested Class Summary
private static class DECQEventQueue.DECQComparator
           
 
Field Summary
private  CalendarQueue _cQueue
           
 
Constructor Summary
DECQEventQueue()
          Construct an empty event queue.
DECQEventQueue(int minBinCount, int binCountFactor, boolean isAdaptive)
          Construct an empty event queue with the specified parameters.
 
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 DE event in the queue without removing it from the queue.
 boolean isEmpty()
          Return true if this event queue is empty.
 void put(DEEvent event)
          Put an event into the event queue.
 void removeDebugListener(DebugListener listener)
          Unregister a debug listener.
 int size()
          Return the size of the event queue.
 DEEvent take()
          Dequeue the earliest DE event in this event queue.
 java.lang.Object[] toArray()
          Return the events currently in the queue as an array.
 java.lang.String toString()
          Describe the Contents of the queue as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_cQueue

private CalendarQueue _cQueue
Constructor Detail

DECQEventQueue

public DECQEventQueue()
Construct an empty event queue.


DECQEventQueue

public DECQEventQueue(int minBinCount,
                      int binCountFactor,
                      boolean isAdaptive)
Construct an empty event queue with the specified parameters.

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.

Specified by:
addDebugListener in interface Debuggable
Parameters:
listener - A listener to which to send debug messages.
See Also:
removeDebugListener(DebugListener)

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 DE event in the queue without removing it from the queue.

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

isEmpty

public final boolean isEmpty()
Return true if this event queue is empty.

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

put

public final void put(DEEvent event)
Put an event into the event queue. If the given DE event is not in the event queue, enqueue it into the event queue and notify all threads that are stalled waiting for a DE 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.
See Also:
addDebugListener(DebugListener)

size

public final int size()
Return the size of the event queue.

Specified by:
size in interface DEEventQueue
Returns:
The size of the event queue.

take

public final DEEvent take()
Dequeue the earliest DE event in this event queue.

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

toArray

public final java.lang.Object[] toArray()
Return the events currently in the queue as an array.

Specified by:
toArray in interface DEEventQueue
Returns:
The events currently in the queue.

toString

public java.lang.String toString()
Describe the Contents of the queue as a string.

Overrides:
toString in class java.lang.Object
Returns:
A string with a comma-separated list of events.