## org.apache.http.nio.protocol
Class AbstractAsyncResponseConsumer<T>

    java.lang.Object
      org.apache.http.nio.protocol.AbstractAsyncResponseConsumer<T>

All Implemented Interfaces:
  Closeable, Cancellable, HttpAsyncResponseConsumer<T>

Direct Known Subclasses:
  BasicAsyncResponseConsumer

    @ThreadSafe
    public abstract class AbstractAsyncResponseConsumer<T>

extends Object
implements HttpAsyncResponseConsumer<T>

Abstract `HttpAsyncResponseConsumer` implementation that relieves its subclasses form having to synchronize access to internal instance variables and provides a number of protected methods that they need to implement.

Since:
  4.2

Constructor Summary
`AbstractAsyncResponseConsumer()`

Method Summary
`protected abstract T` `buildResult(HttpContext context)` Invoked to generate a result object from the received HTTP response message.
`boolean` `cancel()`
`void` `close()`
`void` `consumeContent(ContentDecoder decoder, IOControl ioctrl)` Use `onContentReceived(ContentDecoder, IOControl)` instead.
`void` `failed(Exception ex)` Invoked to signal that the response processing terminated abnormally.
`Exception` `getException()` Returns an exception in case of an abnormal termination.
`T` `getResult()` Returns a result of the response processing, when available.
`boolean` `isDone()` Determines whether or not the response processing completed.
`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 response message encloses a content entity.
`protected abstract void` `onResponseReceived(HttpResponse response)` Invoked when a HTTP response message is received.
`protected abstract void` `releaseResources()` Invoked to release all system resources currently allocated.
`void` `responseCompleted(HttpContext context)` Use `buildResult(HttpContext)` instead.
`void` `responseReceived(HttpResponse response)` Use `onResponseReceived(HttpResponse)` instead.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### AbstractAsyncResponseConsumer

    public AbstractAsyncResponseConsumer()

Method Detail

### onResponseReceived

    protected abstract void onResponseReceived(HttpResponse response)
                                        throws HttpException,
                                               IOException

  Invoked when a HTTP response message is received. Please note that the `onContentReceived(ContentDecoder, IOControl)` method will be invoked only if the response messages has a content entity enclosed.

  Parameters:
    `response` - HTTP response message.
  Throws:
    `HttpException` - in case of HTTP protocol violation
    `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

### onEntityEnclosed

    protected abstract void onEntityEnclosed(HttpEntity entity,
                                             ContentType contentType)
                                      throws IOException

  Invoked if the response message encloses a content entity.

  Parameters:
    `entity` - HTTP entity
    `contentType` - expected content type.
  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 response message.

  Parameters:
    `context` - HTTP context.
  Returns:
    result of the response processing.
  Throws:
    `Exception` - in case of an abnormal termination.

### releaseResources

    protected abstract void releaseResources()

  Invoked to release all system resources currently allocated.

### responseReceived

    public final void responseReceived(HttpResponse response)
                                throws IOException,
                                       HttpException

  Use `onResponseReceived(HttpResponse)` instead.

  Specified by:
    `responseReceived` in interface `HttpAsyncResponseConsumer<T>`
  Parameters:
    `response` - HTTP response message.
  Throws:
    `IOException` - in case of an I/O error
    `HttpException` - in case of HTTP protocol violation

### consumeContent

    public final void consumeContent(ContentDecoder decoder,
                                     IOControl ioctrl)
                              throws IOException

  Use `onContentReceived(ContentDecoder, IOControl)` instead.

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

### responseCompleted

    public final void responseCompleted(HttpContext context)

  Use `buildResult(HttpContext)` instead.

  Specified by:
    `responseCompleted` in interface `HttpAsyncResponseConsumer<T>`
  Parameters:
    `context` - HTTP context

### cancel

    public final boolean cancel()

  Specified by:
    `cancel` in interface `Cancellable`

### failed

    public final void failed(Exception ex)

  Description copied from interface: `HttpAsyncResponseConsumer`
  Invoked to signal that the response processing terminated abnormally.

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

### close

    public final void close()

  Specified by:
    `close` in interface `Closeable`

### getException

    public Exception getException()

  Description copied from interface: `HttpAsyncResponseConsumer`
  Returns an exception in case of an abnormal termination. This method returns `null` if the response processing is still ongoing or if it completed successfully.

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

### getResult

    public T getResult()

  Description copied from interface: `HttpAsyncResponseConsumer`
  Returns a result of the response processing, when available. This method returns `null` if the response processing is still ongoing.

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

### isDone

    public boolean isDone()

  Description copied from interface: `HttpAsyncResponseConsumer`
  Determines whether or not the response processing completed. If the response processing terminated normally `HttpAsyncResponseConsumer.getResult()` can be used to obtain the result. If the response processing terminated abnormally `HttpAsyncResponseConsumer.getException()` can be used to obtain the cause.

  Specified by:
    `isDone` in interface `HttpAsyncResponseConsumer<T>`

Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.