import org.javasim.*; import org.javasim.streams.*; import org.javasim.stats.*; import java.io.IOException; public class Machine extends SimulationProcess { public Machine (double low, double high, int offset) { STime = new UniformStream(low,high, offset); operational = true; working = false; J = null; } public void run () { double ActiveStart, ActiveEnd; for (;;) { working = true; while (!MachineShop.JobQ.isEmpty()) { ActiveStart = currentTime(); MachineShop.CheckFreq++; MachineShop.JobsInQueue += MachineShop.JobQ.size(); J = MachineShop.JobQ.remove(); try { hold(ServiceTime()); } catch (SimulationException e){} catch (RestartException e){} ActiveEnd = currentTime(); MachineShop.MachineActiveTime += ActiveEnd - ActiveStart; MachineShop.ProcessedJobs++; J.finished(); } working = false; MachineShop.Util.setValue(MachineShop.MachineActiveTime); MachineShop.Total.setValue(Scheduler.currentTime()-MachineShop.StartSimulationTime); MachineShop.StartSimulationTime=Scheduler.currentTime(); MachineShop.MachineActiveTime = 0; try { cancel(); } catch (RestartException e){} } } public void Broken () { operational = false; } public void Fixed () { operational = true; } public boolean IsOperational () { return operational; } public boolean Processing () { return working; } public double ServiceTime () { try { return STime.getNumber(); } catch (IOException e){ return 0.0; } } private UniformStream STime; private boolean operational; private boolean working; private Job J; };