Class ResumableAsyncHandler
- java.lang.Object
-
- org.asynchttpclient.handler.resumable.ResumableAsyncHandler
-
- All Implemented Interfaces:
AsyncHandler<Response>
public class ResumableAsyncHandler extends Object implements AsyncHandler<Response>
AnAsyncHandler
which support resumable download, e.g when used with anResumableIOExceptionFilter
, this handler can resume the download operation at the point it was before the interruption occurred. This prevent having to download the entire file again. It's the responsibility of theResumableAsyncHandler
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.Beware that it registers a shutdown hook, that will cause a ClassLoader leak when used in an appserver and only redeploying the application.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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 org.asynchttpclient.AsyncHandler
AsyncHandler.State
-
-
Constructor Summary
Constructors Constructor Description ResumableAsyncHandler()
ResumableAsyncHandler(boolean accumulateBody)
ResumableAsyncHandler(long byteTransferred)
ResumableAsyncHandler(long byteTransferred, AsyncHandler<Response> decoratedAsyncHandler)
ResumableAsyncHandler(AsyncHandler<Response> decoratedAsyncHandler)
ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor)
ResumableAsyncHandler(ResumableAsyncHandler.ResumableProcessor resumableProcessor, boolean accumulateBody)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Request
adjustRequestRange(Request request)
Invoke this API if you want to set the Range header on yourRequest
based on the last valid bytes position.AsyncHandler.State
onBodyPartReceived(HttpResponseBodyPart bodyPart)
Invoked as soon as some response body part are received.Response
onCompleted()
Invoked once the HTTP response processing is finished.AsyncHandler.State
onHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)
Invoked as soon as the HTTP headers have been received.AsyncHandler.State
onStatusReceived(HttpResponseStatus status)
Invoked as soon as the HTTP status line has been receivedvoid
onThrowable(Throwable t)
Invoked when an unexpected exception occurs during the processing of the response.AsyncHandler.State
onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)
Invoked when trailing headers have been received.ResumableAsyncHandler
setResumableListener(ResumableListener resumableListener)
Set aResumableListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.asynchttpclient.AsyncHandler
onConnectionOffer, onConnectionPoolAttempt, onConnectionPooled, onHostnameResolutionAttempt, onHostnameResolutionFailure, onHostnameResolutionSuccess, onRequestSend, onRetry, onTcpConnectAttempt, onTcpConnectFailure, onTcpConnectSuccess, onTlsHandshakeAttempt, onTlsHandshakeFailure, onTlsHandshakeSuccess
-
-
-
-
Constructor Detail
-
ResumableAsyncHandler
public ResumableAsyncHandler(long byteTransferred)
-
ResumableAsyncHandler
public ResumableAsyncHandler(boolean accumulateBody)
-
ResumableAsyncHandler
public ResumableAsyncHandler()
-
ResumableAsyncHandler
public ResumableAsyncHandler(AsyncHandler<Response> decoratedAsyncHandler)
-
ResumableAsyncHandler
public ResumableAsyncHandler(long byteTransferred, AsyncHandler<Response> 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
Description copied from interface:AsyncHandler
Invoked as soon as the HTTP status line has been received- Specified by:
onStatusReceived
in interfaceAsyncHandler<Response>
- 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)
Description copied from interface:AsyncHandler
Invoked when an unexpected exception occurs during the processing of the response. The exception may have been produced by implementation of onXXXReceived method invocation.- Specified by:
onThrowable
in interfaceAsyncHandler<Response>
- Parameters:
t
- aThrowable
-
onBodyPartReceived
public AsyncHandler.State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception
Description copied from interface:AsyncHandler
Invoked as soon as some response body part are received. Could be invoked many times. Beware that, depending on the provider (Netty) this can be notified with empty body parts.- Specified by:
onBodyPartReceived
in interfaceAsyncHandler<Response>
- Parameters:
bodyPart
- response's body part.- Returns:
- a
AsyncHandler.State
telling to CONTINUE or ABORT the current processing. Aborting will also close the connection. - Throws:
Exception
- if something wrong happens
-
onCompleted
public Response onCompleted() throws Exception
Description copied from interface:AsyncHandler
Invoked once the HTTP response processing is finished.
Gets always invoked as last callback method.- Specified by:
onCompleted
in interfaceAsyncHandler<Response>
- Returns:
- T Value that will be returned by the associated
Future
- Throws:
Exception
- if something wrong happens
-
onHeadersReceived
public AsyncHandler.State onHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers) throws Exception
Description copied from interface:AsyncHandler
Invoked as soon as the HTTP headers have been received.- Specified by:
onHeadersReceived
in interfaceAsyncHandler<Response>
- Parameters:
headers
- the HTTP headers.- Returns:
- a
AsyncHandler.State
telling to CONTINUE or ABORT the current processing. - Throws:
Exception
- if something wrong happens
-
onTrailingHeadersReceived
public AsyncHandler.State onTrailingHeadersReceived(io.netty.handler.codec.http.HttpHeaders headers)
Description copied from interface:AsyncHandler
Invoked when trailing headers have been received.- Specified by:
onTrailingHeadersReceived
in interfaceAsyncHandler<Response>
- Parameters:
headers
- the trailing HTTP headers.- Returns:
- a
AsyncHandler.State
telling to CONTINUE or ABORT the current processing.
-
adjustRequestRange
public Request adjustRequestRange(Request request)
Invoke this API if you want to set the Range header on yourRequest
based on the last valid bytes position.
-
setResumableListener
public ResumableAsyncHandler setResumableListener(ResumableListener resumableListener)
Set aResumableListener
- Parameters:
resumableListener
- aResumableListener
- Returns:
- this
-
-