-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.java
75 lines (62 loc) · 2.64 KB
/
Application.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package round_robin;
import round_robin.graphics.SimulationGui;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Application {
/** Change this if you want to start with default values. */
private static final boolean START_WITH_INPUT = false;
public static void main(String args[]) {
if (START_WITH_INPUT) {
launchWithInput();
} else {
launch(2048, 500, 225, 250000, 5000);
}
}
static void launch(long memorySize, long maxCpuTime, long avgIoTime, long simulationLength, long avgArrivalInterval) {
Simulator simulator = new Simulator(memorySize, maxCpuTime, avgIoTime, simulationLength, avgArrivalInterval);
SimulationGui gui = new SimulationGui(simulator);
}
/**
* Reads a number from the an input reader.
* @param reader The input reader from which to read a number.
* @return The number that was inputted.
*/
private static long readLong(BufferedReader reader) {
try {
return Long.parseLong(reader.readLine());
} catch (IOException ioe) {
return 100;
} catch (NumberFormatException nfe) {
return 0;
}
}
/**
* Reads relevant parameters from the standard input,
* and starts up the GUI. The GUI will then start the simulation when
* the user clicks the "Start simulation" button.
*/
private static void launchWithInput(){
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please input system parameters: ");
System.out.print("Memory size (KB): ");
long memorySize = readLong(reader);
while(memorySize < 400) {
System.out.println("Memory size must be at least 400 KB. Specify memory size (KB): ");
memorySize = readLong(reader);
}
System.out.print("Maximum uninterrupted cpu time for a process (ms): ");
long maxCpuTime = readLong(reader);
System.out.print("Average I/O operation time (ms): ");
long avgIoTime = readLong(reader);
System.out.print("Simulation length (ms): ");
long simulationLength = readLong(reader);
while(simulationLength < 1) {
System.out.println("Simulation length must be at least 1 ms. Specify simulation length (ms): ");
simulationLength = readLong(reader);
}
System.out.print("Average time between process arrivals (ms): ");
long avgArrivalInterval = readLong(reader);
launch(memorySize, maxCpuTime, avgIoTime, simulationLength, avgArrivalInterval);
}
}