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) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue