Package ptolemy.domains.de.kernel
Class DECQEventQueue
- java.lang.Object
-
- 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. SeeDEEventQueue
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$
- Author:
- Lukito Muliadi, Edward A. Lee, Jie Liu, Haiyang Zheng
- Pt.AcceptedRating:
- Green (hyzheng)
- Pt.ProposedRating:
- Green (hyzheng)
-
-
Constructor Summary
Constructors Constructor Description DECQEventQueue()
Construct an empty event queue.DECQEventQueue(int minBinCount, int binCountFactor, boolean isAdaptive)
Construct an empty event queue with the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.boolean
remove(DEEvent event)
Remove an event from the event queue and return true if it was removed, and false if it was not in the 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.
-
-
-
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 interfaceDebuggable
- 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 interfaceDEEventQueue
-
get
public final DEEvent get()
Return the earliest DE event in the queue without removing it from the queue.- Specified by:
get
in interfaceDEEventQueue
- 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 interfaceDEEventQueue
- 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 interfaceDEEventQueue
- Parameters:
event
- The event to enqueue.
-
remove
public final boolean remove(DEEvent event)
Remove an event from the event queue and return true if it was removed, and false if it was not in the queue. This should only be used for pure events (consequences of fireAt()), not for events carrying payloads, because this does not remove the payload from the DEReceiver. The event passed is an argument need not be exactly the same event in the queue. It just has to match the actor, timeStamp, microstep, and depth of the event to be removed.- Specified by:
remove
in interfaceDEEventQueue
- Parameters:
event
- The event to enqueue.- Returns:
- True If a match is found and the entry is removed.
-
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 interfaceDebuggable
- 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 interfaceDEEventQueue
- 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 interfaceDEEventQueue
- 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 interfaceDEEventQueue
- 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 classjava.lang.Object
- Returns:
- A string with a comma-separated list of events.
-
-