Class CompletableResponseListener
- All Implemented Interfaces:
- EventListener, Response.AsyncContentListener, Response.BeginListener, Response.CompleteListener, Response.ContentListener, Response.ContentSourceListener, Response.FailureListener, Response.HeaderListener, Response.HeadersListener, Response.Listener, Response.ResponseListener, Response.SuccessListener
A BufferingResponseListener that sends a Request
and returns a CompletableFuture that is completed when
onComplete(Result) is called.
Typical usage:
var request = client.newRequest(...)...;
CompletableFuture<ContentResponse> completable = new CompletableResponseListener(request).send();
// Attach actions that run when the request/response is complete.
completable.thenApply(response -> ...)
    .whenComplete((response, failure) -> ...);
// Possibly even block waiting for the response.
ContentResponse response = completable.get(5, TimeUnit.SECONDS);
- 
Constructor SummaryConstructorsConstructorDescriptionCompletableResponseListener(Request request) CompletableResponseListener(Request request, int maxLength) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidonComplete(Result result) Callback method invoked when the request and the response have been processed, either successfully or not.send()Sends the request asynchronously and returns aCompletableFuturethat is completed when the request/response completes.send(Connection connection) Sends the request asynchronously via the givenConnectionand returns aCompletableFuturethat is completed when the request/response completes.send(Destination destination) Sends the request asynchronously via the givenDestinationand returns aCompletableFuturethat is completed when the request/response completes.Methods inherited from class BufferingResponseListenergetContent, getContentAsInputStream, getContentAsString, getContentAsString, getContentAsString, getEncoding, getMediaType, onContent, onHeadersMethods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Response.AsyncContentListeneronContentSourceMethods inherited from interface Response.ContentListeneronContentMethods inherited from interface Response.ListeneronBegin, onFailure, onHeader, onSuccess
- 
Constructor Details- 
CompletableResponseListener
- 
CompletableResponseListener
 
- 
- 
Method Details- 
getRequest
- 
sendSends the request asynchronously and returns a CompletableFuturethat is completed when the request/response completes.- Returns:
- a CompletableFuturethat is completed when the request/response completes
- See Also:
 
- 
sendSends the request asynchronously via the given Destinationand returns aCompletableFuturethat is completed when the request/response completes.- Parameters:
- destination- the destination to send the request to
- Returns:
- a CompletableFuturethat is completed when the request/response completes
- See Also:
 
- 
sendSends the request asynchronously via the given Connectionand returns aCompletableFuturethat is completed when the request/response completes.- Parameters:
- connection- the connection to send the request to
- Returns:
- a CompletableFuturethat is completed when the request/response completes
- See Also:
 
- 
onCompleteDescription copied from interface:Response.CompleteListenerCallback method invoked when the request and the response have been processed, either successfully or not.The resultparameter contains the request, the response, and eventual failures.Requests may complete after response, for example in case of big uploads that are discarded or read asynchronously by the server. This method is always invoked after Response.SuccessListener.onSuccess(Response)orResponse.FailureListener.onFailure(Response, Throwable), and only when request indicates that it is completed.- Specified by:
- onCompletein interface- Response.CompleteListener
- Specified by:
- onCompletein interface- Response.Listener
- Specified by:
- onCompletein class- BufferingResponseListener
- Parameters:
- result- the result of the request / response exchange
 
 
-