Class StreamingXContentResponse

java.lang.Object
org.elasticsearch.rest.StreamingXContentResponse
All Implemented Interfaces:
Closeable, AutoCloseable, Releasable

public final class StreamingXContentResponse extends Object implements Releasable
A REST response with an XContent body to which the caller can write fragments of content in an asynchronous and streaming fashion.

Callers submit individual fragments of content using writeFragment(org.elasticsearch.common.xcontent.ChunkedToXContent, org.elasticsearch.core.Releasable). Internally, the output entries are held in a queue. If the queue becomes empty then the response transmission is paused until the next entry becomes available.

The internal queue is unbounded. It is the caller's responsibility to ensure that the response does not consume an excess of resources while it's being sent.

The caller must eventually call close() to finish the transmission of the response.

  • Constructor Details

  • Method Details

    • close

      public void close()
      Close this StreamingXContentResponse, indicating that there will be no more fragments to send.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • writeFragment

      public void writeFragment(ChunkedToXContent fragment, Releasable releasable)
      Enqueue the given fragment for transmission.
      Parameters:
      fragment - The fragment to send.
      releasable - A resource which is released when the fragment has been completely processed, i.e. when
      • it has been fully sent, or
      • the overall response was cancelled before completion and all resources related to the partial transmission of this fragment have been released.