org.apache.hc.core5.http.nio.support

## Class BasicResponseProducer

- java.lang.Object
- - org.apache.hc.core5.http.nio.support.BasicResponseProducer

- All Implemented Interfaces:
    AsyncDataProducer, AsyncResponseProducer, ResourceHolder

      public class BasicResponseProducer
      extends Object
      implements AsyncResponseProducer

  Basic implementation of `AsyncResponseProducer` that produces one fixed response and relies on a `AsyncEntityProducer` to generate response entity stream.
  Since:
    5.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BasicResponseProducer(AsyncEntityProducer dataProducer)`
    `BasicResponseProducer(HttpResponse response)`
    `BasicResponseProducer(HttpResponse response, AsyncEntityProducer dataProducer)`
    `BasicResponseProducer(HttpResponse response, String message)`
    `BasicResponseProducer(HttpResponse response, String message, ContentType contentType)`
    `BasicResponseProducer(int code, AsyncEntityProducer dataProducer)`
    `BasicResponseProducer(int code, String message)`
    `BasicResponseProducer(int code, String message, ContentType contentType)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `available()` Returns the number of bytes immediately available for output.
    `void` | `failed(Exception cause)` Triggered to signal a failure in data generation.
    `void` | `produce(DataStreamChannel channel)` Triggered to signal the ability of the underlying data channel to accept more data.
    `void` | `releaseResources()`
    `void` | `sendResponse(ResponseChannel responseChannel, HttpContext httpContext)` Triggered to signal the ability of the underlying response channel to accept response messages.

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

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

- - ### Constructor Detail

    - #### BasicResponseProducer

          public BasicResponseProducer(HttpResponse response,
                                       AsyncEntityProducer dataProducer)

    - #### BasicResponseProducer

          public BasicResponseProducer(HttpResponse response)

    - #### BasicResponseProducer

          public BasicResponseProducer(int code,
                                       AsyncEntityProducer dataProducer)

    - #### BasicResponseProducer

          public BasicResponseProducer(HttpResponse response,
                                       String message,
                                       ContentType contentType)

    - #### BasicResponseProducer

          public BasicResponseProducer(HttpResponse response,
                                       String message)

    - #### BasicResponseProducer

          public BasicResponseProducer(int code,
                                       String message,
                                       ContentType contentType)

    - #### BasicResponseProducer

          public BasicResponseProducer(int code,
                                       String message)

    - #### BasicResponseProducer

          public BasicResponseProducer(AsyncEntityProducer dataProducer)

  - ### Method Detail

    - #### sendResponse

          public void sendResponse(ResponseChannel responseChannel,
                                   HttpContext httpContext)
                            throws HttpException,
                                   IOException

      Description copied from interface: `AsyncResponseProducer`
      Triggered to signal the ability of the underlying response channel to accept response messages. The data producer can choose to send response messages immediately inside the call or asynchronously at some later point.
      Specified by:
        `sendResponse` in interface `AsyncResponseProducer`
      Parameters:
        `responseChannel` - the response channel capable to accepting response messages.
        `httpContext` - the actual execution context.
      Throws:
        `HttpException` - in case of an HTTP protocol violation.
        `IOException` - in case of an I/O error.

    - #### available

          public int available()

      Description copied from interface: `AsyncDataProducer`
      Returns the number of bytes immediately available for output. This method can be used as a hint to control output events of the underlying I/O session.

      Please note this method should return zero if the data producer is unable to produce any more data, in which case `AsyncDataProducer.produce(DataStreamChannel)` method will not get triggered. The producer can resume writing out data asynchronously once more data becomes available or request output readiness events with `DataStreamChannel.requestOutput()`.

      Specified by:
        `available` in interface `AsyncDataProducer`
      Returns:
        the number of bytes immediately available for output
      See Also:
        `AsyncDataProducer.produce(DataStreamChannel)`, `DataStreamChannel.requestOutput()`

    - #### produce

          public void produce(DataStreamChannel channel)
                       throws IOException

      Description copied from interface: `AsyncDataProducer`
      Triggered to signal the ability of the underlying data channel to accept more data. The data producer can choose to write data immediately inside the call or asynchronously at some later point.

      Please note this method gets triggered only if `AsyncDataProducer.available()` returns a positive value.

      Specified by:
        `produce` in interface `AsyncDataProducer`
      Parameters:
        `channel` - the data channel capable of accepting more data.
      Throws:
        `IOException` - in case of an I/O error.
      See Also:
        `AsyncDataProducer.available()`

    - #### failed

          public void failed(Exception cause)

      Description copied from interface: `AsyncResponseProducer`
      Triggered to signal a failure in data generation.
      Specified by:
        `failed` in interface `AsyncResponseProducer`
      Parameters:
        `cause` - the cause of the failure.

    - #### releaseResources

          public void releaseResources()

      Specified by:
        `releaseResources` in interface `ResourceHolder`

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