* @param async
*/
public static void stop(SlaveState slaveState, boolean graceful, boolean async) {
Lifecycle lifecycle = slaveState.getTrait(Lifecycle.class);
if (lifecycle == null) throw new IllegalArgumentException();
Killable killable = slaveState.getTrait(Killable.class);
if (lifecycle.isRunning()) {
for (ServiceListener listener : slaveState.getServiceListeners()) {
listener.beforeServiceStop(graceful);
}
try {
long stoppingTime;
if (graceful || killable == null) {
if (async) {
log.warn("Async graceful stop is not supported.");
}
if (graceful) {
log.info("Stopping service.");
} else {
log.info("Service is not Killable, stopping instead");
}
stoppingTime = System.currentTimeMillis();
lifecycle.stop();
} else {
log.info("Killing service.");
stoppingTime = System.currentTimeMillis();
if (async) {
killable.killAsync();
} else {
killable.kill();
}
}
long stoppedTime = System.currentTimeMillis();
slaveState.getTimeline().addEvent(LIFECYCLE, new Timeline.IntervalEvent(stoppingTime, "Stop", stoppedTime - stoppingTime));
} finally {