opensearch-sdk-java icon indicating copy to clipboard operation
opensearch-sdk-java copied to clipboard

[FEATURE] Add Async version of client.execute to SDKClient and friends

Open dbwiddis opened this issue 2 years ago • 4 comments

Is your feature request related to a problem?

To support AD Extension work we have implemented client.execute(action, request, actionListener).

To support future development we need the async version: future = client.execute(action, request).

What solution would you like?

So current code that looks like this:

CompletableFuture<ExtensionActionResponse> futureResponse = new CompletableFuture<>();
client.execute(
    ProxyAction.INSTANCE,
    proxyActionRequest,
    ActionListener.wrap(r -> futureResponse.complete(r), e -> futureResponse.completeExceptionally(e))
);

Would look like this:

CompletableFuture<ExtensionActionResponse> futureResponse = client.execute(
    ProxyAction.INSTANCE,
    proxyActionRequest
);

This should be a relatively simple method overload moving the ActionListener.wrap() bits into the new method and adding a return value.

This should be added to SDKClient and SDKRestClient as a minimum.

What alternatives have you considered?

Forcing people to wrap action listeners all the time. Ugh!

Do you have any additional context?

The method signature should probably match AbstractClient except replacing the ActionFuture with the more useful CompletableFuture

public final <Request extends ActionRequest, Response extends ActionResponse> ActionFuture<Response> execute(
    ActionType<Response> action,
    Request request
) { ... }

dbwiddis avatar Mar 19 '23 02:03 dbwiddis

I would like to take it

MehulBatra avatar Apr 15 '23 20:04 MehulBatra

Hey @MehulBatra, it's all yours!

dbwiddis avatar Apr 15 '23 21:04 dbwiddis

@MehulBatra are you still working on this?

lorenz-scalable avatar Nov 22 '23 14:11 lorenz-scalable

yes

MehulBatra avatar Jan 28 '24 15:01 MehulBatra