org.apache.http.nio.protocol

## Class BasicAsyncClientExchangeHandler<T>

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

- Type Parameters:
    `T` - the result type of request execution.
  All Implemented Interfaces:
    Closeable, AutoCloseable, Cancellable, HttpAsyncClientExchangeHandler

      public class BasicAsyncClientExchangeHandler<T>
      extends Object
      implements HttpAsyncClientExchangeHandler

  Basic implementation of `HttpAsyncClientExchangeHandler` that executes a single HTTP request / response exchange.
  Since:
    4.3

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicAsyncClientExchangeHandler(HttpAsyncRequestProducer requestProducer, HttpAsyncResponseConsumer<T> responseConsumer, FutureCallback<T> callback, HttpContext localContext, NHttpClientConnection conn, HttpProcessor httppocessor, ConnectionReuseStrategy connReuseStrategy)` Creates new instance of BasicAsyncRequestExecutionHandler.
    `BasicAsyncClientExchangeHandler(HttpAsyncRequestProducer requestProducer, HttpAsyncResponseConsumer<T> responseConsumer, HttpContext localContext, NHttpClientConnection conn, HttpProcessor httppocessor)` Creates new instance of BasicAsyncRequestExecutionHandler.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `cancel()`
    `void` | `close()`
    `void` | `consumeContent(ContentDecoder decoder, IOControl ioctrl)` Invoked to process a chunk of content from the `ContentDecoder`.
    `void` | `failed(Exception ex)` Invoked to signal that the response processing terminated abnormally.
    `HttpRequest` | `generateRequest()` Invoked to generate a HTTP request message head.
    `Future<T>` | `getFuture()`
    `void` | `inputTerminated()` Invoked to signal that the connection has been terminated prematurely by the opposite end.
    `boolean` | `isDone()` Determines whether or not the response processing completed.
    `void` | `produceContent(ContentEncoder encoder, IOControl ioctrl)` Invoked to write out a chunk of content to the `ContentEncoder`.
    `void` | `requestCompleted()` Invoked to signal that the request has been fully written out.
    `void` | `responseCompleted()` Invoked to signal that the response has been fully processed.
    `void` | `responseReceived(HttpResponse response)` Invoked when a HTTP response message is received.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BasicAsyncClientExchangeHandler

          public BasicAsyncClientExchangeHandler(HttpAsyncRequestProducer requestProducer,
                                         HttpAsyncResponseConsumer<T> responseConsumer,
                                         FutureCallback<T> callback,
                                         HttpContext localContext,
                                         NHttpClientConnection conn,
                                         HttpProcessor httppocessor,
                                         ConnectionReuseStrategy connReuseStrategy)

      Creates new instance of BasicAsyncRequestExecutionHandler.
      Parameters:
        `requestProducer` - the request producer.
        `responseConsumer` - the response consumer.
        `callback` - the future callback invoked when the operation is completed.
        `localContext` - the local execution context.
        `conn` - the actual connection.
        `httppocessor` - the HTTP protocol processor.
        `connReuseStrategy` - the connection re-use strategy.

    - #### BasicAsyncClientExchangeHandler

          public BasicAsyncClientExchangeHandler(HttpAsyncRequestProducer requestProducer,
                                         HttpAsyncResponseConsumer<T> responseConsumer,
                                         HttpContext localContext,
                                         NHttpClientConnection conn,
                                         HttpProcessor httppocessor)

      Creates new instance of BasicAsyncRequestExecutionHandler.
      Parameters:
        `requestProducer` - the request producer.
        `responseConsumer` - the response consumer.
        `localContext` - the local execution context.
        `conn` - the actual connection.
        `httppocessor` - the HTTP protocol processor.

  - ### Method Detail

    - #### getFuture

          public Future<T> getFuture()

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Throws:
        `IOException`

    - #### generateRequest

          public HttpRequest generateRequest()
                                      throws IOException,
                                             HttpException

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to generate a HTTP request message head. The message is expected to implement the `HttpEntityEnclosingRequest` interface if it is to enclose a content entity. The `HttpAsyncClientExchangeHandler.produceContent(ContentEncoder, IOControl)` method will not be invoked if `HttpEntityEnclosingRequest.getEntity()` returns `null`.
      Specified by:
        `generateRequest` in interface `HttpAsyncClientExchangeHandler`
      Returns:
        HTTP request message.
      Throws:
        `IOException` - in case of an I/O error
        `HttpException` - in case of HTTP protocol violation

    - #### produceContent

          public void produceContent(ContentEncoder encoder,
                            IOControl ioctrl)
                              throws IOException

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to write out a chunk of content to the `ContentEncoder`. The `IOControl` interface can be used to suspend output event notifications if the producer is temporarily unable to produce more content.

      When all content is finished, the producer MUST call `ContentEncoder.complete()`. Failure to do so may cause the entity to be incorrectly delimited.

      Please note that the `ContentEncoder` object is not thread-safe and should only be used within the context of this method call. The `IOControl` object can be shared and used on other thread to resume output event notifications when more content is made available.
      Specified by:
        `produceContent` in interface `HttpAsyncClientExchangeHandler`
      Parameters:
        `encoder` - content encoder.
        `ioctrl` - I/O control of the underlying connection.
      Throws:
        `IOException` - in case of an I/O error

    - #### requestCompleted

          public void requestCompleted()

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to signal that the request has been fully written out.
      Specified by:
        `requestCompleted` in interface `HttpAsyncClientExchangeHandler`

    - #### responseReceived

          public void responseReceived(HttpResponse response)
                                throws IOException,
                                       HttpException

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked when a HTTP response message is received. Please note that the `HttpAsyncClientExchangeHandler.consumeContent(ContentDecoder, IOControl)` method will be invoked only if the response messages has a content entity enclosed.
      Specified by:
        `responseReceived` in interface `HttpAsyncClientExchangeHandler`
      Parameters:
        `response` - HTTP response message.
      Throws:
        `IOException` - in case of an I/O error
        `HttpException` - in case of HTTP protocol violation

    - #### consumeContent

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

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to process a chunk of content from the `ContentDecoder`. The `IOControl` interface can be used to suspend input event notifications if the consumer is temporarily unable to process content.

      The consumer can use the `ContentDecoder.isCompleted()` method to find out whether or not the message content has been fully consumed.

      Please note that the `ContentDecoder` object is not thread-safe and should only be used within the context of this method call. The `IOControl` object can be shared and used on other thread to resume input event notifications when the consumer is capable of processing more content.
      Specified by:
        `consumeContent` in interface `HttpAsyncClientExchangeHandler`
      Parameters:
        `decoder` - content decoder.
        `ioctrl` - I/O control of the underlying connection.
      Throws:
        `IOException` - in case of an I/O error

    - #### responseCompleted

          public void responseCompleted()
                                 throws IOException

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to signal that the response has been fully processed.
      Specified by:
        `responseCompleted` in interface `HttpAsyncClientExchangeHandler`
      Throws:
        `IOException`

    - #### inputTerminated

          public void inputTerminated()

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to signal that the connection has been terminated prematurely by the opposite end.
      Specified by:
        `inputTerminated` in interface `HttpAsyncClientExchangeHandler`

    - #### failed

          public void failed(Exception ex)

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Invoked to signal that the response processing terminated abnormally.
      Specified by:
        `failed` in interface `HttpAsyncClientExchangeHandler`
      Parameters:
        `ex` - exception

    - #### cancel

          public boolean cancel()

      Specified by:
        `cancel` in interface `Cancellable`

    - #### isDone

          public boolean isDone()

      Description copied from interface: `HttpAsyncClientExchangeHandler`
      Determines whether or not the response processing completed.
      Specified by:
        `isDone` in interface `HttpAsyncClientExchangeHandler`

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