javax.realtime
Class RealtimeThread

java.lang.Object
  extended byjava.lang.Thread
      extended byjavax.realtime.RealtimeThread
All Implemented Interfaces:
java.lang.Runnable, Schedulable
Direct Known Subclasses:
ActivationLatency, BridgeReporter, Car, Car, CarArrivals, ChangeFlaps, ChangeLandingGear, CycleBurner, Job, NoHeapRealtimeThread, OneShotTimerThread, PeriodicTimerThread, Pilot, Terminator, TestAltitude

public abstract class RealtimeThread
extends java.lang.Thread
implements Schedulable

RealtimeThread extends java.lang.Thread and includes classes and methods to get and set parameter objects, manage the execution of those threads with a ReleaseParameters type of PeriodicParameters, and waiting.

A RealtimeThread object must be placed in a memory area such that thread logic may unexceptionally access instance variables and such that Java methods on java.lang.Thread (e.g., enumerate and join) complete normally except where such execution may cause access violations.

Parameters for constructors may be null. In such cases the default value will be the default value set for the particular type by the associated instance of Scheduler.

Author:
gary

Field Summary
 boolean activePhaseToDo
          True iff this RealtimeThread is executing an active phase, i.e., is the coroutine currently under execution in this DSS.
 EventNotice currentEventNotice
          Points to the unique EventNotice for this RealtimeThread.
 int currentPriority
          The current priority of this RealtimeThread, which may temporarily be greater than its base priority, due to priority inheritance.
static int defaultPriority
           
protected  AbsoluteTime endTime
           
protected  double lastPriorityChangeNanos
           
protected  AbsoluteTime lastWaitStart
           
protected  java.lang.Runnable logic
          Not passed to superclass because we need to maintain two run() functions: the one in this RealtimeThread, and the one provided by constructor argument
protected  MemoryArea memoryArea
          This RealtimeThread's MemoryArea.
protected  MemoryParameters memoryParameters
          This RealtimeThread's MemoryParameters.
protected  ProcessingGroupParameters processingGroup
          This RealtimeThread's ProcessingGroupParameters.
protected  ReleaseParameters releaseParameters
          This RealtimeThread's ReleaseParameters.
 java.util.Set resourcesHeld
          The set of resources currently held by this RealtimeThread.
protected  Scheduler scheduler
          This RealtimeThread's Scheduler.
protected  SchedulingParameters scheduling
          This RealtimeThread's Scheduler.
protected  long startAbsoluteMillis
          The milliseconds of this RealtimeThread's start cost.
 boolean started
          True iff this RealtimeThread has started, i.e., begun its run() routine.
protected  AbsoluteTime startTime
          The time at which this RealtimeThread started running.
 boolean terminated
           
protected  double timeWeightedPriority
           
 Resource waitingForResource
          The resource, if any, that this RealtimeThread is currently waiting for.
protected  RelativeTime waitTime
          Accumulates time this RealtimeThread has spent waiting for a Resource.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected RealtimeThread()
          Default constructor
  RealtimeThread(SchedulingParameters scheduling)
          Constructor
  RealtimeThread(SchedulingParameters scheduling, ReleaseParameters releaseParameters)
          Constructor
  RealtimeThread(SchedulingParameters scheduling, ReleaseParameters releaseParameters, MemoryParameters memoryParameters, MemoryArea memoryArea, ProcessingGroupParameters processingGroup, java.lang.Runnable logic)
          Constructor
protected RealtimeThread(java.lang.String name)
           
  RealtimeThread(java.lang.String name, SchedulingParameters scheduling)
          Constructor
  RealtimeThread(java.lang.String name, SchedulingParameters scheduling, ReleaseParameters releaseParameters)
          Constructor
  RealtimeThread(java.lang.String name, SchedulingParameters scheduling, ReleaseParameters releaseParameters, MemoryParameters memoryParameters, MemoryArea memoryArea, ProcessingGroupParameters processingGroup, java.lang.Runnable logic)
          Constructor
 
Method Summary
 boolean addToFeasibility()
          Add this thread to the current scheduler's feasibility set
 void addToWaitTime(RelativeTime time)
           
 double averagePriority()
           
