CaoManhDat commented on a change in pull request #1770:
URL: https://github.com/apache/lucene-solr/pull/1770#discussion_r474380934
##########
File path:
solr/solrj/src/java/org/apache/solr/client/solrj/impl/Http2SolrClient.java
##########
@@ -394,26 +393,26 @@ public void onHeaders(Response response) {
assert ObjectReleaseTracker.track(is);
try {
NamedList<Object> body = processErrorsAndResponse(solrRequest,
parser, response, is);
- asyncListener.onSuccess(body);
- } catch (RemoteSolrException e) {
- if (SolrException.getRootCause(e) != CANCELLED_EXCEPTION) {
- asyncListener.onFailure(e);
- }
- } catch (SolrServerException e) {
- asyncListener.onFailure(e);
+ future.complete(body);
+ } catch (RemoteSolrException | SolrServerException e) {
+ future.completeExceptionally(e);
}
});
}
@Override
public void onFailure(Response response, Throwable failure) {
super.onFailure(response, failure);
- if (failure != CANCELLED_EXCEPTION) {
- asyncListener.onFailure(new
SolrServerException(failure.getMessage(), failure));
- }
+ future.completeExceptionally(new
SolrServerException(failure.getMessage(), failure));
}
});
- return () -> req.abort(CANCELLED_EXCEPTION);
+ future.exceptionally((error) -> {
+ if (error instanceof CancellationException) {
+ req.abort(new Exception());
Review comment:
I feel the way cancellation is implemented is little bit wrong. When we
abort a request the given exception will be called on listeners, in that case
we don't want to cascade that exception further. By doing this way, the `new
Exception()` will be throw to upper level.
##########
File path: solr/solrj/src/java/org/apache/solr/client/solrj/SolrClient.java
##########
@@ -1290,6 +1295,39 @@ public SolrDocumentList getById(Collection<String> ids,
SolrParams params) throw
return request(request, null);
}
+ /**
+ * Execute an asynchronous request against a Solr server for a given
collection.
+ * This is only currently supported on the {@link Http2SolrClient} and
{@link CloudHttp2SolrClient} for now.
+ *
+ * @param request the request to execute
+ * @param collection the collection to execute the request against
+ *
+ * @return a {@link CompletableFuture} that tracks the progress of the async
request. Supports cancelling requests via
+ * {@link CompletableFuture#cancel(boolean)}, adding callbacks/error
handling using {@link CompletableFuture#whenComplete(BiConsumer)}
+ * and {@link CompletableFuture#exceptionally(Function)} methods, and other
CompletableFuture functionality. Will
+ * complete exceptionally in case of either an {@link IOException} or {@link
SolrServerException} during the request.
+ * Once completed, the CompletableFuture will contain a {@link NamedList}
with the response from the server.
+ */
+ public CompletableFuture<NamedList<Object>> requestAsync(final
SolrRequest<?> request, String collection) {
+ throw new UnsupportedOperationException("Async requests not supported on
this Solr Client.");
+ }
+
+ /**
+ * Execute an asynchronous request against a Solr server using the request's
collection parameter.
+ * This is only currently supported on the {@link Http2SolrClient} and
{@link CloudHttp2SolrClient} for now.
+ *
+ * @param request the request to execute
+ *
+ * @return a {@link CompletableFuture} that tracks the progress of the async
request. Supports cancelling requests via
+ * {@link CompletableFuture#cancel(boolean)}, adding callbacks/error
handling using {@link CompletableFuture#whenComplete(BiConsumer)}
+ * and {@link CompletableFuture#exceptionally(Function)} methods, and other
CompletableFuture functionality. Will
+ * complete exceptionally in case of either an {@link IOException} or {@link
SolrServerException} during the request.
+ * Once completed, the CompletableFuture will contain a {@link NamedList}
with the response from the server.
+ */
+ public CompletableFuture<NamedList<Object>> requestAsync(final
SolrRequest<?> request) {
Review comment:
I wonder should we put this method here? Since only Http2SolrClient
gonna support it?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]