public class FutureResponseListener extends BufferingResponseListener implements 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,
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, onHeaderspublic 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.CompleteListeneronComplete in class BufferingResponseListenerresult - the result of the request / response exchangepublic boolean cancel(boolean mayInterruptIfRunning)
cancel in interface Future<ContentResponse>public boolean isCancelled()
isCancelled in interface Future<ContentResponse>public boolean isDone()
isDone in interface Future<ContentResponse>public ContentResponse get() throws InterruptedException, ExecutionException
get in interface Future<ContentResponse>InterruptedExceptionExecutionExceptionpublic ContentResponse get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
get in interface Future<ContentResponse>InterruptedExceptionExecutionExceptionTimeoutExceptionCopyright © 1995–2017 Webtide. All rights reserved.