home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / JSL.ZIP / JSL20 / examples / prepriosys / Customer.java < prev    next >
Encoding:
Java Source  |  1998-02-20  |  1.8 KB  |  77 lines

  1.  
  2. package examples.prepriosys;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.simulation.*;
  7. import simula.random.* ;
  8.                                 /**
  9.  * Customer process
  10.  * @author Andrea Poltronieri
  11.  * @version 1.0 12 Feb 1998
  12.  */
  13.  
  14. public class Customer extends simula.simset.simulation.Process {
  15.     /** Priority level */
  16.     int type ;
  17.     /** Time required for service*/
  18.     double sertime ;
  19.     /** Arrival time*/
  20.     double arrtime ;
  21.     /** Remainig service time, used wge preempted*/
  22.     double remservice ;
  23.     /** Server counter */
  24.     int i ;
  25.  
  26.  
  27.  
  28. /**
  29. * @param _sim The active Simulation
  30. * @param type Priority category : 1 is the highes
  31. * @param sertime Time required for service
  32. */
  33.  
  34.     public Customer (Simulation _sim,int type, double sertime){
  35.         super(_sim);
  36.         this.type = type ;
  37.         this.sertime = sertime ;
  38.     }
  39. /**     
  40.   * Executes actions for this object. Called by simulation on activate
  41.   * @see simula.simset.simulation.Simulation
  42. */
  43.  
  44.     public void run() {
  45.         double arrtime ;
  46.         PrePrioSysSimulation sim = (PrePrioSysSimulation)this.sim ;
  47.         try {
  48.             arrtime=sim.time() ;
  49.             remservice=this.sertime ;
  50.             this.into(sim.queue[type]) ;
  51.             if (sim.queue[type].cardinal()==1) {
  52.                 if (type<sim.top)
  53.                     sim.top=type ;
  54.                 if (!(sim.available.empty()))
  55.                     sim.activate((Server)(sim.available.first())) ;
  56.                 else {
  57.                     i=sim.k ;
  58.                     while ((i>type) && (sim.busy[i].empty()))
  59.                         i-- ;
  60.                     if (i>type) {
  61.                         Server tmp=(Server)(sim.busy[i].last()) ;
  62.                         tmp.interrupted=true ;
  63.  
  64.                         sim.reactivate((Server)(sim.busy[i].last())) ;
  65.                     }
  66.                 }
  67.             }            
  68.             sim.passivate()     ;
  69.             sim.sojourn[type]+=sim.time()-arrtime ;
  70.             sim.numthrough[type]++ ;
  71.             
  72.         } catch (Exception e ) { 
  73.             System.err.println("Exception caught in " + this.toString() + " :\n" + e) ;
  74.             System.exit(1) ;
  75.         }
  76.     }
  77. }