EnvironmentClassLoader envLoader
= EnvironmentClassLoader.create(_system.getClassLoader());
Thread thread = Thread.currentThread();
WriteStream jvmOut = null;
ServerSocket ss = null;
Socket s = null;
try {
thread.setContextClassLoader(envLoader);
envLoader.start();
ss = new ServerSocket(0, 5, InetAddress.getByName("127.0.0.1"));
int port = ss.getLocalPort();
log.warning("Watchdog starting Resin[" + _watchdog.getId() + "]");
jvmOut = createJvmOut();
_process = createProcess(port, jvmOut);
if (_process != null) {
if (_process instanceof JniProcess)
_pid = ((JniProcess) _process).getPid();
else
_pid = 0;
InputStream stdIs = _process.getInputStream();
_stdOs = _process.getOutputStream();
WatchdogProcessLogThread logThread
= new WatchdogProcessLogThread(stdIs, jvmOut);
ThreadPool.getCurrent().start(logThread);
s = connectToChild(ss);
message(new StartInfoMessage(_watchdog.isRestart(),
_watchdog.getRestartMessage()));
_status = _process.waitFor();
logStatus(_status);
}
} catch (Exception e) {
log.log(Level.WARNING, e.toString(), e);
try {
Thread.sleep(5000);
} catch (Exception e1) {
}
} catch (Throwable e) {
log.log(Level.WARNING, e.toString(), e);
} finally {
if (ss != null) {
try {
ss.close();
} catch (Exception e) {
}
}
try {
if (s != null)
s.close();
} catch (Throwable e) {
log.log(Level.FINER, e.toString(), e);
}
kill();
if (jvmOut != null && ! _watchdog.isConsole()) {
try {
synchronized (jvmOut) {
jvmOut.close();
}
} catch (Exception e) {
}
}