Package org.apache.http.nio.protocol
Class AbstractAsyncRequestConsumer<T>
java.lang.Object
org.apache.http.nio.protocol.AbstractAsyncRequestConsumer<T>
- All Implemented Interfaces:
Closeable,AutoCloseable,HttpAsyncRequestConsumer<T>
- Direct Known Subclasses:
BasicAsyncRequestConsumer
public abstract class AbstractAsyncRequestConsumer<T>
extends Object
implements HttpAsyncRequestConsumer<T>
Abstract
HttpAsyncRequestConsumer implementation that relieves its
subclasses from having to manage internal state and provides a number of protected
event methods that they need to implement.- Since:
- 4.2
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract TbuildResult(org.apache.http.protocol.HttpContext context) Invoked to generate a result object from the received HTTP request message.final voidclose()final voidconsumeContent(ContentDecoder decoder, IOControl ioControl) UseonContentReceived(ContentDecoder, IOControl)instead.final voidInvoked to signal that the request processing terminated abnormally.Returns an exception in case of an abnormal termination.Returns a result of the request execution, when available.booleanisDone()Determines whether or not the request execution completed.protected voidonClose()Invoked when the consumer is being closed.protected abstract voidonContentReceived(ContentDecoder decoder, IOControl ioControl) Invoked to process a chunk of content from theContentDecoder.protected abstract voidonEntityEnclosed(org.apache.http.HttpEntity entity, org.apache.http.entity.ContentType contentType) Invoked if the request message encloses a content entity.protected abstract voidonRequestReceived(org.apache.http.HttpRequest request) Invoked when a HTTP request message is received.protected abstract voidInvoked to release all system resources currently allocated.final voidrequestCompleted(org.apache.http.protocol.HttpContext context) UsebuildResult(HttpContext)instead.final voidrequestReceived(org.apache.http.HttpRequest request) UseonRequestReceived(HttpRequest)instead.
-
Constructor Details
-
AbstractAsyncRequestConsumer
public AbstractAsyncRequestConsumer()
-
-
Method Details
-
onRequestReceived
protected abstract void onRequestReceived(org.apache.http.HttpRequest request) throws org.apache.http.HttpException, IOException Invoked when a HTTP request message is received. Please note that theonContentReceived(ContentDecoder, IOControl)method will be invoked only for if the request message implementsHttpEntityEnclosingRequestinterface and has a content entity enclosed.- Parameters:
request- HTTP request message.- Throws:
org.apache.http.HttpException- in case of HTTP protocol violationIOException- in case of an I/O error
-
onEntityEnclosed
protected abstract void onEntityEnclosed(org.apache.http.HttpEntity entity, org.apache.http.entity.ContentType contentType) throws IOException Invoked if the request message encloses a content entity.- Parameters:
entity- HTTP entitycontentType- expected content type.- Throws:
IOException- in case of an I/O error
-
onContentReceived
protected abstract void onContentReceived(ContentDecoder decoder, IOControl ioControl) throws IOException Invoked to process a chunk of content from theContentDecoder. TheIOControlinterface can be used to suspend input events if the consumer is temporarily unable to consume more content.The consumer can use the
ContentDecoder.isCompleted()method to find out whether or not the message content has been fully consumed.- Parameters:
decoder- content decoder.ioControl- I/O control of the underlying connection.- Throws:
IOException- in case of an I/O error
-
buildResult
Invoked to generate a result object from the received HTTP request message.- Parameters:
context- HTTP context.- Returns:
- result of the request processing.
- Throws:
Exception- in case of an abnormal termination.
-
releaseResources
protected abstract void releaseResources()Invoked to release all system resources currently allocated. -
onClose
Invoked when the consumer is being closed.- Throws:
IOException- may be thrown by subclassses- Since:
- 4.3
-
requestReceived
public final void requestReceived(org.apache.http.HttpRequest request) throws org.apache.http.HttpException, IOException UseonRequestReceived(HttpRequest)instead.- Specified by:
requestReceivedin interfaceHttpAsyncRequestConsumer<T>- Parameters:
request- HTTP request message.- Throws:
org.apache.http.HttpException- in case of HTTP protocol violationIOException- in case of an I/O error
-
consumeContent
UseonContentReceived(ContentDecoder, IOControl)instead.- Specified by:
consumeContentin interfaceHttpAsyncRequestConsumer<T>- Parameters:
decoder- content decoder.ioControl- I/O control of the underlying connection.- Throws:
IOException- in case of an I/O error
-
requestCompleted
public final void requestCompleted(org.apache.http.protocol.HttpContext context) UsebuildResult(HttpContext)instead.- Specified by:
requestCompletedin interfaceHttpAsyncRequestConsumer<T>- Parameters:
context- HTTP context
-
failed
Description copied from interface:HttpAsyncRequestConsumerInvoked to signal that the request processing terminated abnormally.- Specified by:
failedin interfaceHttpAsyncRequestConsumer<T>- Parameters:
ex- exception
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getException
Description copied from interface:HttpAsyncRequestConsumerReturns an exception in case of an abnormal termination. This method returnsnullif the request execution is still ongoing or if it completed successfully.- Specified by:
getExceptionin interfaceHttpAsyncRequestConsumer<T>- See Also:
-
getResult
Description copied from interface:HttpAsyncRequestConsumerReturns a result of the request execution, when available. This method returnsnullif the request execution is still ongoing.- Specified by:
getResultin interfaceHttpAsyncRequestConsumer<T>- See Also:
-
isDone
public boolean isDone()Description copied from interface:HttpAsyncRequestConsumerDetermines whether or not the request execution completed. If the request processing terminated normallyHttpAsyncRequestConsumer.getResult()can be used to obtain the result. If the request processing terminated abnormallyHttpAsyncRequestConsumer.getException()can be used to obtain the cause.- Specified by:
isDonein interfaceHttpAsyncRequestConsumer<T>
-