org.xlightweb
Interface IFutureResponse

Package class diagram package IFutureResponse
All Superinterfaces:
Future<IHttpResponse>
All Known Implementing Classes:
FutureResponseHandler

public interface IFutureResponse
extends Future<IHttpResponse>

The IFutureResponse represents the result of an asynchronous call. Methods are provided to check if the call is complete, to wait for its completion, and to retrieve the result of the computation. The result can only be retrieved using method get when the computation has completed, blocking if necessary until it is ready. Cancellation is performed by the cancel method. Additional methods are provided to determine if the task completed normally or was cancelled. Once a computation has completed, the computation cannot be cancelled.

Example:

 
  HttpClient client = new HttpClient();
  
  IFutureResponse futureResponse = client.send(url);
  
  // do something else
  
  IHttpResponse response = futureResponse.getResponse();
  // ...
 


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.
 

Method Detail

getResponse

IHttpResponse getResponse()
                          throws IOException,
                                 InterruptedException,
                                 SocketTimeoutException
blocking call to retrieve the response. Often this method will be used instead (Future.get()

Returns:
the response
Throws:
IOException - if an ioe exception occurs
InterruptedException - if the current thread was interrupted while waiting
SocketTimeoutException - if an socket timeout exception occurs

getResponse

IHttpResponse getResponse(long timeout,
                          TimeUnit unit)
                          throws IOException,
                                 InterruptedException,
                                 SocketTimeoutException
blocking call to retrieve the response. Often this method will be used instead (Future.get(long, TimeUnit)

Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
the response
Throws:
IOException - if an ioe exception occurs
InterruptedException - if the current thread was interrupted while waiting
SocketTimeoutException - if an socket timeout exception occurs

get

IHttpResponse get()
                  throws InterruptedException,
                         ExecutionException
blocking call to retrieve the response. Often the getResponse() method will be used instead of this method.

This method exists for compatibility reasons

Specified by:
get in interface Future<IHttpResponse>
Throws:
InterruptedException
ExecutionException

get

IHttpResponse get(long timeout,
                  TimeUnit unit)
                  throws InterruptedException,
                         ExecutionException,
                         TimeoutException
blocking call to retrieve the response. Often the getResponse(long, TimeUnit) method will be used instead of this method.

This method exists for compatibility reasons

Specified by:
get in interface Future<IHttpResponse>
Throws:
InterruptedException
ExecutionException
TimeoutException

isDone

boolean isDone()
Returns true if this task completed. Completion may be due to normal termination, an exception, or cancellation.

Specified by:
isDone in interface Future<IHttpResponse>
Returns:
true if this task completed.

cancel

boolean cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of receiving the response. This attempt will fail if the response has already received, already been cancelled, or could not be cancelled for some other reason. The mayInterruptIfRunning parameter determines whether the receiving process should be interrupted

Specified by:
cancel in interface Future<IHttpResponse>
Parameters:
mayInterruptIfRunning - true if the receiving process should be interrupted
Returns:
false if the receiving process could not be cancelled, typically because it has already completed normally; true otherwise

isCancelled

boolean isCancelled()
Returns true if this task was cancelled before it completed normally.

Specified by:
isCancelled in interface Future<IHttpResponse>
Returns:
true if task was cancelled before it completed