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

  1.  
  2. package examples.priosys;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.simulation.*;
  7. import simula.random.* ;
  8. /**
  9.  * Process wich serves customer
  10.  * @author Andrea Poltronieri
  11.  * @version 1.0 12 Feb 1998
  12.  */
  13.   
  14. public class Server extends simula.simset.simulation.Process {
  15.  
  16.  
  17.  
  18. /**
  19. * @param _sim The active Simulation
  20. */
  21.  
  22.     public Server (Simulation _sim) {
  23.       super(_sim);
  24.     }
  25. /**     
  26.   * Executes actions for this object. Called by simulation on activate
  27.   * @see simula.simset.simulation.Simulation
  28. */
  29.  
  30.     public void run()  {
  31.         PrioSysSimulation sim = (PrioSysSimulation)this.sim ;
  32.         try {
  33.             Customer cust ;
  34.             // infinite loop 
  35.             while (true) {
  36.                 this.out() ;
  37.                 //System.out.println("Status of queue is " + sim.queue[sim.top].empty());
  38.                 while (!(sim.queue[sim.top].empty())) {
  39.                     cust = (Customer)(sim.queue[sim.top].first()) ;
  40.                     cust.out() ;
  41.                     //System.out.println("Beginning service of customer");
  42.                     sim.hold(cust.sertime) ;
  43.                     sim.activate(cust) ;
  44.                     //System.out.println("Finished service of customer");
  45.                 }    
  46.  
  47.                 //System.out.println("Top queue is " + sim.top);
  48.                 // the top queue is now empty
  49.                 if (sim.top < sim.k) {
  50.                     sim.top++ ;
  51.                 } else {
  52.                     //System.out.println("New server available");
  53.                     this.into(sim.available) ;
  54.                     sim.passivate() ;
  55.                 }    
  56.             }    
  57.         } catch (Exception e ) { 
  58.             System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
  59.             System.exit(1) ;
  60.         }
  61.     }
  62. }