Skip to content

Conversation

@arturobernalg
Copy link
Member

This change improves the fluent Async API without altering existing behaviour or contracts. It adds executeAsync overloads returning CompletableFuture, including variants that also invoke the existing FutureCallback, making it easier to compose and aggregate asynchronous request execution using standard Java primitives. It also introduces an optional owned bounded default executor, configurable in terms of thread count and queue capacity, for applications that prefer not to manage their own ExecutorService. The existing Future-based methods and the default execution model remain unchanged.

Comment on lines 121 to 125
final ThreadFactory threadFactory = r -> {
final Thread t = new Thread(r, "httpclient5-fluent-async-" + instanceId + "-" + threadCount.incrementAndGet());
t.setDaemon(true);
return t;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use DefaultThreadFactory from core

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*
* @since 4.3
*/
public class Async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class needs a thread-safety policy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just add Contract

Comment on lines 58 to 60
private Executor executor;
private java.util.concurrent.Executor concurrentExec;
private ExecutorService ownedConcurrentExec;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields need to either be volatile, final, or guarded by some other memory barrier (e.g. only accessed from synchronized methods)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*
* @since 5.7
*/
public <T> CompletableFuture<T> executeAsync(final Request request, final HttpClientResponseHandler<T> handler) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we can't push this down into HttpAsyncClient? Seems like this would work as a simple default interface method to adapt the older continuation-passing API to the new promise (CompletableFuture) based API.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm confused. This class provides an async API for synchronous request execution?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm confused. This class provides an async API for synchronous request execution?

@rschmitt Fluent is a wrapper around the classic HttpClient with simplified APIs for most common use cases. Async in Fluent is indeed just a wrapper around multi-threaded executor and synchronous request execution.

This is historic and goes back to the early days of HttpClient 4.x

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm confused. This class provides an async API for synchronous request execution?

Fluent is built on the classic client. The new CompletableFuture methods are just adapters over the existing callback-based API.

…r simpler async composition.

Provide an optional bounded default executor with configurable thread and queue limits.
Keep existing Future-based API and default execution behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants