refactored out reentrant code, dont break on bad input (client)

This commit is contained in:
Aidan Hahn 2019-05-17 12:19:51 -07:00
parent cf5a5f122b
commit 2497f848c4
No known key found for this signature in database
GPG key ID: 327711E983899316

View file

@ -153,15 +153,13 @@ public class JobServClient {
switch (input) {
case "pause":
System.out.println("Enter a PID");
pid = reader.nextInt();
pid = getPid();
status = client.makeProcessRequest(pid, PAUSE);
// TODO: parse status return
break;
case "resume":
System.out.println("Enter a PID");
pid = reader.nextInt();
pid = getPid();
status = client.makeProcessRequest(pid, RESUME);
// TODO: parse status return
break;
@ -174,22 +172,19 @@ public class JobServClient {
break;
case "output":
System.out.println("Enter a PID");
pid = reader.nextInt();
pid = getPid();
String out = client.getProcessOutput(pid);
System.out.println(out);
break;
case "status":
System.out.println("Enter a PID");
pid = reader.nextInt();
pid = getPid();
status = client.makeProcessRequest(pid, STATUS);
System.out.println(String.format("Current status of program is: %d", status));
break;
case "return":
System.out.println("Enter a PID");
pid = reader.nextInt();
pid = getPid();
status = client.makeProcessRequest(pid, RETURN);
System.out.println(String.format("Exit code of process is: %d", status));
break;
@ -199,12 +194,13 @@ public class JobServClient {
return;
case "help":
System.out.println("pause: pauses a process on the server");
System.out.println("pause: pauses a process on the server");
System.out.println("resume: resumes a process on the server");
System.out.println("new: starts a new process on the server");
System.out.println("new: starts a new process on the server");
System.out.println("output: garners (new) output from a process on the server");
System.out.println("status: outputs the current status of a program on the server");
System.out.println("return: outputs exit code of a process on the sercer");
System.out.println("return: outputs exit code of a process on the server");
System.out.println("quit: exits this server");
break;
default:
@ -212,5 +208,22 @@ public class JobServClient {
break;
}
}
private static int getPid(Scanner reader) {
System.out.println("Enter a PID");
int pid;
while(true) {
try {
pid = reader.nextInt();
} catch (InputMismatchException e) {
System.out.println("That was not a valid integer");
continue;
}
break;
}
}
}
}