com.ning.http.client.providers.jdk
Class JDKFuture<V>

java.lang.Object
  extended by com.ning.http.client.providers.jdk.JDKFuture<V>
All Implemented Interfaces:
FutureImpl<V>, Future<V>
Direct Known Subclasses:
JDKDelegateFuture

public class JDKFuture<V>
extends Object
implements FutureImpl<V>


Field Summary
protected  AsyncHandler<V> asyncHandler
           
protected  AtomicBoolean cancelled
           
protected  AtomicBoolean contentProcessed
           
protected  AtomicReference<Throwable> exception
           
protected  Future<V> innerFuture
           
protected  AtomicBoolean isDone
           
protected  int responseTimeoutInMs
           
protected  AtomicBoolean timedOut
           
protected  AtomicLong touch
           
protected  HttpURLConnection urlConnection
           
 
Constructor Summary
JDKFuture(AsyncHandler<V> asyncHandler, int responseTimeoutInMs, HttpURLConnection urlConnection)
           
 
Method Summary
 void abort(Throwable t)
          Abort the current processing, and propagate the Throwable to the AsyncHandler or Future
 boolean cancel(boolean mayInterruptIfRunning)
           
 void content(V v)
          Set the content that will be returned by this instance
 void done(Callable callable)
          Execute a Callable and if there is no exception, mark this Future as done and release the internal lock.
 V get()
           
 V get(long timeout, TimeUnit unit)
           
 boolean getAndSetWriteBody(boolean writeBody)
          Write the Request body
 boolean getAndSetWriteHeaders(boolean writeHeaders)
          Write the Request headers
 boolean hasExpired()
          Is the Future still valid
 boolean isCancelled()
           
 boolean isDone()
           
protected  void setInnerFuture(Future<V> innerFuture)
           
 void touch()
          Touch the current instance to prevent external service to times out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

innerFuture

protected Future<V> innerFuture

asyncHandler

protected final AsyncHandler<V> asyncHandler

responseTimeoutInMs

protected final int responseTimeoutInMs

cancelled

protected final AtomicBoolean cancelled

timedOut

protected final AtomicBoolean timedOut

isDone

protected final AtomicBoolean isDone

exception

protected final AtomicReference<Throwable> exception

touch

protected final AtomicLong touch

contentProcessed

protected final AtomicBoolean contentProcessed

urlConnection

protected final HttpURLConnection urlConnection
Constructor Detail

JDKFuture

public JDKFuture(AsyncHandler<V> asyncHandler,
                 int responseTimeoutInMs,
                 HttpURLConnection urlConnection)
Method Detail

setInnerFuture

protected void setInnerFuture(Future<V> innerFuture)

done

public void done(Callable callable)
Description copied from interface: FutureImpl
Execute a Callable and if there is no exception, mark this Future as done and release the internal lock.

Specified by:
done in interface FutureImpl<V>

abort

public void abort(Throwable t)
Description copied from interface: FutureImpl
Abort the current processing, and propagate the Throwable to the AsyncHandler or Future

Specified by:
abort in interface FutureImpl<V>

content

public void content(V v)
Description copied from interface: FutureImpl
Set the content that will be returned by this instance

Specified by:
content in interface FutureImpl<V>
Parameters:
v - the content that will be returned by this instance

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<V>

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<V>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<V>

get

public V get()
      throws InterruptedException,
             ExecutionException
Specified by:
get in interface Future<V>
Throws:
InterruptedException
ExecutionException

get

public V get(long timeout,
             TimeUnit unit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException
Specified by:
get in interface Future<V>
Throws:
InterruptedException
ExecutionException
TimeoutException

hasExpired

public boolean hasExpired()
Is the Future still valid

Returns:
true if response has expired and should be terminated.

touch

public void touch()
Touch the current instance to prevent external service to times out.

Specified by:
touch in interface FutureImpl<V>

getAndSetWriteHeaders

public boolean getAndSetWriteHeaders(boolean writeHeaders)
Write the Request headers

Specified by:
getAndSetWriteHeaders in interface FutureImpl<V>

getAndSetWriteBody

public boolean getAndSetWriteBody(boolean writeBody)
Write the Request body

Specified by:
getAndSetWriteBody in interface FutureImpl<V>


Copyright © 2011. All Rights Reserved.