in taverna-server-webapp/src/main/java/org/apache/taverna/server/master/localworker/ForkRunFactory.java [138:207]
public void initFactory() throws Exception {
if (factory != null)
return;
// Generate the arguments to use when spawning the subprocess
factoryProcessName = state.getFactoryProcessNamePrefix() + randomUUID();
ProcessBuilder p = new ProcessBuilder(getJavaBinary());
p.command().add("-jar");
p.command().add(getServerWorkerJar());
if (getExecuteWorkflowScript() == null)
log.fatal("no execute workflow script");
p.command().add(getExecuteWorkflowScript());
p.command().addAll(asList(getExtraArguments()));
p.command().add(factoryProcessName);
p.redirectErrorStream(true);
p.directory(new File(getProperty("javax.servlet.context.tempdir",
getProperty("java.io.tmpdir"))));
// Spawn the subprocess
log.info("about to create subprocess: " + p.command());
factoryProcess = launchSubprocess(p);
outlog = new StreamLogger("FactoryStdout", factoryProcess.getInputStream()) {
@Override
protected void write(String msg) {
log.info(msg);
}
};
errlog = new StreamLogger("FactoryStderr", factoryProcess.getErrorStream()) {
@Override
protected void write(String msg) {
log.info(msg);
}
};
// Wait for the subprocess to register itself in the RMI registry
Calendar deadline = Calendar.getInstance();
deadline.add(SECOND, state.getWaitSeconds());
Exception lastException = null;
lastStartupCheckCount = 0;
while (deadline.after(Calendar.getInstance())) {
try {
sleep(state.getSleepMS());
lastStartupCheckCount++;
factory = getRemoteFactoryHandle(factoryProcessName);
initInteractionDetails(factory);
return;
} catch (InterruptedException ie) {
continue;
} catch (NotBoundException nbe) {
lastException = nbe;
log.info("resource \"" + factoryProcessName
+ "\" not yet registered...");
continue;
} catch (RemoteException re) {
// Unpack a remote exception if we can
lastException = re;
try {
if (re.getCause() != null)
lastException = (Exception) re.getCause();
} catch (Throwable t) {
// Ignore!
}
} catch (RuntimeException e) {
lastException = e;
}
}
if (lastException == null)
lastException = new InterruptedException();
throw lastException;
}