all initialized service objects use the same processmanager now, added shutdown hook to deinitialize processmanager and processcontroller objects

This commit is contained in:
Aidan Hahn 2019-05-23 17:24:48 -07:00
parent 3538cac0d8
commit 7b0184cbd3
No known key found for this signature in database
GPG key ID: 327711E983899316
3 changed files with 34 additions and 26 deletions

View file

@ -66,16 +66,21 @@ public class JobServClient {
* writes help information about all commands in the shell to screen * writes help information about all commands in the shell to screen
*/ */
public static void outputHelp() { public static void outputHelp() {
System.out.println("... new (command)"); System.out.println("... new (command)\n"+
System.out.println("Starts a new process on the server"); "Starts a new process on the server\n"+
System.out.println("... output (pid)"); "example: ./client key.pem cert.crt ca.crt localhost 8448 new echo hello world!\n\n"+
System.out.println("Garners output from process on server"); "... output (pid)\n"+
System.out.println("... status (pid)"); "Garners output from process on server\n"+
System.out.println("Returns whether process on server is running"); "example: ./client key.pem cert.crt ca.crt localhost 8448 output 0\n\n"+
System.out.println("... return (pid)"); "... status (pid)\n"+
System.out.println("Collects return code from remote process"); "Returns whether process on server is running"+
System.out.println("... kill (pid)"); "example: ./client key.pem cert.crt ca.crt localhost 8448 status 0\n\n"+
System.out.println("Immediately destroys remote process"); "... return (pid)\n"+
"Collects return code from remote process\n"+
"example: ./client key.pem cert.crt ca.crt localhost 8448 return 0\n\n"+
"... kill (pid)"+
"Immediately destroys remote process"+
"example: ./client key.pem cert.crt ca.crt localhost 8448 kill 0\n\n"+
} }
/* /*

View file

@ -32,17 +32,18 @@ public class JobServServer {
private static final Logger logger = Logger.getLogger(JobServServer.class.getName()); private static final Logger logger = Logger.getLogger(JobServServer.class.getName());
private Server server; private Server server;
private ProcessManager manager;
/* /*
* Constructor * Constructor
* builds server object * builds server object
*/ */
public JobServServer(SslContext ssl, int port) throws IOException { public JobServServer(SslContext ssl, int port) throws IOException {
this.server = NettyServerBuilder.forPort(port) this.server = NettyServerBuilder.forPort(port)
.addService(new ShellServerService()) .addService(new ShellServerService(manager))
.sslContext(ssl) .sslContext(ssl)
.build() .build()
.start(); .start();
} }
/* /*
@ -58,6 +59,7 @@ public class JobServServer {
@Override @Override
public void run() { public void run() {
logger.info("Shutting down server"); logger.info("Shutting down server");
manager.shutdown();
JobServServer.this.stop(); JobServServer.this.stop();
} }
}); });
@ -100,14 +102,14 @@ public class JobServServer {
JobServServer server; JobServServer server;
try { try {
SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(new File(args[1]), new File(args[2])); SslContextBuilder sslContextBuilder = SslContextBuilder.forServer(new File(args[1]), new File(args[2]));
// Mutual TLS trust store and require client auth // Mutual TLS trust store and require client auth
sslContextBuilder.trustManager(new File(args[3])); sslContextBuilder.trustManager(new File(args[3]));
sslContextBuilder.clientAuth(ClientAuth.REQUIRE); sslContextBuilder.clientAuth(ClientAuth.REQUIRE);
server = new JobServServer(GrpcSslContexts.configure(sslContextBuilder).build(), server = new JobServServer(GrpcSslContexts.configure(sslContextBuilder).build(),
Integer.parseInt(args[0])); Integer.parseInt(args[0]));
} catch (InputMismatchException e) { } catch (InputMismatchException e) {
System.out.println("Invalid port!"); System.out.println("Invalid port!");
@ -118,10 +120,11 @@ public class JobServServer {
return; return;
} catch (IOException e) { } catch (IOException e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
return; return;
} }
System.out.println("JobServ Server Initialized! Connect anytime...");
server.blockUntilShutdown(); server.blockUntilShutdown();
} }
} }

View file

@ -21,8 +21,8 @@ class ShellServerService extends ShellServerGrpc.ShellServerImplBase {
* constructor * constructor
* initialized ProcessManager * initialized ProcessManager
*/ */
public ShellServerService() { public ShellServerService(ProcessManager manager) {
manager = new ProcessManager(); this.manager = manager
} }
/* /*