/*****************************************************************
                        CPU Scheduler
PURPOSE: This is the abstract base class for CPU scheduling. It uses the 
constructs of animation view to display trace simulation, statistics 
view  to display empirical data about the simulation, and input view to 
generate input for the algorithm.
*****************************************************************/
import java.util.Vector;

abstract public class Scheduler extends Object {
   Vector readyQ, finishQ, Q;
   int clock;
   process P, T;
   boolean idle;
   public Thread thread;

   statsFrame st;
   animeFrame an;
   inputFrame in;

   /*--------------------------------------------------------
                        Constructor
   PURPOSE:  To ask help from views, set up data, and begin simulation
   PARAMTERS: references the input queue, stats and anime view. gets
   value of starting clock time.
   --------------------------------------------------------*/
   public Scheduler(Vector q, statsFrame s, animeFrame a, inputFrame i, int c) {
      Q = q;
      st = s;
      an = a;
      in = i;
      clock = c-1; // stagger for run loop
      idle = true;
      readyQ = new Vector(1,1);
      finishQ = new Vector(1,1);      
   } // constructor

   /*--------------------------------------------------------
                        Process Ready
   PURPOSE:  To determine if a process is ready
   PARAMTERS: gets the value of current clock time, returns ready process if any
   --------------------------------------------------------*/
   public process processready(int tick) {
      for (int j=0; j<Q.size(); j++)
         if (((process)(Q.elementAt(j))).getArrival() <= tick)
            return (process)Q.elementAt(j);
      return null;
   } // clock

   /*--------------------------------------------------------
                        Reset Queues
   PURPOSE:  To reset all data structures for scheduling algorithms
   --------------------------------------------------------*/
   public void resetQ() {
      readyQ.setSize(0);
      finishQ.setSize(0);
      Q.setSize(0);
      in.resetGUI();
   } // reset all queues

} // Scheduler class
