Search in sources :

Example 1 with ClosedInput

use of org.vcell.util.executable.ClosedInput in project vcell by virtualcell.

the class SBMLStandaloneImporter method createProcess.

private LiveProcess<ClosedInput, InheritOutput, InheritOutput> createProcess() throws ExecutableException, IOException {
    @SuppressWarnings("resource") ServerSocket ss = new ServerSocket(0);
    InetSocketAddress isa = (InetSocketAddress) ss.getLocalSocketAddress();
    String home = System.getProperty("java.home");
    String exe = home + "/bin/java";
    String classpath = System.getProperty("java.class.path");
    String us = getClass().getName();
    ArrayList<String> cmdArgs = new ArrayList<String>();
    cmdArgs.add(exe);
    cmdArgs.addAll(jvmArgs());
    String[] invokeArgs = { "-classpath", classpath, us };
    cmdArgs.addAll(Arrays.asList(invokeArgs));
    InheritOutput i = new InheritOutput();
    LiveProcess<ClosedInput, InheritOutput, InheritOutput> lp = new LiveProcess<ClosedInput, InheritOutput, InheritOutput>(new ClosedInput(), i, i, cmdArgs.toArray(new String[cmdArgs.size()]));
    lp.setEnvironment(PORT_KEY, Integer.toString(isa.getPort()));
    lp.setEnvironment(HOST_KEY, isa.getHostName());
    lp.begin(OUR_LABEL);
    ss.setSoTimeout(START_TIMEOUT_SECONDS * 1000);
    try {
        channel = ss.accept();
    } catch (SocketTimeoutException sto) {
        throw new ExecutableException("Standalone client failed to communicate in " + START_TIMEOUT_SECONDS + " seconds");
    }
    toChildProcess = new ObjectOutputStream(channel.getOutputStream());
    fromChildProcess = new ObjectInputStream(channel.getInputStream());
    return lp;
}
Also used : ClosedInput(org.vcell.util.executable.ClosedInput) ExecutableException(org.vcell.util.exe.ExecutableException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) ServerSocket(java.net.ServerSocket) ObjectOutputStream(java.io.ObjectOutputStream) InheritOutput(org.vcell.util.executable.InheritOutput) LiveProcess(org.vcell.util.executable.LiveProcess) SocketTimeoutException(java.net.SocketTimeoutException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 ExecutableException (org.vcell.util.exe.ExecutableException)1 ClosedInput (org.vcell.util.executable.ClosedInput)1 InheritOutput (org.vcell.util.executable.InheritOutput)1 LiveProcess (org.vcell.util.executable.LiveProcess)1