private void startRuntimeIfNeeded ( ) { if ( childProcess != null ) { return ; } // If JSII_DEBUG is set, enable traces. String jsiiDebug = System . getenv ( "JSII_DEBUG" ) ; if ( jsiiDebug != null && ! jsiiDebug . isEmpty ( ) && ! jsiiDebug . equalsIgnoreCase ( "false" ) && ! jsiiDebug . equalsIgnoreCase ( "0" ) ) { traceEnabled = true ; } // If JSII_RUNTIME is set, use it to find the jsii-server executable // otherwise, we default to "jsii-runtime" from PATH. String jsiiRuntimeExecutable = System . getenv ( "JSII_RUNTIME" ) ; if ( jsiiRuntimeExecutable == null ) { jsiiRuntimeExecutable = prepareBundledRuntime ( ) ; } if ( traceEnabled ) { System . err . println ( "jsii-runtime: " + jsiiRuntimeExecutable ) ; } ProcessBuilder pb = new ProcessBuilder ( "node" , jsiiRuntimeExecutable ) ; if ( traceEnabled ) { pb . environment ( ) . put ( "JSII_DEBUG" , "1" ) ; } pb . environment ( ) . put ( "JSII_AGENT" , "Java/" + System . getProperty ( "java.version" ) ) ; try { this . childProcess = pb . start ( ) ; } catch ( IOException e ) { throw new JsiiException ( "Cannot find the 'jsii-runtime' executable (JSII_RUNTIME or PATH)" ) ; } try { OutputStreamWriter stdinStream = new OutputStreamWriter ( this . childProcess . getOutputStream ( ) , "UTF-8" ) ; InputStreamReader stdoutStream = new InputStreamReader ( this . childProcess . getInputStream ( ) , "UTF-8" ) ; InputStreamReader stderrStream = new InputStreamReader ( this . childProcess . getErrorStream ( ) , "UTF-8" ) ; this . stderr = new BufferedReader ( stderrStream ) ; this . stdout = new BufferedReader ( stdoutStream ) ; this . stdin = new BufferedWriter ( stdinStream ) ; handshake ( ) ; this . client = new JsiiClient ( this ) ; // if trace is enabled, start a thread that continuously reads from the child process's // STDERR and prints to my STDERR. if ( traceEnabled ) { startPipeErrorStreamThread ( ) ; } } catch ( IOException e ) { throw new JsiiException ( e ) ; } }
Starts jsii - server as a child process if it is not already started .