org.apache.http.nio.protocol
Class AbstractAsyncRequestConsumer<T>

java.lang.Object
  extended by org.apache.http.nio.protocol.AbstractAsyncRequestConsumer<T>
All Implemented Interfaces:
Closeable, 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
AbstractAsyncRequestConsumer()
           
 
Method Summary
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(Exception ex)
          Invoked to signal that the request processing terminated abnormally.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAsyncRequestConsumer

public AbstractAsyncRequestConsumer()
Method Detail

onRequestReceived

protected abstract void onRequestReceived(HttpRequest request)
                                   throws HttpException,
                                          IOException
Invoked when a HTTP request message is received. Please note that the onContentReceived(ContentDecoder, IOControl) method will be invoked only for if the request message implements HttpEntityEnclosingRequest interface and has a content entity enclosed.

Parameters:
request - HTTP request message.
Throws:
HttpException - in case of HTTP protocol violation
IOException - in case of an I/O error

onEntityEnclosed

protected abstract void onEntityEnclosed(HttpEntity entity,
                                         ContentType contentType)
                                  throws IOException
Invoked if the request message encloses a content entity.

Parameters:
entity - HTTP entity
contentType - expected content type.
Throws:
IOException - in case of an I/O error

onContentReceived

protected abstract void onContentReceived(ContentDecoder decoder,
                                          IOControl ioctrl)
                                   throws IOException
Invoked to process a chunk of content from the 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.

Parameters:
decoder - content decoder.
ioctrl - I/O control of the underlying connection.
Throws:
IOException - in case of an I/O error

buildResult

protected abstract T buildResult(HttpContext context)
                          throws Exception
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

protected void onClose()
                throws IOException
Invoked when the consumer is being closed.

Throws:
IOException - may be thrown by subclassses
Since:
4.3

requestReceived

public final void requestReceived(HttpRequest request)
                           throws HttpException,
                                  IOException
Use onRequestReceived(HttpRequest) instead.

Specified by:
requestReceived in interface HttpAsyncRequestConsumer<T>
Parameters:
request - HTTP request message.
Throws:
HttpException - in case of HTTP protocol violation
IOException - in case of an I/O error

consumeContent

public final void consumeContent(ContentDecoder decoder,
                                 IOControl ioctrl)
                          throws IOException
Use onContentReceived(ContentDecoder, IOControl) instead.

Specified by:
consumeContent in interface HttpAsyncRequestConsumer<T>
Parameters:
decoder - content decoder.
ioctrl - I/O control of the underlying connection.
Throws:
IOException - in case of an I/O error

requestCompleted

public final void requestCompleted(HttpContext context)
Use buildResult(HttpContext) instead.

Specified by:
requestCompleted in interface HttpAsyncRequestConsumer<T>
Parameters:
context - HTTP context

failed

public final void failed(Exception ex)
Description copied from interface: HttpAsyncRequestConsumer
Invoked to signal that the request processing terminated abnormally.

Specified by:
failed in interface HttpAsyncRequestConsumer<T>
Parameters:
ex - exception

close

public final void close()
                 throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

getException

public Exception getException()
Description copied from interface: HttpAsyncRequestConsumer
Returns an exception in case of an abnormal termination. This method returns null if the request execution is still ongoing or if it completed successfully.

Specified by:
getException in interface HttpAsyncRequestConsumer<T>
See Also:
HttpAsyncRequestConsumer.isDone()

getResult

public T getResult()
Description copied from interface: HttpAsyncRequestConsumer
Returns a result of the request execution, when available. This method returns null if the request execution is still ongoing.

Specified by:
getResult in interface HttpAsyncRequestConsumer<T>
See Also:
HttpAsyncRequestConsumer.isDone()

isDone

public boolean isDone()
Description copied from interface: HttpAsyncRequestConsumer
Determines whether or not the request execution completed. If the request processing terminated normally HttpAsyncRequestConsumer.getResult() can be used to obtain the result. If the request processing terminated abnormally HttpAsyncRequestConsumer.getException() can be used to obtain the cause.

Specified by:
isDone in interface HttpAsyncRequestConsumer<T>


Copyright © 2005–2015 The Apache Software Foundation. All rights reserved.