Class Scheduler

java.lang.Object
  |
  +--Scheduler
Direct Known Subclasses:
DiskScheduler, RRScheduler

public abstract class Scheduler
extends java.lang.Object

A Scheduler schedules jobs seeking service from a Device. The class Scheduler itself is "abstract", meaning that there are no instance of Scheduler, only of its subclasses. This simulation has two Schedulers: DiskScheduler for scheduling the disk and RRScheduler for scheduling the CPU. As part of the assignment, students will write other schedulers for the CPU. The base class takes care of maintaining statistics on queue lengths. The subclasses do all the actual work.

See Also:
DiskScheduler, RRScheduler

Field Summary
protected  int baseQuantum
          A baseline quantum to be used by schedulers that require it.
 
Constructor Summary
Scheduler()
           
 
Method Summary
abstract  boolean add(Job newJob, Job currentJob)
          A new job has just requested service for the device.
 void endBurst(Job job)
          This method is called when a job finishes a burst.
 int getBaseQuantum()
          Retrieve the value of the base quantum
 int getQuantum(Job currentJob)
          Get the value of the quantum for a specific job.
abstract  void printQueue()
          For debugging: print the queue of waiting jobs
 void printStats()
          Print statistics about the history of this queue.
protected  void queueChanged(int amount)
          This method should be called by a subclass whenever the queue length changes.
abstract  Job remove()
          Retrieve (and remove) the next job to be served.
abstract  boolean reschedule(Job j)
          This method is called when there is a clock interrupt.
 void setBaseQuantum(int quantum)
          Method to set the value of the baseQuantum
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseQuantum

protected int baseQuantum
A baseline quantum to be used by schedulers that require it. In simple round-robin implentation, this will be the only quantum value. In more sophisticated schedulers that require multiple quantums, this will just be one of the quantums.
Constructor Detail

Scheduler

public Scheduler()
Method Detail

setBaseQuantum

public void setBaseQuantum(int quantum)
Method to set the value of the baseQuantum
Parameters:
quantum -  

getBaseQuantum

public int getBaseQuantum()
Retrieve the value of the base quantum
Returns:
baseQuantum

getQuantum

public int getQuantum(Job currentJob)
Get the value of the quantum for a specific job. This information may need to be stored in the schedulerInfo object for the class, or as is the case for round robin, you may only need to return the base quantum for the scheduler. By default, return the baseQuantum.
Parameters:
currentJob - the current job on the cpu
Returns:
quantum

add

public abstract boolean add(Job newJob,
                            Job currentJob)
A new job has just requested service for the device. The scheduler should add it to the queue. This method should return true if this arrival warrents preempting the current job using the device. Otherwise, it should return false. Note that the sheduler doesn't actually preempt the current job, it just indicates its opinion whether the job should be preempted. The main simulator loop will stop the job and call this method again to add that job to the queue. It will then call the remove method to select the next job to use the device.
Parameters:
newJob - the job newly awaiting service for the device.
currentJob - the job currently using the device, if any (may be null).
Returns:
true if this scheduler would like to preempt the current job.

remove

public abstract Job remove()
Retrieve (and remove) the next job to be served.
Returns:
the next job (null if there is no such job).

reschedule

public abstract boolean reschedule(Job j)
This method is called when there is a clock interrupt. It should decide whether to preempt the current job. If it returns true, the job will be stopped and added to the queue (by a call to the add method), and then another job will be selected to use the device (by a call to the remove method).
Parameters:
j - the job currently being serviced by the corresponding device.
Returns:
true if the scheduler wants to preempt the current job.

endBurst

public void endBurst(Job job)
This method is called when a job finishes a burst. At this point the job's burstUsed() method returns the total length (in ms) of the burst just completed. The default implementation of this method does nothing. A subclass of Scheduler can override it to perform any bookkeeping necessary for a specific scheduling algorithm.
Parameters:
job - the job that just finished its burst.

printQueue

public abstract void printQueue()
For debugging: print the queue of waiting jobs

queueChanged

protected void queueChanged(int amount)
This method should be called by a subclass whenever the queue length changes.

printStats

public void printStats()
Print statistics about the history of this queue.