abstract  void body()
          Where all the application work gets done.
 int dynamicPriority()
          Compute dynamic priority of this .
 void exit()
          Exit a run method.
 int getBasePriority()
           
 AbsoluteTime getLastWaitStart()
           
 MemoryParameters getMemoryParameters()
          Set this thread's memory parameters
 ProcessingGroupParameters getProcessingGroupParameters()
          Get this thread's processing group parameters
 ReleaseParameters getReleaseParameters()
          Get this thread's release parameters
 Scheduler getScheduler()
          Get this thread's scheduler
 SchedulingParameters getSchedulingParameters()
          Get this thread's scheduling parameters
 void initialize()
          Start this thread, and wait until it has actually started.
 boolean isActive()
          Tests whether this RealtimeThread is running or scheduled to run later.
 void notifyPriorityChange(int oldPriority, int newPriority)
           
static void printAllStatistics()
           
 void printResourcesHeld()
           
 void printStatistics()
           
 void printTimes()
           
 boolean removeFromFeasibility()
          Remove this thread from its scheduler's feasibility set
 void run()
          The run() method of this thread.
 void setLastWaitStart()
           
 void setMemoryParameters(MemoryParameters memoryParameters)
          Set this thread's memory parameters
 boolean setMemoryParametersIfFeasible(MemoryParameters memoryParameters)
          Set this thread's memory parameters if it would still be feasible given that change
 void setProcessingGroupParameters(ProcessingGroupParameters processingGroup)
          Set this thread's processing group parameters
 boolean setProcessingGroupParametersIfFeasible(ProcessingGroupParameters groupParameters)
          Set this thread's processing group parameters if it would still be feasible given that change
 void setReleaseParameters(ReleaseParameters releaseParameters)
          Set this thread's release parameters
 boolean setReleaseParametersIfFeasible(ReleaseParameters releaseParameters)
          Set this thread's release parameters if it would still be feasible given that change
 void setScheduler(Scheduler scheduler)
          Set this thread's scheduler
 void setScheduler(Scheduler scheduler, SchedulingParameters scheduling, ReleaseParameters releaseParameters, MemoryParameters memoryParameters, ProcessingGroupParameters processingGroup)
          Set all the following parameters of this thread:
 void setSchedulingParameters(SchedulingParameters scheduling)
          Set this RealtimeThread's scheduling parameters
 boolean setSchedulingParametersIfFeasible(SchedulingParameters scheduling)
          Set this thread's scheduling parameters if it would still be feasible given that change
 java.lang.String toString()
          Construct a string representation of this thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentPriority

public int currentPriority
The current priority of this RealtimeThread, which may temporarily be greater than its base priority, due to priority inheritance.


resourcesHeld

public java.util.Set resourcesHeld
The set of resources currently held by this RealtimeThread. Used in priority inheritance calculation.


waitingForResource

public Resource waitingForResource
The resource, if any, that this RealtimeThread is currently waiting for.


started

public boolean started
True iff this RealtimeThread has started, i.e., begun its run() routine.


terminated

public boolean terminated

activePhaseToDo

public boolean activePhaseToDo
True iff this RealtimeThread is executing an active phase, i.e., is the coroutine currently under execution in this DSS.


currentEventNotice

public EventNotice currentEventNotice
Points to the unique EventNotice for this RealtimeThread. Must be null if this RealtimeThread is unscheduled, i.e., passivated or terminated.


scheduler

protected Scheduler scheduler
This RealtimeThread's Scheduler.


scheduling

protected SchedulingParameters scheduling
This RealtimeThread's Scheduler.


releaseParameters

protected ReleaseParameters releaseParameters
This RealtimeThread's ReleaseParameters.


memoryParameters

protected MemoryParameters memoryParameters
This RealtimeThread's MemoryParameters.


memoryArea

protected MemoryArea memoryArea
This RealtimeThread's MemoryArea.


processingGroup

protected ProcessingGroupParameters processingGroup
This RealtimeThread's ProcessingGroupParameters.


defaultPriority

public static final int defaultPriority
See Also:
Constant Field Values

startTime

protected AbsoluteTime startTime
The time at which this RealtimeThread started running.


endTime

protected AbsoluteTime endTime

startAbsoluteMillis

protected long startAbsoluteMillis
The milliseconds of this RealtimeThread's start cost.


waitTime

protected RelativeTime waitTime
Accumulates time this RealtimeThread has spent waiting for a Resource.


lastPriorityChangeNanos

protected double lastPriorityChangeNanos

timeWeightedPriority

protected double timeWeightedPriority

lastWaitStart

protected AbsoluteTime lastWaitStart

logic

