lejos.realtime
Class PriorityScheduler

java.lang.Object
  extended by lejos.realtime.Scheduler
      extended by lejos.realtime.PriorityScheduler
Direct Known Subclasses:
DMScheduler, RMScheduler

public class PriorityScheduler
extends Scheduler

Author:
Team iRboT

Method Summary
 void fireSchedulable(Schedulable schedulable)
          Trigger the execution of a schedulable object (like an AsyncEventHandler).
 int getMaxPriority()
          Gets the maximum priority available for a schedulable object managed by this scheduler.
static int getMaxPriority(Thread thread)
          Gets the maximum priority for the given thread.
 int getMinPriority()
          Gets the minimum priority available for a schedulable object managed by this scheduler.
static int getMinPriority(Thread thread)
          Gets the minimum priority for the given thread.
 int getNormPriority()
          Gets the normal priority available for a schedulable object managed by this scheduler.
static int getNormPriority(Thread thread)
          Gets the "norm" priority for the given thread.
 String getPolicyName()
          Gets the policy name of this.
static PriorityScheduler instance()
          Return a reference to the distinguished instance of PriorityScheduler which is the system's base scheduler.
 boolean isFeasible()
          Queries this scheduler about the feasibility of the set of schedulable objects currently in the feasibility set.
 boolean setIfFeasible(Schedulable schedulable, ReleaseParameters release, MemoryParameters memory)
          This method first performs a feasibility analysis using the proposed parameter objects as replacements for the current parameters of schedulable.
 boolean setIfFeasible(Schedulable schedulable, ReleaseParameters release, MemoryParameters memory, ProcessingGroupParameters group)
          This method first performs a feasibility analysis using the proposed parameter objects as replacements for the current parameters of schedulable.
 boolean setIfFeasible(Schedulable schedulable, SchedulingParameters scheduling, ReleaseParameters release, MemoryParameters memory, ProcessingGroupParameters group)
          This method first performs a feasibility analysis using the proposed parameter objects as replacements for the current parameters of schedulable.
 
Methods inherited from class lejos.realtime.Scheduler
getDefaultScheduler, setDefaultScheduler
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static PriorityScheduler instance()
Return a reference to the distinguished instance of PriorityScheduler which is the system's base scheduler.

Returns:
A reference to the distinguished instance PriorityScheduler.

getMaxPriority

public int getMaxPriority()
Gets the maximum priority available for a schedulable object managed by this scheduler.

Returns:
The value of the maximum priority.

getMaxPriority

public static int getMaxPriority(Thread thread)
Gets the maximum priority for the given thread. If the given thread is a real-time thread that is scheduled by an instance of PriorityScheduler, then the maximum priority for that scheduler is returned. If the given thread is a Java thread then the maximum priority of its thread group is returned. Otherwise an exception is thrown.

Parameters:
thread - - An instance of Thread. If null, the maximum priority of this scheduler is returned.
Returns:
The maximum priority for thread
Throws:
IllegalArgumentException - - Thrown if thread is a real-time thread that is not scheduled by an instance of PriorityScheduler.

getMinPriority

public int getMinPriority()
Gets the minimum priority available for a schedulable object managed by this scheduler.

Returns:
The minimum priority used by this scheduler.

getMinPriority

public static int getMinPriority(Thread thread)
Gets the minimum priority for the given thread. If the given thread is a real-time thread that is scheduled by an instance of PriorityScheduler, then the minimum priority for that scheduler is returned. If the given thread is a Java thread then Thread.MIN_PRIORITY is returned. Otherwise an exception is thrown.

Parameters:
thread - - An instance of Thread. If null, the minimum priority of this scheduler is returned.
Returns:
The minimum priority for thread
Throws:
IllegalArgumentException - - Thrown if thread is a real-time thread that is not scheduled by an instance of PriorityScheduler.

getNormPriority

public int getNormPriority()
Gets the normal priority available for a schedulable object managed by this scheduler.

Returns:
The value of the normal priority.

getNormPriority

public static int getNormPriority(Thread thread)
Gets the "norm" priority for the given thread. If the given thread is a real-time thread that is scheduled by an instance of PriorityScheduler, then the norm priority for that scheduler is returned. If the given thread is a Java thread then Thread.NORM_PRIORITY is returned. Otherwise an exception is thrown.

Parameters:
thread - - An instance of Thread. If null, the norm priority for this scheduler is returned.
Returns:
The norm priority for thread
Throws:
IllegalArgumentException - - Thrown if thread is a real-time thread that is not scheduled by an instance3 of PriorityScheduler.

isFeasible

public boolean isFeasible()
Queries this scheduler about the feasibility of the set of schedulable objects currently in the feasibility set. Implementation Notes: The default feasibility test for the PriorityScheduler considers a set of schedulable objects with bounded resource requirements, to always be feasible. This covers all schedulable objects with release parameters of types PeriodicParameters and SporadicParameters. If any schedulable object within the feasibility set has release parameters of the exact type AperiodicParameters (not a subclass thereof), then the feasibility set is not feasible, as aperiodic release characteristics require unbounded resources. In that case, this method will return false and all methods in the setIfFeasible family of methods will also return false. Consequently, any call to a setIfFeasible method that passes a schedulable object which has release parameters of type AperiodicParameters, or passes proposed release parameters of type AperiodicParameters, will return false. The only time a setIfFeasible method can return true, when there exists in the feasibility set a schedulable object with release parameters of type AperiodicParameters, is when the method will change those release parameters to not be AperiodicParameters. Implementations may provide a feasibility test other than the default test just described. In which case the details of that test should be documented here in place of this description of the default implementation. Specified by: isFeasible in class @see Scheduler

