Class ChunkedZipResponse

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

public final class ChunkedZipResponse extends Object implements Releasable
A REST response with Content-type: application/zip to which the caller can write entries in an asynchronous and streaming fashion.

Callers obtain a listener for individual entries using newEntryListener(java.lang.String, org.elasticsearch.core.Releasable) and complete these listeners to submit the corresponding entries for transmission. Internally, the output entries are held in a queue in the order in which the entry listeners are completed. 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.

Note that individual entries can also pause themselves mid-transmission, since listeners returned by newEntryListener(java.lang.String, org.elasticsearch.core.Releasable) accept a pauseable ChunkedRestResponseBodyPart. Zip files do not have any mechanism which supports the multiplexing of outputs, so if the entry at the head of the queue is paused then that will hold up the transmission of all subsequent entries too.

  • Field Details

  • Constructor Details

    • ChunkedZipResponse

      public ChunkedZipResponse(String filename, RestChannel restChannel, Releasable onCompletion)
      Parameters:
      filename - The name of the zip file, which appears in the Content-Disposition HTTP header of the response, and also is used as a directory prefix for all entries.
      restChannel - The RestChannel on which to send the response.
      onCompletion - A resource which is released when the transmission is complete.
  • Method Details

    • close

      public void close()
      Close this ChunkedZipResponse. Once closed, when there are no more pending listeners the zip file footer is sent.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable
    • newEntryListener

      public ActionListener<ChunkedRestResponseBodyPart> newEntryListener(String entryName, Releasable releasable)
      Create a listener which, when completed, will write the result ChunkedRestResponseBodyPart, and any following parts, as an entry in the response stream with the given name. If the listener is completed successfully with null, or exceptionally, then no entry is sent. When all listeners created by this method have been completed, the zip file footer is sent.

      This method may be called as long as this ChunkedZipResponse is not closed, or there is at least one other incomplete entry listener.

      Parameters:
      entryName - The name of the entry in the response zip file.
      releasable - A resource which is released when the entry has been completely processed, i.e. when
      • the sequence of ChunkedRestResponseBodyPart instances have been fully sent, or
      • the listener was completed with null, or an exception, indicating that no entry is to be sent, or
      • the overall response was cancelled before completion and all resources related to the partial transmission of this entry have been released.