RunManager rm = RunManager.getInstance();
try {
Runner r = rm.get(runner);
if (r == null) {
throw new RunnerException("Request for unknown runner: " +
runner);
}
boolean wait = false;
if (waitParam != null) {
wait = Boolean.parseBoolean(waitParam);
}
StatusWaiter waiter = null;
if (action.equalsIgnoreCase("start")) {
waiter = rm.start(r, wait);
} else if (action.equalsIgnoreCase("stop")) {
waiter = rm.stop(r, wait);
} else if (action.equalsIgnoreCase("restart")) {
// stop the runner and wait for it to stop
waiter = rm.stop(r, true);
if (waiter != null) {
waiter.waitFor();
}
// wait for a bit so that everything gets cleaned up
try {
Thread.sleep(ActionResource.getRestartDelay() * 1000);
} catch (InterruptedException ie) {
// oh well
}
// restart the runner
waiter = rm.start(r, wait);
} else if (action.equalsIgnoreCase("log")) {
// read the log file
if (r.getLogFile() != null) {
BufferedReader reader = new BufferedReader(
new FileReader(r.getLogFile()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
ResponseBuilder rb = Response.ok(sb.toString());
return rb.build();
}
} else {
throw new RunnerException("Unkown action " + action);
}
// if necessary, wait for the runner
if (waiter != null) {
waiter.waitFor();