refactored out reentrant code, dont break on bad input (client)
This commit is contained in:
parent
cf5a5f122b
commit
2497f848c4
1 changed files with 26 additions and 13 deletions
|
|
@ -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;
|
||||
|
|
@ -204,7 +199,8 @@ public class JobServClient {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue