public abstract class AbstractAsyncRequestConsumer<T> extends java.lang.Object implements HttpAsyncRequestConsumer<T>
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.| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicBoolean |
completed |
private java.lang.Exception |
ex |
private T |
result |
| Constructor and Description |
|---|
AbstractAsyncRequestConsumer() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract T |
buildResult(HttpContext context)
Invoked to generate a result object from the received HTTP request
message.
|
void |
close() |
void |
consumeContent(ContentDecoder decoder,
IOControl ioctrl)
Use
onContentReceived(ContentDecoder, IOControl) instead. |
void |
failed(java.lang.Exception ex)
Invoked to signal that the request processing terminated abnormally.
|
java.lang.Exception |
getException()
Returns an exception in case of an abnormal termination.
|
T |
getResult()
Returns a result of the request execution, when available.
|
boolean |
isDone()
Determines whether or not the request execution completed.
|
protected void |
onClose()
Invoked when the consumer is being closed.
|
protected abstract void |
onContentReceived(ContentDecoder decoder,
IOControl ioctrl)
Invoked to process a chunk of content from the
ContentDecoder. |
protected abstract void |
onEntityEnclosed(HttpEntity entity,
ContentType contentType)
Invoked if the request message encloses a content entity.
|
protected abstract void |
onRequestReceived(HttpRequest request)
Invoked when a HTTP request message is received.
|
protected abstract void |
releaseResources()
Invoked to release all system resources currently allocated.
|
void |
requestCompleted(HttpContext context)
Use
buildResult(HttpContext) instead. |
void |
requestReceived(HttpRequest request)
Use
onRequestReceived(HttpRequest) instead. |
private final java.util.concurrent.atomic.AtomicBoolean completed
private volatile T result
private volatile java.lang.Exception ex
protected abstract void onRequestReceived(HttpRequest request) throws HttpException, java.io.IOException
onContentReceived(ContentDecoder, IOControl) method
will be invoked only for if the request message implements
HttpEntityEnclosingRequest interface and has a content
entity enclosed.request - HTTP request message.HttpException - in case of HTTP protocol violationjava.io.IOException - in case of an I/O errorprotected abstract void onEntityEnclosed(HttpEntity entity, ContentType contentType) throws java.io.IOException
entity - HTTP entitycontentType - expected content type.java.io.IOException - in case of an I/O errorprotected abstract void onContentReceived(ContentDecoder decoder, IOControl ioctrl) throws java.io.IOException
ContentDecoder.
The IOControl interface 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.
decoder - content decoder.ioctrl - I/O control of the underlying connection.java.io.IOException - in case of an I/O errorprotected abstract T buildResult(HttpContext context) throws java.lang.Exception
context - HTTP context.java.lang.Exception - in case of an abnormal termination.protected abstract void releaseResources()
protected void onClose()
throws java.io.IOException
java.io.IOException - may be thrown by subclasssespublic final void requestReceived(HttpRequest request) throws HttpException, java.io.IOException
onRequestReceived(HttpRequest) instead.requestReceived in interface HttpAsyncRequestConsumer<T>request - HTTP request message.HttpException - in case of HTTP protocol violationjava.io.IOException - in case of an I/O errorpublic final void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws java.io.IOException
onContentReceived(ContentDecoder, IOControl) instead.consumeContent in interface HttpAsyncRequestConsumer<T>decoder - content decoder.ioctrl - I/O control of the underlying connection.java.io.IOException - in case of an I/O errorpublic final void requestCompleted(HttpContext context)
buildResult(HttpContext) instead.requestCompleted in interface HttpAsyncRequestConsumer<T>context - HTTP contextpublic final void failed(java.lang.Exception ex)
HttpAsyncRequestConsumerfailed in interface HttpAsyncRequestConsumer<T>ex - exceptionpublic final void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic java.lang.Exception getException()
HttpAsyncRequestConsumernull if the request execution is still ongoing
or if it completed successfully.getException in interface HttpAsyncRequestConsumer<T>HttpAsyncRequestConsumer.isDone()public T getResult()
HttpAsyncRequestConsumernull if the request execution is still ongoing.getResult in interface HttpAsyncRequestConsumer<T>HttpAsyncRequestConsumer.isDone()public boolean isDone()
HttpAsyncRequestConsumerHttpAsyncRequestConsumer.getResult()
can be used to obtain the result. If the request processing terminated
abnormally HttpAsyncRequestConsumer.getException() can be used to obtain the cause.isDone in interface HttpAsyncRequestConsumer<T>