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) { switch (input) {
case "pause": case "pause":
System.out.println("Enter a PID"); pid = getPid();
pid = reader.nextInt();
status = client.makeProcessRequest(pid, PAUSE); status = client.makeProcessRequest(pid, PAUSE);
// TODO: parse status return // TODO: parse status return
break; break;
case "resume": case "resume":
System.out.println("Enter a PID"); pid = getPid();
pid = reader.nextInt();
status = client.makeProcessRequest(pid, RESUME); status = client.makeProcessRequest(pid, RESUME);
// TODO: parse status return // TODO: parse status return
break; break;
@ -174,22 +172,19 @@ public class JobServClient {
break; break;
case "output": case "output":
System.out.println("Enter a PID"); pid = getPid();
pid = reader.nextInt();
String out = client.getProcessOutput(pid); String out = client.getProcessOutput(pid);
System.out.println(out); System.out.println(out);
break; break;
case "status": case "status":
System.out.println("Enter a PID"); pid = getPid();
pid = reader.nextInt();
status = client.makeProcessRequest(pid, STATUS); status = client.makeProcessRequest(pid, STATUS);
System.out.println(String.format("Current status of program is: %d", status)); System.out.println(String.format("Current status of program is: %d", status));
break; break;
case "return": case "return":
System.out.println("Enter a PID"); pid = getPid();
pid = reader.nextInt();
status = client.makeProcessRequest(pid, RETURN); status = client.makeProcessRequest(pid, RETURN);
System.out.println(String.format("Exit code of process is: %d", status)); System.out.println(String.format("Exit code of process is: %d", status));
break; break;
@ -199,12 +194,13 @@ public class JobServClient {
return; return;
case "help": 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("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("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("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; break;
default: default:
@ -212,5 +208,22 @@ public class JobServClient {
break; 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;
}
}
} }
} }