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

  1.  
  2. package examples.priosys;
  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.     
  20.  
  21.  
  22. /**
  23. * @param _sim The active Simulation
  24. * @param type Priority category : 1 is the highes
  25. * @param sertime Time required for service
  26. */
  27.     public Customer (Simulation _sim,int type, double sertime){
  28.         super(_sim);
  29.         this.type = type ;
  30.         this.sertime = sertime ;
  31.     }
  32. /**     
  33.   * Executes actions for this object. Called by simulation on activate
  34.   * @see simula.simset.simulation.Simulation
  35. */
  36.  
  37.     public void run() {
  38.         double arrtime ;
  39.         PrioSysSimulation sim = (PrioSysSimulation)this.sim ;
  40.         try {
  41.             arrtime = sim.time() ;
  42.             //System.out.println("Queuing");
  43.             this.into(sim.queue[this.type]) ;
  44.             if (type < sim.top)
  45.                 sim.top = type ;
  46.             if (!(sim.available.empty()))
  47.                 sim.activate((simula.simset.simulation.Process)(sim.available.first())) ;
  48.             sim.passivate() ;
  49.             sim.sojourn[type] += sim.time()-arrtime ;
  50.             sim.numthrough[type]++ ;
  51.             //System.out.println("Customer said bye");
  52.             sim.passivate();
  53.         } catch (Exception e ) { 
  54.             System.err.println("Exception caught in " + this.toString() + " :\n" + e) ;
  55.             System.exit(1) ;
  56.         }
  57.     }
  58. }