home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-02-20 | 1.8 KB | 77 lines |
-
- package examples.prepriosys;
-
-
- import simula.*;
- import simula.simset.simulation.*;
- import simula.random.* ;
- /**
- * Customer process
- * @author Andrea Poltronieri
- * @version 1.0 12 Feb 1998
- */
-
- public class Customer extends simula.simset.simulation.Process {
- /** Priority level */
- int type ;
- /** Time required for service*/
- double sertime ;
- /** Arrival time*/
- double arrtime ;
- /** Remainig service time, used wge preempted*/
- double remservice ;
- /** Server counter */
- int i ;
-
-
-
- /**
- * @param _sim The active Simulation
- * @param type Priority category : 1 is the highes
- * @param sertime Time required for service
- */
-
- public Customer (Simulation _sim,int type, double sertime){
- super(_sim);
- this.type = type ;
- this.sertime = sertime ;
- }
- /**
- * Executes actions for this object. Called by simulation on activate
- * @see simula.simset.simulation.Simulation
- */
-
- public void run() {
- double arrtime ;
- PrePrioSysSimulation sim = (PrePrioSysSimulation)this.sim ;
- try {
- arrtime=sim.time() ;
- remservice=this.sertime ;
- this.into(sim.queue[type]) ;
- if (sim.queue[type].cardinal()==1) {
- if (type<sim.top)
- sim.top=type ;
- if (!(sim.available.empty()))
- sim.activate((Server)(sim.available.first())) ;
- else {
- i=sim.k ;
- while ((i>type) && (sim.busy[i].empty()))
- i-- ;
- if (i>type) {
- Server tmp=(Server)(sim.busy[i].last()) ;
- tmp.interrupted=true ;
-
- sim.reactivate((Server)(sim.busy[i].last())) ;
- }
- }
- }
- sim.passivate() ;
- sim.sojourn[type]+=sim.time()-arrtime ;
- sim.numthrough[type]++ ;
-
- } catch (Exception e ) {
- System.err.println("Exception caught in " + this.toString() + " :\n" + e) ;
- System.exit(1) ;
- }
- }
- }