Package ptolemy.domains.tm.kernel
Class TMEvent
- java.lang.Object
-
- ptolemy.domains.tm.kernel.TMEvent
-
- All Implemented Interfaces:
java.lang.Comparable
public class TMEvent extends java.lang.Object implements java.lang.Comparable
A TM event is an event that triggers the execution of a TM actor (task). It has the following information that assists the dispatching and processing of the event.- the destination receiver,
- the destination actor,
- a token,
- the priority, inherited from the destination port or the destination actor. A smaller value represents a higher priority.
- a flag hasStarted indicating whether the processing of this event has been started but has not yet finished (typically due to preemption),
- a processingTime recording the remaining processing time needed to finish the processing of this event. Note that for an event that has been preempted, the processingTime is smalled than the execution time of the destination actor.
A event queue is used to sort these event, based on
- priority, and - whether it has been started
in that order.Notice that an interrupt event (an event generated by calling fireAt() of the director) is not a TM event. They are external events that carries time stamps, implemented using the DEEvent class.
- Since:
- Ptolemy II 2.0
- Version:
- $Id$
- Author:
- Jie Liu
- See Also:
DEEvent
- Pt.AcceptedRating:
- Yellow (janneck)
- Pt.ProposedRating:
- Yellow (liuj)
-
-
Constructor Summary
Constructors Constructor Description TMEvent(TMReceiver receiver, Token token, int priority, double processingTime)
Construct an event with the specified destination receiver, token, priority, and executionTime.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Actor
actor()
Return the destination actor for this event.int
compareTo(java.lang.Object event)
Compare the order of this event with the specified event for order.int
compareTo(TMEvent event)
Compare the tag of this event with the specified event for order.boolean
equals(java.lang.Object tmEvent)
Return true if this TMEvent has the same sequence number as the given TMEvent.int
hashCode()
Return the hash code for this TMEvent object.boolean
hasStarted()
Return true if the processing of this event has started.int
priority()
Return the priority.double
processingTime()
Return the remaining time needed to finish processing this event.TMReceiver
receiver()
Return the destination receiver of this event.void
setPriority(int newPriority)
Set the priority of the event.void
setProcessingTime(double time)
Set the remaining processing time of the event.void
startProcessing()
Start the processing of this event.void
timeProgress(double time)
Reduce the remaining processing time of this event by a certain amount.Token
token()
Return the token contained by this event.java.lang.String
toString()
Return a description of the event, including the contained token (or "null" if there is none), the priority, the destination actor, whether it has been started, and the remaining processing time.
-
-
-
Constructor Detail
-
TMEvent
public TMEvent(TMReceiver receiver, Token token, int priority, double processingTime)
Construct an event with the specified destination receiver, token, priority, and executionTime. Upon creation, the processing of an event has not started. The destination actor is the container's container of the destination receiver.- Parameters:
receiver
- The destination receiver.token
- The transferred token.priority
- The priority of the port that contains the destination receiver.processingTime
- The time needed to finish processing the event.- Throws:
java.lang.NullPointerException
- If the receiver is null or is not contained by a port contained by an actor.
-
-
Method Detail
-
actor
public final Actor actor()
Return the destination actor for this event.- Returns:
- The destination actor.
-
compareTo
public final int compareTo(java.lang.Object event)
Compare the order of this event with the specified event for order. See compareTo(TMEvent event) for the comparison rules. The argument has to be an instance of TMEvent or a ClassCastException will be thrown.- Specified by:
compareTo
in interfacejava.lang.Comparable
- Parameters:
event
- The event to compare against.- Returns:
- -1, 0, or 1, depends on the order of the events.
- Throws:
java.lang.ClassCastException
- If the argument is not an instance of TMEvent.
-
compareTo
public final int compareTo(TMEvent event)
Compare the tag of this event with the specified event for order. Return -1, zero, or +1 if this event is less than, equal to, or greater than the specified event. The priority is checked first. Return 1 if the priority of this event is strictly higher than that of the argument, (i.e. the priority is smaller in value). Return -1 if the priority of this event is strictly lower than the argument. If the two priorities are identical, then the hasStarted field is checked. return 1 if hasStarted of this event is true. Return -1 if this event has not started, but the argument has. Return 0 otherwise, i.e. they have the same priority and none of them has started. Notice that it is impossible that two events with the same priority have both started.- Parameters:
event
- The event to compare against.- Returns:
- -1, 0, or 1, depends on the order of the events.
-
equals
public boolean equals(java.lang.Object tmEvent)
Return true if this TMEvent has the same sequence number as the given TMEvent.- Overrides:
equals
in classjava.lang.Object
- Parameters:
tmEvent
- The TMEvent object that this TMEvent object is compared to.- Returns:
- True if the two TMEvent objects have the same sequence number, name and workspace
-
hashCode
public int hashCode()
Return the hash code for this TMEvent object. If two TMEvent objects contain the receiver, token, name and workspace, then they will have the same hashCode.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- The hash code for this TimedEvent object.
-
hasStarted
public final boolean hasStarted()
Return true if the processing of this event has started.- Returns:
- True if the processing of this event has started.
-
priority
public final int priority()
Return the priority.- Returns:
- The priority.
-
processingTime
public final double processingTime()
Return the remaining time needed to finish processing this event.- Returns:
- The time needed to finish processing this event.
-
receiver
public final TMReceiver receiver()
Return the destination receiver of this event.- Returns:
- The destination receiver.
-
setPriority
public final void setPriority(int newPriority)
Set the priority of the event. This method may be used for dynamic priority assignment scheduling strategies.- Parameters:
newPriority
- The priority set to the event.
-
setProcessingTime
public final void setProcessingTime(double time)
Set the remaining processing time of the event. This method is typically used by TMDirector to keep tack of the remaining processing time when time is advance. Notice that this method does not insist that the time to be set is smaller than the original processing time. The caller should perform the comparison if that is the desired behavior.- Parameters:
time
- The remaining processing time.
-
startProcessing
public final void startProcessing()
Start the processing of this event.
-
timeProgress
public final void timeProgress(double time)
Reduce the remaining processing time of this event by a certain amount. This is a syntactic sugar for setProcessingTime().- Parameters:
time
- The amount of time progressed.
-
token
public final Token token()
Return the token contained by this event.- Returns:
- The token in this event.
-
toString
public final java.lang.String toString()
Return a description of the event, including the contained token (or "null" if there is none), the priority, the destination actor, whether it has been started, and the remaining processing time.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The token as a string with necessary information.
-
-