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

  1.  
  2. package examples.machine;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.simulation.*;
  7. import simula.random.* ;
  8. /**
  9.  * Worker wich fixes broken machines
  10.  * @author Andrea Poltronieri
  11.  * @version 1.0 12 Feb 1998
  12.  */
  13.   
  14. public class RepairMan extends simula.simset.simulation.Process {
  15.  
  16.  
  17.     Negexp negexp ;
  18.  
  19. /**
  20. * @param _sim The active Simulation
  21. */
  22.  
  23.     public RepairMan (Simulation _sim) {
  24.       super(_sim);
  25.       MachineSimulation sim = (MachineSimulation)this.sim ;
  26.       this.negexp=new Negexp(sim.seed,sim.rep) ;
  27.     }
  28. /**     
  29.   * Executes actions for this object. Called by simulation on activate
  30.   * @see simula.simset.simulation.Simulation
  31. */
  32.  
  33.     public void run()  {
  34.         MachineSimulation sim = (MachineSimulation)this.sim ;
  35.         try {
  36.             // declare each local variable and enter infinite loop ;
  37.             Machine mach ;
  38.             
  39.  
  40.             while (true) {
  41.                 this.out() ;
  42.                 while (!(sim.broken.empty())) {
  43.                     mach=(Machine)(sim.broken.first()) ;
  44.                     mach.out() ;
  45.                     sim.hold(this.negexp.draw().asReal()) ;
  46.                     sim.activate(mach) ;
  47.                 }
  48.                 this.into(sim.available) ;
  49.                 sim.passivate() ;
  50.             }
  51.  
  52.         } catch (Exception e ) { 
  53.             System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
  54.             System.exit(1) ;
  55.         }
  56.     }
  57. }