in components/camel-blueprint-main/src/main/java/org/apache/camel/blueprint/CamelBlueprintHelper.java [328:364]
public static void waitForBlueprintContainer(final Set<Long> eventHistory, BundleContext context,
final String symbolicName, final int bpEvent, final Runnable runAndWait)
throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final Throwable[] pThrowable = new Throwable[] {null};
ServiceRegistration<BlueprintListener> registration = context.registerService(BlueprintListener.class, new BlueprintListener() {
@Override
public void blueprintEvent(BlueprintEvent event) {
if (event.getBundle().getSymbolicName().equals(symbolicName)) {
if (event.getType() == bpEvent) {
// we skip events that we've already seen
// it works with BP container reloads if next CREATE state is at least 1ms after previous one
if (eventHistory == null || eventHistory.add(event.getTimestamp())) {
latch.countDown();
}
} else if (event.getType() == BlueprintEvent.FAILURE) {
// we didn't wait for FAILURE, but we got it - fail fast then
pThrowable[0] = event.getCause();
latch.countDown();
}
}
}
}, null);
if (runAndWait != null) {
runAndWait.run();
}
boolean found = latch.await(CamelBlueprintHelper.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
registration.unregister();
if (!found) {
throw new RuntimeException("Gave up waiting for BlueprintContainer from bundle \"" + symbolicName + "\"");
}
if (pThrowable[0] != null) {
throw new RuntimeException(pThrowable[0].getMessage(), pThrowable[0]);
}
}