ptolemy.domains.tm.kernel
Class TMEvent

java.lang.Object
  extended by 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.

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: TMEvent.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Jie Liu
See Also:
DEEvent
Accepted Rating:
Yellow (janneck)
Proposed Rating:
Yellow (liuj)

Field Summary
private  Actor _actor
           
private  boolean _hasStarted
           
private  int _priority
           
private  double _processingTime
           
private  TMReceiver _receiver
           
private  Token _token
           
 
Constructor Summary
TMEvent(TMReceiver receiver, Token token, int priority, double processingTime)
          Construct an event with the specified destination receiver, token, priority, and executionTime.
 
Method Summary
 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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_receiver

private TMReceiver _receiver

_actor

private Actor _actor

_token

private Token _token

_priority

private int _priority

_hasStarted

private boolean _hasStarted

_processingTime

private double _processingTime
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 interface java.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.

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 class java.lang.Object
Returns:
The token as a string with necessary information.