in twill-core/src/main/java/org/apache/twill/internal/CompositeService.java [82:108]
private void stopAll() throws Exception {
Throwable failureCause = null;
// Stop services in reverse order.
Iterator<Service> itor = services.descendingIterator();
while (itor.hasNext()) {
Service service = itor.next();
try {
if (service.isRunning() || service.state() == State.STARTING) {
service.stopAndWait();
}
} catch (UncheckedExecutionException e) {
// Just catch as we want all services stopped
if (failureCause == null) {
failureCause = e.getCause();
} else {
// Log for sub-sequence service shutdown error, as only the first failure cause will be thrown.
LOG.warn("Failed to stop service {}", service, e);
}
}
}
if (failureCause != null) {
Throwables.propagateIfPossible(failureCause, Exception.class);
throw new RuntimeException(failureCause);
}
}