Package org.eclipse.jetty.client.util
Class FutureResponseListener
- java.lang.Object
-
- org.eclipse.jetty.client.api.Response.Listener.Adapter
-
- org.eclipse.jetty.client.util.BufferingResponseListener
-
- org.eclipse.jetty.client.util.FutureResponseListener
-
- All Implemented Interfaces:
java.util.concurrent.Future<ContentResponse>
,java.util.EventListener
,Response.AsyncContentListener
,Response.BeginListener
,Response.CompleteListener
,Response.ContentListener
,Response.DemandedContentListener
,Response.FailureListener
,Response.HeaderListener
,Response.HeadersListener
,Response.Listener
,Response.ResponseListener
,Response.SuccessListener
public class FutureResponseListener extends BufferingResponseListener implements java.util.concurrent.Future<ContentResponse>
ABufferingResponseListener
that is also aFuture
, to allow applications to block (indefinitely or for a timeout) untilonComplete(Result)
is called, or toabort
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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.api.Response.Listener
Response.Listener.Adapter
-
-
Constructor Summary
Constructors Constructor Description FutureResponseListener(Request request)
FutureResponseListener(Request request, int maxLength)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.eclipse.jetty.client.util.BufferingResponseListener
getContent, getContentAsInputStream, getContentAsString, getContentAsString, getContentAsString, getEncoding, getMediaType, onContent, onHeaders
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.client.api.Response.AsyncContentListener
onContent
-
Methods inherited from interface org.eclipse.jetty.client.api.Response.ContentListener
onContent
-
Methods inherited from interface org.eclipse.jetty.client.api.Response.DemandedContentListener
onBeforeContent
-
Methods inherited from interface org.eclipse.jetty.client.api.Response.Listener
onBegin, onFailure, onHeader, onSuccess
-
-
-
-
Method Detail
-
getRequest
public Request getRequest()
-
onComplete
public void onComplete(Result result)
Description copied from interface:Response.CompleteListener
Callback method invoked when the request and the response have been processed, either successfully or not.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)
orResponse.FailureListener.onFailure(Response, Throwable)
, and only when request indicates that it is completed.- Specified by:
onComplete
in interfaceResponse.CompleteListener
- Specified by:
onComplete
in interfaceResponse.Listener
- Specified by:
onComplete
in classBufferingResponseListener
- Parameters:
result
- the result of the request / response exchange
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancel
in interfacejava.util.concurrent.Future<ContentResponse>
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfacejava.util.concurrent.Future<ContentResponse>
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfacejava.util.concurrent.Future<ContentResponse>
-
get
public ContentResponse get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
- Specified by:
get
in interfacejava.util.concurrent.Future<ContentResponse>
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
-
get
public ContentResponse get(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.TimeoutException
- Specified by:
get
in interfacejava.util.concurrent.Future<ContentResponse>
- Throws:
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
-
-