com.github.threadcontext.httpasyncclient.ContextAsyncClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of httpasyncclient-thread-context Show documentation
Show all versions of httpasyncclient-thread-context Show documentation
httpasyncclient-thread-context
package com.github.threadcontext.httpasyncclient;
import com.github.threadcontext.Context;
import java.io.IOException;
import java.util.concurrent.Future;
import java.util.function.Supplier;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.protocol.HttpContext;
public class ContextAsyncClient extends CloseableHttpAsyncClient {
private final CloseableHttpAsyncClient client;
private final Supplier contextSupplier;
public ContextAsyncClient(CloseableHttpAsyncClient client, Supplier contextSupplier) {
this.client = client;
this.contextSupplier = contextSupplier;
}
public boolean isRunning() {
return client.isRunning();
}
public void start() {
client.start();
}
public void close() throws IOException {
client.close();
}
public Future execute(HttpAsyncRequestProducer producer, HttpAsyncResponseConsumer responseConsumer, HttpContext context, FutureCallback callback) {
Context threadContext = contextSupplier.get();
return client.execute(
new ContextAsyncRequestProducer(producer, threadContext),
new ContextAsyncResponseConsumer<>(responseConsumer, threadContext),
context,
new ContextFutureCallback<>(callback, threadContext)
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy