@Override public void initialize(String shardIdToProcess) { try { this.shardId = shardIdToProcess; try { this.process = startProcess(); } catch (IOException e) { /* * The process builder has thrown an exception while starting the child process so we would like to shut * down */ throw new IOException("Failed to start client executable", e); } // Initialize all of our utility objects that will handle interacting with the process over // STDIN/STDOUT/STDERR messageWriter.initialize(process.getOutputStream(), shardId, objectMapper, executorService); messageReader.initialize(process.getInputStream(), shardId, objectMapper, executorService); readSTDERRTask.initialize(process.getErrorStream(), shardId, "Reading STDERR for " + shardId); // Submit the error reader for execution stderrReadTask = executorService.submit(readSTDERRTask); protocol = new MultiLangProtocol(messageReader, messageWriter, shardId); if (!protocol.initialize()) { throw new RuntimeException("Failed to initialize child process"); } initialized = true; } catch (Throwable t) { // Any exception in initialize results in MultiLangDaemon shutdown. stopProcessing("Encountered an error while trying to initialize record processor", t); } }