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

  1.  
  2. package examples.network;
  3.  
  4.  
  5. import simula.*;
  6. import simula.simset.* ;
  7. import simula.simset.simulation.*;
  8. import simula.random.* ;
  9.  
  10. /**
  11.  * A universal service process
  12.  * @author Andrea Poltronieri
  13.  * @version 1.0 12 Feb 1998
  14.  */
  15.  
  16. public class  Server extends simula.simset.simulation.Process {
  17.    /** Node to wich access */
  18.     Station s ;
  19.  
  20.  
  21.  
  22. /**
  23. * @param _sim The active Simulation
  24. * @param s Station in wich run and from wich access attributes 
  25. */
  26.  
  27.     public  Server (Simulation _sim, Station s) {
  28.       super(_sim);
  29.         this.s=s ;
  30.     }
  31. /**     
  32.   * Executes actions for this object. Called by simulation on activate
  33.   * @see simula.simset.simulation.Simulation
  34. */
  35.  
  36.     public void run()  {
  37.         NetworkSimulation sim = (NetworkSimulation)this.sim ;
  38.         try {
  39.             // initialize random generator
  40.             Negexp negexp = new Negexp(sim.seed,s.ser) ;
  41.             Job j ;
  42.             while (true) {
  43.                 while (!(s.queue.empty())) {
  44.                     j=(Job)(s.queue.first()) ;
  45.                     sim.hold(negexp.draw().asReal()) ;
  46.                     j.move(sim.n,s.q) ;
  47.                 }
  48.                 sim.passivate() ;
  49.             }
  50.         } catch (Exception e ) { 
  51.             System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
  52.             System.exit(1) ;
  53.         }
  54.     }
  55. }