|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||

java.lang.Objectorg.xlightweb.FutureResponseHandler
public class FutureResponseHandler
A response handler implementation which supports a future behavior. Typically this response handler will be used, if the send method is required to send the request, but the response should be read in a blocking behavior. Example:
FutureResponseHandler future = new FutureResponseHandler();
HttpRequestHeader header = new HttpRequestHeader("POST", url, "application/octet-stream");
BodyDataSink bodyDataSink = httpClient.send(header, future);
bodyDataSink.transferFrom(source);
bodyDataSink.close();
IHttpResponse response = future.getResponse(); // blocks until the response header is received
if (response.getStatus() != 200) {
throw new IOException("got status " + response.getStatus());
}
| Field Summary |
|---|
| Fields inherited from interface org.xlightweb.IHttpResponseHandler |
|---|
DEFAULT_EXECUTION_MODE, DEFAULT_INVOKE_ON_MODE |
| Constructor Summary | |
|---|---|
FutureResponseHandler()
|
|
| Method Summary | |
|---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of receiving the response. |
IHttpResponse |
get()
blocking call to retrieve the response. |
IHttpResponse |
get(long timeout,
TimeUnit unit)
blocking call to retrieve the response. |
IHttpResponse |
getResponse()
blocking call to retrieve the response. |
IHttpResponse |
getResponse(long timeout,
TimeUnit unit)
blocking call to retrieve the response. |
boolean |
isCancelled()
Returns true if this task was cancelled before it completed normally. |
boolean |
isDone()
Returns true if this task completed. |
void |
onException(IOException ioe)
call back method which will be called if an io exception occurs |
void |
onException(SocketTimeoutException stoe)
call back method which will be called if an socket timeout exception occurs |
void |
onResponse(IHttpResponse response)
call back method which will be called if the response is received |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FutureResponseHandler()
| Method Detail |
|---|
public void onResponse(IHttpResponse response)
throws IOException
onResponse in interface IHttpResponseHandlerresponse - the response
IOException
public void onException(IOException ioe)
throws IOException
onException in interface IHttpResponseHandlerioe - the io exception
IOExceptionpublic void onException(SocketTimeoutException stoe)
onException in interface IHttpSocketTimeoutHandler
public IHttpResponse getResponse()
throws IOException,
InterruptedException,
SocketTimeoutException
Future.get()
getResponse in interface IFutureResponseIOException - if an ioe exception occurs
SocketTimeoutException - if an socket timeout exception occurs
InterruptedException - if the current thread was interrupted while waiting
public IHttpResponse getResponse(long timeout,
TimeUnit unit)
throws IOException,
SocketTimeoutException
Future.get(long, TimeUnit)
getResponse in interface IFutureResponsetimeout - the maximum time to waitunit - the time unit of the timeout argument
IOException - if an ioe exception occurs
SocketTimeoutException - if an socket timeout exception occurs
public IHttpResponse get()
throws InterruptedException,
ExecutionException
IFutureResponse.getResponse() method will be used instead of this method.
get in interface Future<IHttpResponse>get in interface IFutureResponseInterruptedException
ExecutionException
public IHttpResponse get(long timeout,
TimeUnit unit)
throws InterruptedException,
ExecutionException,
TimeoutException
IFutureResponse.getResponse(long, TimeUnit) method will be used instead of this method.
get in interface Future<IHttpResponse>get in interface IFutureResponseInterruptedException
ExecutionException
TimeoutExceptionpublic boolean isDone()
isDone in interface Future<IHttpResponse>isDone in interface IFutureResponsepublic boolean cancel(boolean mayInterruptIfRunning)
cancel in interface Future<IHttpResponse>cancel in interface IFutureResponsemayInterruptIfRunning - true if the receiving process should be interrupted
public boolean isCancelled()
isCancelled in interface Future<IHttpResponse>isCancelled in interface IFutureResponse
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||