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

  1.  
  2. package examples.prepriosys;
  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.     /** Customer to serve */
  16.     Customer cust ;
  17.     /** True if restared */
  18.     boolean interrupted ;
  19.     /** Time of starting the service */
  20.     double beganservice ;
  21.  
  22.  
  23. /**
  24. * @param _sim The active Simulation
  25. */
  26.  
  27.     public Server (Simulation _sim) {
  28.       super(_sim);
  29.     }
  30. /**     
  31.   * Executes actions for this object. Called by simulation on activate
  32.   * @see simula.simset.simulation.Simulation
  33. */
  34.  
  35.     public void run()  {
  36.         PrePrioSysSimulation sim = (PrePrioSysSimulation)this.sim ;
  37.         try {
  38.             
  39.             while (true) {
  40.                 // get busy
  41.                 while (!( sim.queue[sim.top].empty() )) {
  42.                     cust= (Customer)(sim.queue[sim.top].first()) ;
  43.                     this.into(sim.busy[cust.type]) ;
  44.                     cust.out() ;
  45.                     beganservice=sim.time() ;
  46.                     interrupted=false ;
  47.                     sim.hold(cust.remservice) ;
  48.                     if (!( interrupted ))
  49.                         sim.activate(cust) ;
  50.                     else {
  51.                         if (sim.queue[cust.type].empty())
  52.                             cust.into(sim.queue[cust.type]) ;
  53.                         else
  54.                             cust.precede(sim.queue[cust.type].first()) ;
  55.                         cust.remservice-=sim.time()-beganservice ;
  56.                     }    
  57.                 }        
  58.                 if (sim.top<sim.k)
  59.                     sim.top++;
  60.                 else {
  61.                     this.into(sim.available);
  62.                     sim.passivate() ;
  63.                 }
  64.             }        
  65.                         
  66.         } catch (Exception e ) { 
  67.             System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
  68.             System.exit(1) ;
  69.         }
  70.     }
  71. }