home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-02-20 | 1.6 KB | 71 lines |
-
- package examples.prepriosys;
-
-
- 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 {
- /** Customer to serve */
- Customer cust ;
- /** True if restared */
- boolean interrupted ;
- /** Time of starting the service */
- double beganservice ;
-
-
- /**
- * @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() {
- PrePrioSysSimulation sim = (PrePrioSysSimulation)this.sim ;
- try {
-
- while (true) {
- // get busy
- while (!( sim.queue[sim.top].empty() )) {
- cust= (Customer)(sim.queue[sim.top].first()) ;
- this.into(sim.busy[cust.type]) ;
- cust.out() ;
- beganservice=sim.time() ;
- interrupted=false ;
- sim.hold(cust.remservice) ;
- if (!( interrupted ))
- sim.activate(cust) ;
- else {
- if (sim.queue[cust.type].empty())
- cust.into(sim.queue[cust.type]) ;
- else
- cust.precede(sim.queue[cust.type].first()) ;
- cust.remservice-=sim.time()-beganservice ;
- }
- }
- if (sim.top<sim.k)
- sim.top++;
- else {
- this.into(sim.available);
- sim.passivate() ;
- }
- }
-
- } catch (Exception e ) {
- System.err.println ("Exception caught in " + this.toString() + " :\n" + e) ;
- System.exit(1) ;
- }
- }
- }