com.ning.http.client.resumable
Class ResumableAsyncHandler<T>

java.lang.Object
  extended by com.ning.http.client.resumable.ResumableAsyncHandler<T>
All Implemented Interfaces:
AsyncHandler<T>

public class ResumableAsyncHandler<T>
extends Object
implements AsyncHandler<T>

An AsyncHandler which support resumable download, e.g when used with an ResumableIOExceptionFilter, this handler can resume the download operation at the point it was before the interruption occured. This prevent having to download the entire file again. It's the responsibility of the TransferListener to track how many bytes has been transferred and to properly adjust the file's write position.

In case of a JVM crash/shutdown, you can create an instance of this class and pass the last valid bytes position.


Nested Class Summary
static interface ResumableAsyncHandler.ResumableProcessor
          An interface to implement in order to manage the way the incomplete file management are handled.
 
Nested classes/interfaces inherited from interface com.ning.http.client.AsyncHandler
AsyncHandler.STATE
 
Constructor Summary
ResumableAsyncHandler()
           
ResumableAsyncHandler(AsyncHandler<T> decoratedAsyncHandler)
           
ResumableAsyncHandler(boolean accumulateBody)
           
ResumableAsyncHandler(long byteTransferred)
           
ResumableAsyncHandler(long byteTransferred, AsyncHandler<T> decoratedAsyncHandler)
           
ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor)
           
ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor, boolean accumulateBody)
           
 
Method Summary
 Request adjustRequestRange(Request request)
          Invoke this API if you want to set the Range header on your Request based on the last valid bytes position.
 AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
          Invoked as soon as some response body part are received.
 T onCompleted()
          Invoked once the HTTP response processing is finished.
 AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
          Invoked as soon as the HTTP headers has been received.
 AsyncHandler.STATE onStatusReceived(HttpResponseStatus status)
          Invoked as soon as the HTTP status line has been received
 void onThrowable(Throwable t)
          Invoked when an unexpected exception occurs during the processing of the response.
 ResumableAsyncHandler setResumableListener(ResumableListener resumableListener)
          Set a ResumableListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResumableAsyncHandler

public ResumableAsyncHandler(long byteTransferred)

ResumableAsyncHandler

public ResumableAsyncHandler(boolean accumulateBody)

ResumableAsyncHandler

public ResumableAsyncHandler()

ResumableAsyncHandler

public ResumableAsyncHandler(AsyncHandler<T> decoratedAsyncHandler)

ResumableAsyncHandler

public ResumableAsyncHandler(long byteTransferred,
                             AsyncHandler<T> decoratedAsyncHandler)

ResumableAsyncHandler

public ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor)

ResumableAsyncHandler

public ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor,
                             boolean accumulateBody)
Method Detail

onStatusReceived

public AsyncHandler.STATE onStatusReceived(HttpResponseStatus status)
                                    throws Exception
Invoked as soon as the HTTP status line has been received

Specified by:
onStatusReceived in interface AsyncHandler<T>
Parameters:
status - the status code and test of the response
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onThrowable

public void onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response. The exception may have been produced by implementation of onXXXReceived method invokation.

Specified by:
onThrowable in interface AsyncHandler<T>
Parameters:
t - a Throwable

onBodyPartReceived

public AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart)
                                      throws Exception
Invoked as soon as some response body part are received. Could be invoked many times.

Specified by:
onBodyPartReceived in interface AsyncHandler<T>
Parameters:
bodyPart - response's body part.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

onCompleted

public T onCompleted()
              throws Exception
Invoked once the HTTP response processing is finished.

Gets always invoked as last callback method.

Specified by:
onCompleted in interface AsyncHandler<T>
Returns:
T Value that will be returned by the associated Future
Throws:
Exception - if something wrong happens

onHeadersReceived

public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers)
                                     throws Exception
Invoked as soon as the HTTP headers has been received. Can potentially be invoked morethan once if a broken server sent trailling headers.

Specified by:
onHeadersReceived in interface AsyncHandler<T>
Parameters:
headers - the HTTP headers.
Returns:
a AsyncHandler.STATE telling to CONTINUE or ABORT the current processing.
Throws:
Exception - if something wrong happens

adjustRequestRange

public Request adjustRequestRange(Request request)
Invoke this API if you want to set the Range header on your Request based on the last valid bytes position.

Parameters:
request - Request
Returns:
a Request with the Range header properly set.

setResumableListener

public ResumableAsyncHandler setResumableListener(ResumableListener resumableListener)
Set a ResumableListener

Parameters:
resumableListener - a ResumableListener
Returns:
this


Copyright © 2011. All Rights Reserved.