protected java.lang.Runnable logic
Not passed to superclass because we need to maintain two run() functions: the one in this RealtimeThread, and the one provided by constructor argument

Constructor Detail

RealtimeThread

protected RealtimeThread()
Default constructor


RealtimeThread

protected RealtimeThread(java.lang.String name)

RealtimeThread

public RealtimeThread(SchedulingParameters scheduling)
Constructor

Parameters:
scheduling - the SchedulingParameters for this object

RealtimeThread

public RealtimeThread(SchedulingParameters scheduling,
                      ReleaseParameters releaseParameters)
Constructor

Parameters:
scheduling - the SchedulingParameters for this object
releaseParameters - the ReleaseParameters for this object

RealtimeThread

public RealtimeThread(SchedulingParameters scheduling,
                      ReleaseParameters releaseParameters,
                      MemoryParameters memoryParameters,
                      MemoryArea memoryArea,
                      ProcessingGroupParameters processingGroup,
                      java.lang.Runnable logic)
Constructor

Parameters:
scheduling - the SchedulingParameters for this object
releaseParameters - the ReleaseParameters for this object
memoryParameters - the MemoryParameters for this object
memoryArea - the MemoryArea for this object
processingGroup - the ProcessingGroupParameters for this object
logic - the Runnable code for this object

RealtimeThread

public RealtimeThread(java.lang.String name,
                      SchedulingParameters scheduling)
Constructor

Parameters:
name - the String name of this object
scheduling - the SchedulingParameters for this object

RealtimeThread

public RealtimeThread(java.lang.String name,
                      SchedulingParameters scheduling,
                      ReleaseParameters releaseParameters)
Constructor

Parameters:
name - the String name of this object
scheduling - the SchedulingParameters for this object
releaseParameters - the ReleaseParameters for this object

RealtimeThread

public RealtimeThread(java.lang.String name,
                      SchedulingParameters scheduling,
                      ReleaseParameters releaseParameters,
                      MemoryParameters memoryParameters,
                      MemoryArea memoryArea,
                      ProcessingGroupParameters processingGroup,
                      java.lang.Runnable logic)
Constructor

Parameters:
name - the String name of this object
scheduling - the SchedulingParameters for this object
releaseParameters - the ReleaseParameters for this object
memoryParameters - the MemoryParameters for this object
memoryArea - the MemoryArea for this object
processingGroup - the ProcessingGroupParameters for this object
logic - the Runnable code for this object
Method Detail

body

public abstract void body()
                   throws java.lang.InterruptedException,
                          ThreadTerminatedException
Where all the application work gets done. Analogous to Thread.run(), but that method is used as a wrapper RealtimeThread to initialize, passivate and clean up this RealtimeThread. Must be overridden in subclass.

Throws:
java.lang.InterruptedException - thrown if a wait() is interrupted
ThreadTerminatedException - thrown if a simulation shutdown occurs while this thread has not yet terminated


run

public void run()
The run() method of this thread.

Specified by:
run in interface java.lang.Runnable

dynamicPriority

public int dynamicPriority()
Compute dynamic priority of this . All resources held must be examined, since they can induce temporary priority elevation, in the cases of priority inheritance and priority ceiling.

Returns:
the dynamic priority

initialize

public void initialize()
Start this thread, and wait until it has actually started.


toString

public java.lang.String toString()
Construct a string representation of this thread.

Returns:
the string representation

exit

public void exit()
Exit a run method.


addToFeasibility

public boolean addToFeasibility()
Add this thread to the current scheduler's feasibility set

Specified by:
addToFeasibility in interface Schedulable
Returns:
true if the resulting system is feasible

Not currently implemented


getMemoryParameters

public MemoryParameters getMemoryParameters()
Set this thread's memory parameters

Specified by:
getMemoryParameters in interface Schedulable
Returns:
the MemoryParameters of this object.

getProcessingGroupParameters

public ProcessingGroupParameters getProcessingGroupParameters()
Get this thread's processing group parameters

Specified by:
getProcessingGroupParameters in interface Schedulable
Returns:
the ProcessingGroupParameters of this object.

getReleaseParameters

public ReleaseParameters getReleaseParameters()
Get this thread's release parameters

Specified by:
getReleaseParameters in interface Schedulable
Returns:
the ReleaseParameters of this object.

getScheduler

public Scheduler getScheduler()
Get this thread's scheduler

