Sie sind auf Seite 1von 3

tatic int serviceTime = 7;; private static boolean PoissonService; private int countRejected; private boolean keep_running = true;

// Constructor for the Creator class. // Initial arrival process has a Poisson distribution, and the // process duration has a Poisson distribution, too. A Poisson // distribution is denoted as TRUE. Creator(Queue Q) { FIFO = Q; PoissonArrival = false; PoissonService = false; countRejected = 0; countCreated = 0; } public static gui_aux GUI; // Accesor method to GUI public static void setGUI(gui_aux obj) { GUI = obj; } // Accesor method to modify the arrivalTime public static void setArrivalTime(float newArrivalTime) { if (newArrivalTime < 1.0) newArrivalTime = 1; arrivalTime = newArrivalTime; } // Accesor method to read the arrival process type public boolean getArrType() { return PoissonArrival; } // Accesor method to modify the arrival process type public static void setArrType(boolean type) { PoissonArrival = type; } // Accesor method to read the service time parameter public int getServiceTime() { return serviceTime; } // Accesor method to modify the service time parameter public static void setServiceTime(float newServiceTime) { if (newServiceTime < 1) newServiceTime = 1; if (newServiceTime > 10) newServiceTime = 10; serviceTime = (int) newServiceTime; } // Accesor method to read the process duration distribution public boolean getProcType() { return PoissonService; } // Accesor method to modify the process duration distribution public static void setProcType(boolean type) {

PoissonService = type; } // This method calculates the process's service time. // It can be either a Poisson distribution (TRUE) // or a fixed-interval distribution. // private int ProcessTime() { int temp; if (PoissonService) temp = (int) (Math.log(Math.random())*(-serviceTime)); else temp = serviceTime; if (temp > 10) temp = 10; if (temp < 1) temp = 1; return temp; } // This method calculates arrival times for the processes. // It can be either a Poisson distribution (TRUE) // or a fixed-interval distribution . // private float nextArrival() { float temp; if (PoissonArrival) temp = (float) Math.log(Math.random())*(-arrivalTime); else temp = arrivalTime; if (temp < 1.0) temp = 1; return arrivalTime; } public void create() { if (FIFO.isFull()) { countRejected++; } else { int time = ProcessTime(); String name = new String(""+countCreated); countCreated++; Proc newProcess = new Proc(time, name); // System.out.println("Created process " + name + " with service time " + time); FIFO.enqueue(newProcess); // FIFO.printQueue(); } } public void pause() { keep_running = !keep_running; } public void turnoff() { keep_running = false; }

public void run() { System.out.println("Got to creator's run()"); while(true) if(keep_running) { try { create(); GUI.repaint(10); int temp = (int) (nextArrival()*1000); // System.out.println("Creator sleeping for " + temp); Thread.sleep(temp); } catch (InterruptedException e) {} } else // creator paused try { Thread.sleep(2000); } catch (InterruptedException e) {} } // }

Das könnte Ihnen auch gefallen