## org.apache.http.nio.protocol
Class BasicAsyncRequestProducer

    java.lang.Object
      org.apache.http.nio.protocol.BasicAsyncRequestProducer

All Implemented Interfaces:
  Closeable, HttpAsyncRequestProducer

    @ThreadSafe
    public class BasicAsyncRequestProducer

extends Object
implements HttpAsyncRequestProducer

Basic implementation of `HttpAsyncRequestProducer`. The producer can make use of the `HttpAsyncContentProducer` interface to efficiently stream out message content to the underlying non-blocking HTTP connection, if it is implemented by the enclosed `HttpEntity`.

Since:
  4.2
See Also:
  `HttpAsyncContentProducer`

Constructor Summary
`protected` `BasicAsyncRequestProducer(HttpHost target, HttpEntityEnclosingRequest request, HttpAsyncContentProducer producer)` Creates a producer that can be used to transmit the given request message.
`` `BasicAsyncRequestProducer(HttpHost target, HttpRequest request)` Creates a producer that can be used to transmit the given request message.

Method Summary
`void` `close()`
`void` `failed(Exception ex)` Invoked to signal that the response processing terminated abnormally.
`HttpRequest` `generateRequest()` Invoked to generate a HTTP request message head.
`HttpHost` `getTarget()` Invoked to obtain the request target host.
`boolean` `isRepeatable()` Determines whether or not this producer is capable of producing HTTP request messages more than once.
`void` `produceContent(ContentEncoder encoder, IOControl ioctrl)` Invoked to write out a chunk of content to the `ContentEncoder`.
`void` `requestCompleted(HttpContext context)` Invoked to signal that the request has been fully written out.
`void` `resetRequest()` Invoked to reset the producer to its initial state.

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

Constructor Detail

### BasicAsyncRequestProducer

    protected BasicAsyncRequestProducer(HttpHost target,
                                        HttpEntityEnclosingRequest request,
                                        HttpAsyncContentProducer producer)

  Creates a producer that can be used to transmit the given request message. The given content producer will be used to stream out message content. Please note that the request message is expected to enclose an `HttpEntity` whose properties are consistent with the behavior of the content producer.

  Parameters:
    `target` - target host.
    `request` - request message.
    `producer` - request content producer.

### BasicAsyncRequestProducer

    public BasicAsyncRequestProducer(HttpHost target,
                                     HttpRequest request)

  Creates a producer that can be used to transmit the given request message. If the request message encloses an `HttpEntity` it is also expected to implement `HttpAsyncContentProducer`.

  Parameters:
    `target` - target host.
    `request` - request message.

Method Detail

### generateRequest

    public HttpRequest generateRequest()

  Description copied from interface: `HttpAsyncRequestProducer`
  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 `HttpAsyncRequestProducer.produceContent(ContentEncoder, IOControl)` method will not be invoked if `HttpEntityEnclosingRequest.getEntity()` returns `null`.

  Specified by:
    `generateRequest` in interface `HttpAsyncRequestProducer`
  Returns:
    HTTP request message.

### getTarget

    public HttpHost getTarget()

  Description copied from interface: `HttpAsyncRequestProducer`
  Invoked to obtain the request target host.

  Specified by:
    `getTarget` in interface `HttpAsyncRequestProducer`

### produceContent

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

  Description copied from interface: `HttpAsyncRequestProducer`
  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 `HttpAsyncRequestProducer`
  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(HttpContext context)

  Description copied from interface: `HttpAsyncRequestProducer`
  Invoked to signal that the request has been fully written out.

  Specified by:
    `requestCompleted` in interface `HttpAsyncRequestProducer`
  Parameters:
    `context` - HTTP context

### failed

    public void failed(Exception ex)

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

  Specified by:
    `failed` in interface `HttpAsyncRequestProducer`
  Parameters:
    `ex` - exception

### isRepeatable

    public boolean isRepeatable()

  Description copied from interface: `HttpAsyncRequestProducer`
  Determines whether or not this producer is capable of producing HTTP request messages more than once.

  Specified by:
    `isRepeatable` in interface `HttpAsyncRequestProducer`

### resetRequest

    public void resetRequest()
                      throws IOException

  Description copied from interface: `HttpAsyncRequestProducer`
  Invoked to reset the producer to its initial state. Repeatable request producers are expected to release currently allocated resources that are no longer needed or re-acquire resources needed to repeat the process.

  Specified by:
    `resetRequest` in interface `HttpAsyncRequestProducer`
  Throws:
    `IOException` - in case of an I/O error

### close

    public void close()
               throws IOException

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

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