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

  1.  
  2. package examples.computer;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.simulation.*;
  7. import simula.random.* ;
  8. /**
  9.  * Activity wich creates new jobs
  10.  * @author Andrea Poltronieri
  11.  * @version 1.0 12 Feb 1998
  12.  */
  13.  
  14. public class Arrivals extends simula.simset.simulation.Process {
  15.  
  16.  
  17.  
  18. /**
  19. * @param _sim The active Simulation
  20. */
  21.         public Arrivals (Simulation _sim){
  22.           super(_sim);
  23.         }
  24. /**     
  25.   * Executes actions for this object. Called by simulation on activate
  26.   * @see simula.simset.simulation.Simulation
  27. */
  28.  
  29. public void run()  {
  30.     ComputerSimulation sim = (ComputerSimulation) this.sim ;
  31.     Negexp negexp=new Negexp(sim.seed,sim.arr) ;
  32.     Randint randint=new Randint(sim.seed,sim.m1,sim.m2) ;
  33.     //declare local integer for number of items in batch and enter infinite loop
  34.     int number ;
  35.     Job newjob ;
  36.     try {
  37.         while (true) {
  38.             sim.hold(negexp.draw().asReal()) ;
  39.             newjob=new Job(sim,randint.draw().asInteger()) ;
  40.             if (sim.free>=newjob.req) {
  41.                 //Enough pages available -> go into inner queue
  42.                 newjob.into(sim.inner) ;
  43.                 sim.free-=newjob.req ;
  44.             }    
  45.             else
  46.                 newjob.into(sim.outer) ;
  47.             
  48.             if (sim.server.idle())
  49.                 sim.activate(sim.server) ;
  50.         }    
  51.         
  52.     
  53.     } catch (Exception e ) {
  54.         System.err.println ("Arrivals exception caught : " + e ) ;
  55.         System.exit(1) ;
  56.     }    
  57. }
  58. }