Specified by:
getScheduler in interface Schedulable
Returns:
the current scheduler

getSchedulingParameters

public SchedulingParameters getSchedulingParameters()
Get this thread's scheduling parameters

Specified by:
getSchedulingParameters in interface Schedulable
Returns:
the current scheduling parameters

getBasePriority

public int getBasePriority()

removeFromFeasibility

public boolean removeFromFeasibility()
Remove this thread from its scheduler's feasibility set

Specified by:
removeFromFeasibility in interface Schedulable
Returns:
true if the resulting system is feasible

Not currently implemented


setMemoryParameters

public void setMemoryParameters(MemoryParameters memoryParameters)
Set this thread's memory parameters

Specified by:
setMemoryParameters in interface Schedulable
Parameters:
memoryParameters -

setMemoryParametersIfFeasible

public boolean setMemoryParametersIfFeasible(MemoryParameters memoryParameters)
Set this thread's memory parameters if it would still be feasible given that change

Specified by:
setMemoryParametersIfFeasible in interface Schedulable
Parameters:
memoryParameters -

Not currently implemented

Returns:
true if the resulting system is feasible.

setProcessingGroupParameters

public void setProcessingGroupParameters(ProcessingGroupParameters processingGroup)
Set this thread's processing group parameters

Specified by:
setProcessingGroupParameters in interface Schedulable
Parameters:
processingGroup -

setProcessingGroupParametersIfFeasible

public boolean setProcessingGroupParametersIfFeasible(ProcessingGroupParameters groupParameters)
Set this thread's processing group parameters if it would still be feasible given that change

Specified by:
setProcessingGroupParametersIfFeasible in interface Schedulable
Parameters:
groupParameters -
Returns:
true if the resulting system is feasible

Not currently implemented


setReleaseParameters

public void setReleaseParameters(ReleaseParameters releaseParameters)
Set this thread's release parameters

Specified by:
setReleaseParameters in interface Schedulable
Parameters:
releaseParameters -

setReleaseParametersIfFeasible

public boolean setReleaseParametersIfFeasible(ReleaseParameters releaseParameters)
Set this thread's release parameters if it would still be feasible given that change

Specified by:
setReleaseParametersIfFeasible in interface Schedulable
Parameters:
releaseParameters -
Returns:
true if the resulting system is feasible

Not currently implemented


setScheduler

public void setScheduler(Scheduler scheduler)
                  throws java.lang.IllegalThreadStateException
Set this thread's scheduler

Specified by:
setScheduler in interface Schedulable
Parameters:
scheduler -
Throws:
java.lang.IllegalStateException
java.lang.IllegalThreadStateException

setScheduler

public void setScheduler(Scheduler scheduler,
                         SchedulingParameters scheduling,
                         ReleaseParameters releaseParameters,
                         MemoryParameters memoryParameters,
                         ProcessingGroupParameters processingGroup)
                  throws java.lang.IllegalThreadStateException
Set all the following parameters of this thread:

Specified by:
setScheduler in interface Schedulable
Parameters:
scheduler -
scheduling -
releaseParameters -
memoryParameters -
processingGroup -
Throws:
IllegalThreadstateException
java.lang.IllegalThreadStateException

setSchedulingParameters

public void setSchedulingParameters(SchedulingParameters scheduling)
Set this RealtimeThread's scheduling parameters

Specified by:
setSchedulingParameters in interface Schedulable
Parameters:
scheduling - The new scheduling parameters

setSchedulingParametersIfFeasible

public boolean setSchedulingParametersIfFeasible(SchedulingParameters scheduling)
Set this thread's scheduling parameters if it would still be feasible given that change

Specified by:
setSchedulingParametersIfFeasible in interface Schedulable
Parameters:
scheduling -
Returns:
true if the resulting system is feasible

Not currently implemented


isActive

public boolean isActive()
Tests whether this RealtimeThread is running or scheduled to run later.

Returns:
true iff this RealtimeThread is active

printResourcesHeld

public void printResourcesHeld()

printAllStatistics

public static void printAllStatistics()

notifyPriorityChange

public void notifyPriorityChange(int oldPriority,
                                 int newPriority)

averagePriority

public double averagePriority()

printStatistics

public void printStatistics()

getLastWaitStart

public AbsoluteTime getLastWaitStart()

printTimes

public void printTimes()

setLastWaitStart

public void setLastWaitStart()

addToWaitTime

public void addToWaitTime(RelativeTime time)