Skip to content

Commit f16cae2

Browse files
committed
chore(components): simplify mdc CompletableFuture method
1 parent 0684bb7 commit f16cae2

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

components/camel-mdc/src/main/java/org/apache/camel/mdc/MDCProcessorsInterceptStrategy.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.camel.NamedNode;
2727
import org.apache.camel.Processor;
2828
import org.apache.camel.spi.InterceptStrategy;
29+
import org.apache.camel.support.AsyncCallbackToCompletableFutureAdapter;
2930
import org.apache.camel.support.AsyncProcessorConverterHelper;
3031
import org.slf4j.MDC;
3132

@@ -93,23 +94,12 @@ public void process(Exchange exchange) throws Exception {
9394

9495
@Override
9596
public CompletableFuture<Exchange> processAsync(Exchange exchange) {
96-
CompletableFuture<Exchange> future = new CompletableFuture<>();
97-
Map<String, String> previousContext = MDC.getCopyOfContextMap();
98-
mdcService.setMDC(exchange);
99-
asyncProcessor.process(exchange, doneSync -> {
100-
if (exchange.getException() != null) {
101-
future.completeExceptionally(exchange.getException());
102-
} else {
103-
future.complete(exchange);
104-
}
105-
if (previousContext != null) {
106-
MDC.setContextMap(previousContext);
107-
} else {
108-
MDC.clear();
109-
}
110-
});
111-
return future;
97+
AsyncCallbackToCompletableFutureAdapter<Exchange> callback
98+
= new AsyncCallbackToCompletableFutureAdapter<>(exchange);
99+
process(exchange, callback);
100+
return callback.getFuture();
112101
}
102+
113103
};
114104
}
115105

0 commit comments

Comments
 (0)