p.setService(service);
}
}
else
{
WrappedProcess w = WrappedProcessFactory.createProcess(_config);
// set service in wrapper so that we may stop the service in case the application terminates and we need to shutdown the wrapper
w.setService(service);
w.init();
wList.add(w);
}
w = wList.get(0);
// start the applications
// the wrapper may have to wait longer for the application to come up ->
// start the application
// in a separate thread and then check that the wrapper is up after a
// max timeout
// but return as soon as possible to the windows service controller
final long maxStartTime = w.getMaxStartTime();
final Future future = pool.submit(new Runnable()
{
public void run()
{
try
{
Thread.yield();
wList.startAll();
}
catch (Throwable ex)
{
ex.printStackTrace();
w.getWrapperLogger().info("Win Service: error starting wrapper " + ex.getMessage());
Runtime.getRuntime().halt(999);
}
}
});
pool.execute(new Runnable()
{
public void run()
{
try
{
future.get(maxStartTime, TimeUnit.MILLISECONDS);
}
catch (Exception ex)
{
ex.printStackTrace();
w.getWrapperLogger().info("Win Service: wrapper did not start within " + maxStartTime + " ms " + ex.getMessage());
Runtime.getRuntime().halt(999);
}
}
});
w.getWrapperLogger().info("Win service: before service init");
// init the service for signaling with services.exe. app will hang
// here until service is stopped
service.init();
// service has terminated -> halt the wrapper jvm
w.getWrapperLogger().info("Win service: terminated correctly");
Runtime.getRuntime().halt(0);
}