Specified by:
isFeasible in class Scheduler
Returns:
True, if the system is feasible. False, if not.

setIfFeasible

public boolean setIfFeasible(Schedulable schedulable,
                             ReleaseParameters release,
                             MemoryParameters memory)
This method first performs a feasibility analysis using the proposed parameter objects as replacements for the current parameters of schedulable. If the resulting system is feasible, this method replaces the current parameters of schedulable with the proposed ones. This method does not require that the schedulable object be in the feasibility set before it is called. If it is not initially a member of the feasibility set it will be added if the resulting system is feasible. Specified by: setIfFeasible in class @see Scheduler

Specified by:
setIfFeasible in class Scheduler
Parameters:
schedulable - - The schedulable object for which the changes are proposed.
release - - The proposed release parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
memory - - The proposed memory parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
Returns:
True, if the resulting system is feasible and the changes are made. False, if the resulting system is not feasible and no changes are made.
Throws:
IllegalArgumentException - - Thrown if schedulable is null, or schedulable is not associated with this scheduler, or the proposed parameters are not compatible with this scheduler.
IllegalAssignmentError - - Thrown if schedulable cannot hold references to the proposed parameter objects, or the parameter objects cannot hold a reference to schedulable.
java.lang.IllegalThreadStateException - - Thrown if the new release parameters change schedulable from periodic scheduling to some other protocol and schedulable is currently waiting for the next release in RealtimeThread.waitForNextPeriod() or RealtimeThread.waitForNextPeriodInterruptible().

setIfFeasible

public boolean setIfFeasible(Schedulable schedulable,
                             ReleaseParameters release,
                             MemoryParameters memory,
                             ProcessingGroupParameters group)
This method first performs a feasibility analysis using the proposed parameter objects as replacements for the current parameters of schedulable. If the resulting system is feasible, this method replaces the current parameters of schedulable with the proposed ones. This method does not require that the schedulable object be in the feasibility set before it is called. If it is not initially a member of the feasibility set it will be added if the resulting system is feasible. Specified by: setIfFeasible in class @see Scheduler

Specified by:
setIfFeasible in class Scheduler
Parameters:
schedulable - - The schedulable object for which the changes are proposed.
release - - The proposed release parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
memory - - The proposed memory parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
group - - The proposed processing group parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
Returns:
True, if the resulting system is feasible and the changes are made. False, if the resulting system is not feasible and no changes are made.
Throws:
IllegalArgumentException - - Thrown if schedulable is null, or schedulable is not associated with this scheduler, or the proposed parameters are not compatible with this scheduler.
IllegalAssignmentError - - Thrown if schedulable cannot hold references to the proposed parameter objects, or the parameter objects cannot hold a reference to schedulable.
java.lang.IllegalThreadStateException - - Thrown if the new release parameters change schedulable from periodic scheduling to some other protocol and schedulable is currently waiting for the next release in RealtimeThread.waitForNextPeriod() or RealtimeThread.waitForNextPeriodInterruptible().

setIfFeasible

public boolean setIfFeasible(Schedulable schedulable,
                             SchedulingParameters scheduling,
                             ReleaseParameters release,
                             MemoryParameters memory,
                             ProcessingGroupParameters group)
This method first performs a feasibility analysis using the proposed parameter objects as replacements for the current parameters of schedulable. If the resulting system is feasible, this method replaces the current parameters of schedulable with the proposed ones. This method does not require that the schedulable object be in the feasibility set before it is called. If it is not initially a member of the feasibility set it will be added if the resulting system is feasible. Specified by: setIfFeasible in class @see Scheduler

Specified by:
setIfFeasible in class Scheduler
Parameters:
schedulable - - The schedulable object for which the changes are proposed.
scheduling - - The proposed scheduling parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
release - - The proposed release parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
memory - - The proposed memory parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
group - - The proposed processing group parameters. If null, the default value of this scheduler is used (a new object is created if the default value is not null). (See PriorityScheduler.)
Returns:
True, if the resulting system is feasible and the changes are made. False, if the resulting system is not feasible and no changes are made.
Throws:
IllegalArgumentException - - Thrown if schedulable is null, or schedulable is not associated with this scheduler, or the proposed parameters are not compatible with this scheduler.
IllegalAssignmentError - - Thrown if schedulable cannot hold references to the proposed parameter objects, or the parameter objects cannot hold a reference to schedulable.
java.lang.IllegalThreadStateException - - Thrown if the new release parameters change schedulable from periodic scheduling to some other protocol and schedulable is currently waiting for the next release in RealtimeThread.waitForNextPeriod() or RealtimeThread.waitForNextPeriodInterruptible().

fireSchedulable

public void fireSchedulable(Schedulable schedulable)
Trigger the execution of a schedulable object (like an AsyncEventHandler). Specified by: fireSchedulable in class @see Scheduler

Specified by:
fireSchedulable in class Scheduler
Parameters:
schedulable - - The schedulable object to make active. If null, nothing happens.
Throws:
UnsupportedOperationException - - Thrown in all cases by the PriorityScheduler

getPolicyName

public String getPolicyName()
Gets the policy name of this. Specified by: getPolicyName in class @see Scheduler

Specified by:
getPolicyName in class Scheduler
Returns:
The policy name (Fixed Priority) as a string.