Improve handling of exceptions raised during CamelContext startup - Closes
@@ -68,20 +68,17 @@ public class CamelMainSupport {
});
}
- public void start() throws InterruptedException {
+ public void start() throws Exception {
log.info("Starting CamelContext");
- exService.execute(new Runnable() {
- @Override
- public void run() {
- try {
- camelMain.run();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ CamelContextStarter starter = new CamelContextStarter();
+ exService.execute(starter);
+ startFinishedSignal.await();
+
+ if (starter.hasException()) {
+ log.info("CamelContext failed to start", starter.getException());
+ throw starter.getException();
}
- });
- startFinishedSignal.await();
log.info("CamelContext started");
}
@@ -134,4 +131,30 @@ public class CamelMainSupport {
}
}
+
+ private class CamelContextStarter implements Runnable {
+ private Exception startException;
+
+ @Override
+ public void run() {
+ try {
+ camelMain.run();
+ } catch (Exception e) {
+ if (startFinishedSignal.getCount() > 0) {
+ startException = e;
+ startFinishedSignal.countDown();
+ } else {
+ log.error("Caught exception from CamelContext", e);
+ }
+ }
+ }
+
+ public boolean hasException() {
+ return startException != null;
+ }
+
+ public Exception getException() {
+ return startException;
+ }
+ }
}
