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

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