public class FutureResponseListener extends BufferingResponseListener implements java.util.concurrent.Future<ContentResponse>
BufferingResponseListener
that is also a Future
, to allow applications
to block (indefinitely or for a timeout) until onComplete(Result)
is called,
or to abort
the request/response conversation.
Typical usage is:
Request request = httpClient.newRequest(...)...; FutureResponseListener listener = new FutureResponseListener(request); request.send(listener); // Asynchronous send ContentResponse response = listener.get(5, TimeUnit.SECONDS); // Timed block
Response.Listener.Adapter
Constructor and Description |
---|
FutureResponseListener(Request request) |
FutureResponseListener(Request request,
int maxLength) |
Modifier and Type | Method and Description |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
ContentResponse |
get() |
ContentResponse |
get(long timeout,
java.util.concurrent.TimeUnit unit) |
Request |
getRequest() |
boolean |
isCancelled() |
boolean |
isDone() |
void |
onComplete(Result result)
Callback method invoked when the request and the response have been processed,
either successfully or not.
|
getContent, getContentAsInputStream, getContentAsString, getContentAsString, getContentAsString, getEncoding, getMediaType, onContent, onHeaders
public FutureResponseListener(Request request)
public FutureResponseListener(Request request, int maxLength)
public Request getRequest()
public void onComplete(Result result)
Response.CompleteListener
The result
parameter 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)
or
Response.FailureListener.onFailure(Response, Throwable)
, and only when request indicates that
it is completed.
onComplete
in interface Response.CompleteListener
onComplete
in class BufferingResponseListener
result
- the result of the request / response exchangepublic boolean cancel(boolean mayInterruptIfRunning)
cancel
in interface java.util.concurrent.Future<ContentResponse>
public boolean isCancelled()
isCancelled
in interface java.util.concurrent.Future<ContentResponse>
public boolean isDone()
isDone
in interface java.util.concurrent.Future<ContentResponse>
public ContentResponse get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
get
in interface java.util.concurrent.Future<ContentResponse>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public ContentResponse get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
get
in interface java.util.concurrent.Future<ContentResponse>
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
Copyright © 1995–2023 Webtide. All rights reserved.