private void closeServerSocket(ServerSocket serverSocket) { try { log("Terminating..."); terminated = true; serverSocket.close(); } catch (IOException e) { throw VMError.shouldNotReachHere(e); } }
private boolean processRequest(Socket socket) { try { DataOutputStream output = new DataOutputStream(socket.getOutputStream()); DataInputStream input = new DataInputStream(socket.getInputStream()); try { return processCommand(socket, SubstrateServerMessage.receive(input)); } catch (Throwable t) { log("Execution failed: " + t + "\n"); t.printStackTrace(logOutput); sendExitStatus(output, 1); } } catch (IOException ioe) { log("Failed fetching the output stream."); } finally { closeConnection(socket); log("Connection with the client closed.\n"); // Remove the application class loader and save a GC on the next compilation System.gc(); System.runFinalization(); System.gc(); log("Available Memory: " + Runtime.getRuntime().freeMemory() + "\n"); } return true; }
threadPoolExecutor.purge(); if (port == 0) { log("Server selects ephemeral port\n"); } else { log("Try binding server to port " + port + "...\n"); System.out.println(portLogMessage); System.out.flush(); log(portLogMessage); log("Accepted request from " + socket.getInetAddress().getHostName() + ". Queuing to position: " + threadPoolExecutor.getQueue().size() + "\n"); threadPoolExecutor.execute(() -> { if (!processRequest(socket)) { log("Compilation server timed out. Shutting down...\n"); } catch (SocketException se) { log("Terminated: " + se.getMessage() + "\n"); if (!terminated) { log("Server error: " + se.getMessage() + "\n"); log("IOException in the socket operation.", e); } finally { log("Shutting down server...\n"); try { Thread.sleep(10000);
switch (serverCommand.command) { case STOP_SERVER: log("Received 'stop' request. Shutting down server.\n"); sendExitStatus(output, 0); return false; case GET_VERSION: log("Received 'version' request. Responding with " + System.getProperty(GRAALVM_VERSION_PROPERTY) + ".\n"); SubstrateServerMessage.send(new SubstrateServerMessage(serverCommand.command, System.getProperty(GRAALVM_VERSION_PROPERTY).getBytes()), output); return Instant.now().isBefore(lastKeepAliveAction.plus(Duration.ofMinutes(TIMEOUT_MINUTES))); if (activeTasks > 1) { String message = "Can not build image: tasks are already running in the server.\n"; log(message); sendError(output, message); sendExitStatus(output, -1); } else { log("Starting compilation for request:\n%s\n", serverCommand.payloadString()); final ArrayList<String> arguments = new ArrayList<>(Arrays.asList(serverCommand.payloadString().split("\n"))); () -> executeCompilation(arguments)); sendExitStatus(output, exitStatus); log("Image building completed.\n"); log("Received 'abort' request. Interrupting all image build tasks.\n"); return true; default: log("Invalid command: " + serverCommand.command); sendExitStatus(output, 1);