@@ -19,7 +19,7 @@ public class Client {
1919 // multiple threads. Here it is used for benchmarking, to store the sum
2020 // of the command completion times for all threads
2121 private static AtomicLong totalTime = new AtomicLong (0 );
22-
22+
2323 // this AtomicLong is used to keep track of the current # of running threads
2424 private static AtomicLong runningThreads = new AtomicLong (0 );
2525
@@ -77,7 +77,8 @@ else while (menuSelection != 8) {
7777 e .printStackTrace ();
7878 }
7979 }
80-
80+ // while runningThreads is not 0, there are still clients waiting for the server
81+ // to send a response, so keep looping (waiting) until they are finished
8182 while (runningThreads .get () != 0 ) {}
8283
8384 System .out .println ("Average response time: " + (totalTime .get () / numProcesses ) + " ms\n " );
@@ -86,22 +87,32 @@ else while (menuSelection != 8) {
8687
8788 }
8889 //----------------------------------------------------------------------------
90+ /**
91+ * Function to prompt the user for a command to run
92+ * @return command number 1-8
93+ */
8994 public static int mainMenu () {
9095 int menuSelection = 0 ;
96+ // loop (and prompt again) until the user's input is an integer between 1 and 8
9197 while ((menuSelection <= 0 ) || (menuSelection > 8 )) {
9298 System .out .println ("The menu provides the following choices to the user: " );
9399 System .out .println ("1. Host current Date and Time \n 2. Host uptime\n "
94100 + "3. Host memory use \n 4. Host Netstat \n 5. Host current users "
95- + "\n 6. Host running processes \n 7. Benchmark\n 8. Quit " );
101+ + "\n 6. Host running processes \n 7. Benchmark (measure mean response time) \n 8. Quit " );
96102 System .out .print ("Please provide number corresponding to the action you want to be performed: " );
97103 Scanner sc = new Scanner (System .in );
98104 if (sc .hasNextInt ()) menuSelection = sc .nextInt ();
99105 }
100106 return menuSelection ;
101107 }
102108
109+ /**
110+ * Function to prompt the user for a benchmark command to run
111+ * @return command number 1-6
112+ */
103113 public static int benchmarkMenu () {
104114 int menuSelection = 0 ;
115+ // loop (and prompt again) until the user's input is an integer between 1 and 6
105116 while ((menuSelection <= 0 ) || (menuSelection > 6 )) {
106117 System .out .println ("Which command would you like to benchmark? " );
107118 System .out .println ("1. Host current Date and Time \n 2. Host uptime\n "
@@ -114,8 +125,13 @@ public static int benchmarkMenu() {
114125 return menuSelection ;
115126 }
116127
128+ /**
129+ * Function to prompt the user for how many connections to make (for measuring the mean response time)
130+ * @return number 1-100
131+ */
117132 public static int numProcessesMenu () {
118133 int menuSelection = 0 ;
134+ // loop (and prompt again) until the user's input is an integer between 1 and 100
119135 while ((menuSelection <= 0 ) || (menuSelection > 100 )) {
120136 System .out .print ("How many connections to the server would you like to open? [1-100]: " );
121137 Scanner sc = new Scanner (System .in );
0 commit comments