/* Class name: Crusher * Description: Truck units come to the "Crusher" to dump their ore. * The original intention was to take a linear ammount of time to unload * trucks, however, due to homework limitations, the time it takes to unload * ore from trucks is set statically. * Absent Function: Trucks with other than 20T and 50T capacity all unload * within a preset ammount of time.... * Class: SEG 2106 */ package hw4_multithreadtrucks; import java.util.*; import pbxlogique.Pbx; /** * * @author Peilos */ public class Crusher extends Thread { private Vector truckList; //Rate at which to load trucks that do not come under the 20T or 50T //categories. private long defaultTonsLoadRate = 10; private long defaultMinTimeRate = 750; private long defaultMaxTimerate = 1250; //Hard coded definition for time to take to load a 20T truck private long iLoadRate1 = 1500; private long iLoadRate1Max = 2500; //Hard coded definition for time to take to load a 50T truck private long iLoadRate2 = 3500; private long iLoadRate2Max = 4500; //Helper variable for time calculations... private TimeCal myTimer = new TimeCal(); //Is true if the instance is, or is still in a runnable state. private boolean bReady; //As *this* crusher crushes ore from trucks, the ammount of ore is added //to the oreCrushed variable. This ammount is outputed on the console //when and if the crusher is normally shut down (by calling the //"shutDownCrusher" procedure. private int oreCrushed=0; /* Give higher priority to trucks assigned to Shovel #1?*/ private boolean bUseHighPriorityScheme = false; private int iHighPrioShovelNumber = 0; private String sCrusherName; private double dIdleTime; //Stats, idle time after first truck arrives. private boolean bFirstTruckArrive; private double dTrucksWaitTime; /* Default Constrtuctor * MOD: bReady, truckList * */ public Crusher() { super(); sCrusherName = ""; bReady = true; truckList = new Vector(); dIdleTime = 0; bFirstTruckArrive = false; dTrucksWaitTime = 0; } public void setCrusherName(String sName) { sCrusherName = sName; } public String getCrusherName() { return sCrusherName; } /* procedure useHighPriority * Description: Assigns a shovel as a "high priority" shovel. All trucks * assigned to that shovel are processed first! :) * IN: doWeUseIt: true: Use high priority system * priorityShovelNumber * MOD: bUseHighPriorityScheme,iHighPrioShovelNumber * */ public void useHighPriority(boolean doWeUseIt, int priorityShovelNumber) { this.bUseHighPriorityScheme = doWeUseIt; this.iHighPrioShovelNumber = priorityShovelNumber; } /* Used by a TRUCK unit to place itself in line. * IN: Truck * MOD: truckList * */ public synchronized void placeTruckInLine(Truck oTruck) { truckList.add(oTruck); } /* procedure loadNextTruck * Description: Unloads and crushes ore comming from trucks. The trucks * should already be in line by teh time this procedure is called. * Trucks can place themselves in line by calling the "placeTruckInLine" * procedure. * OUT: Console * MODIFIED: oreCrushed * */ private synchronized void loadNextTruck() { double timeDelays=0; //Timed delay long tmpMin=0, tmpMax=0; //Used for timerDelays int iHelp;//Just a helper variable. Used to extract data from truckList. int chosenOne = -1; //Used in the priority system. Becomes >=0 if priority is given to a truck Truck currentTruck;//Helper variable to load the truck we are dealing with iHelp = truckList.size(); //Get the size of the vector array //Check to ensure the truckList if (0 == truckList.size()) return; if ((!bUseHighPriorityScheme) || iHelp==1) //Priority {//If the priority system is disabled, take the first truck in line currentTruck = (Truck) truckList.remove(0); }else {//Give higher priority to trucks comming from Shovel