Skip to content

Instantly share code, notes, and snippets.

@semenodm
Created December 7, 2015 21:57
Show Gist options
  • Save semenodm/1434b155217ba5427850 to your computer and use it in GitHub Desktop.
Save semenodm/1434b155217ba5427850 to your computer and use it in GitHub Desktop.
Awaiting downstream processor completion
public static void process(final AsyncProcessor processor, final Exchange exchange) throws Exception {
final AsyncProcessorAwaitManager awaitManager = exchange.getContext().getAsyncProcessorAwaitManager();
final CountDownLatch latch = new CountDownLatch(1);
boolean sync = processor.process(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
if (!doneSync) {
awaitManager.countDown(exchange, latch);
}
}
@Override
public String toString() {
return "Done " + processor;
}
});
if (!sync) {
awaitManager.await(exchange, latch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment