refactored out re-entrant code in client
This commit is contained in:
parent
75c3dcda61
commit
5724953e9d
2 changed files with 41 additions and 51 deletions
|
|
@ -220,15 +220,16 @@ public class JobServClient {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// start client
|
|
||||||
// fails if port is improperly formatted or if an ssl exception occurs
|
|
||||||
JobServClient client;
|
JobServClient client;
|
||||||
try {
|
try {
|
||||||
client = new JobServClient(args[3], Integer.parseInt(args[4]), args[2], args[1], args[0]);
|
client = new JobServClient(args[3], Integer.parseInt(args[4]), args[2], args[1], args[0]);
|
||||||
|
|
||||||
|
// Likely bad port
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
System.out.println("Invalid Port");
|
System.out.println("Invalid Port");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// bad cert or key format
|
||||||
} catch (SSLException e) {
|
} catch (SSLException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
return;
|
return;
|
||||||
|
|
@ -254,71 +255,40 @@ public class JobServClient {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "output":
|
case "output":
|
||||||
if (args.length != 7) {
|
candidatePid = getPidArg(args, 7);
|
||||||
System.out.println("Improper formatting, try client --help");
|
if (candidatePid < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
candidatePid = Integer.parseInt(args[6]);
|
|
||||||
} catch (InputMismatchException e) {
|
|
||||||
System.out.println(args[6] + " is not a valid int, much less a valid pid");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
String processOutput = client.getProcessOutput(candidatePid);
|
String processOutput = client.getProcessOutput(candidatePid);
|
||||||
System.out.println(processOutput);
|
System.out.println(processOutput);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "status":
|
case "status":
|
||||||
if (args.length != 7) {
|
candidatePid = getPidArg(args, 7);
|
||||||
System.out.println("Improper formatting, try client --help");
|
if (candidatePid < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
candidatePid = Integer.parseInt(args[6]);
|
|
||||||
|
|
||||||
} catch (InputMismatchException e) {
|
|
||||||
System.out.println(args[6] + " is not a valid int, much less a valid pid");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean processStatus = client.getProcessStatus(candidatePid);
|
Boolean processStatus = client.getProcessStatus(candidatePid);
|
||||||
System.out.printf("Process is currently running? %b\n", processStatus);
|
System.out.printf("Process is currently running? %b\n", processStatus);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "kill":
|
case "kill":
|
||||||
if (args.length != 7) {
|
candidatePid = getPidArg(args, 7);
|
||||||
System.out.println("Improper formatting, try client --help");
|
if (candidatePid < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
candidatePid = Integer.parseInt(args[6]);
|
|
||||||
|
|
||||||
} catch (InputMismatchException e) {
|
|
||||||
System.out.println(args[6] + " is not a valid int, much less a valid pid");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
client.killProcess(candidatePid);
|
client.killProcess(candidatePid);
|
||||||
System.out.println("End process request recieved!");
|
System.out.println("End process request recieved!");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "return":
|
case "return":
|
||||||
if (args.length != 7) {
|
candidatePid = getPidArg(args, 7);
|
||||||
System.out.println("Improper formatting, try client --help");
|
if (candidatePid < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
candidatePid = Integer.parseInt(args[6]);
|
|
||||||
|
|
||||||
} catch (InputMismatchException e) {
|
|
||||||
System.out.println(args[6] + " is not a valid int, much less a valid pid");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int returnCode = client.getProcessReturn(candidatePid);
|
int returnCode = client.getProcessReturn(candidatePid);
|
||||||
|
|
||||||
|
|
@ -340,6 +310,28 @@ public class JobServClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* getPidArg()
|
||||||
|
* reentrant code was found in all commands except newjob
|
||||||
|
* this function pulls the pid argument and wraps around the integer case
|
||||||
|
* returns -1 (an invalid PID) if bad index or unparsable int
|
||||||
|
*/
|
||||||
|
private static int getPidArg(String[] args, int index) {
|
||||||
|
if (args.length < index) {
|
||||||
|
System.out.println("Improper formatting, try client --help");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(args[6]);
|
||||||
|
|
||||||
|
} catch (InputMismatchException e) {
|
||||||
|
System.out.println(args[6] + " is not a valid int, much less a valid pid");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* outputHelp()
|
* outputHelp()
|
||||||
* writes help information about all commands in the shell to screen
|
* writes help information about all commands in the shell to screen
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,6 @@ public class JobServServer {
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
// JVM shutdown might break logger functionality
|
|
||||||
// so investigate this....
|
|
||||||
logger.info("Shutting down server");
|
logger.info("Shutting down server");
|
||||||
JobServServer.this.stop();
|
JobServServer.this.stop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue