home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-02-20 | 1.5 KB | 62 lines |
-
- package examples.priosys;
-
-
- import simula.*;
- import simula.simset.simulation.*;
- import simula.random.* ;
- /**
- * Process wich serves customer
- * @author Andrea Poltronieri
- * @version 1.0 12 Feb 1998
- */
-
- public class Server extends simula.simset.simulation.Process {
-
-
-
- /**
- * @param _sim The active Simulation
- */
-
- public Server (Simulation _sim) {
- super(_sim);
- }
- /**
- * Executes actions for this object. Called by simulation on activate
- * @see simula.simset.simulation.Simulation
- */
-
- public void run() {
- PrioSysSimulation sim = (PrioSysSimulation)this.sim ;
- try {
- Customer cust ;
- // infinite loop
- while (true) {
- this.out() ;
- //System.out.println("Status of queue is " + sim.queue[sim.top].empty());
- while (!(sim.queue[sim.top].empty())) {
- cust = (Customer)(sim.queue[sim.top].first()) ;
- cust.out() ;
- //System.out.println("Beginning service of customer");
- sim.hold(cust.sertime) ;
- sim.activate(cust) ;
- //System.out.println("Finished service of customer");
- }
-
- //System.out.println("Top queue is " + sim.top);
- // the top queue is now empty
- if (sim.top < sim.k) {
- sim.top++ ;
- } else {
- //System.out.println("New server available");
- this.into(sim.available) ;
- sim.passivate() ;
- }
- }
- } catch (Exception e ) {
- System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
- System.exit(1) ;
- }
- }
- }