java.lang.Object
org.elasticsearch.rest.StreamingXContentResponse
- All Implemented Interfaces:
Closeable,AutoCloseable,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 Summary
ConstructorsConstructorDescriptionStreamingXContentResponse(RestChannel restChannel, ToXContent.Params params, Releasable onCompletion) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close thisStreamingXContentResponse, indicating that there will be no more fragments to send.voidwriteFragment(ChunkedToXContent fragment, Releasable releasable) Enqueue the given fragment for transmission.
-
Constructor Details
-
StreamingXContentResponse
public StreamingXContentResponse(RestChannel restChannel, ToXContent.Params params, Releasable onCompletion) throws IOException - Parameters:
restChannel- TheRestChannelon which to send the response.params- TheToXContent.Paramsto control the serialization.onCompletion- A resource which is released when the transmission is complete.- Throws:
IOException
-
-
Method Details
-
close
public void close()Close thisStreamingXContentResponse, indicating that there will be no more fragments to send.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReleasable
-
writeFragment
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.
-