- All Implemented Interfaces:
Closeable
,AutoCloseable
,Releasable
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionChunkedZipResponse
(String filename, RestChannel restChannel, Releasable onCompletion) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close thisChunkedZipResponse
.newEntryListener
(String entryName, Releasable releasable) Create a listener which, when completed, will write the resultChunkedRestResponseBodyPart
, and any following parts, as an entry in the response stream with the given name.
-
Field Details
-
ZIP_CONTENT_TYPE
- See Also:
-
-
Constructor Details
-
ChunkedZipResponse
- Parameters:
filename
- The name of the zip file, which appears in theContent-Disposition
HTTP header of the response, and also is used as a directory prefix for all entries.restChannel
- TheRestChannel
on which to send the response.onCompletion
- A resource which is released when the transmission is complete.
-
-
Method Details
-
close
public void close()Close thisChunkedZipResponse
. Once closed, when there are no more pending listeners the zip file footer is sent.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceReleasable
-
newEntryListener
public ActionListener<ChunkedRestResponseBodyPart> newEntryListener(String entryName, Releasable releasable) Create a listener which, when completed, will write the resultChunkedRestResponseBodyPart
, and any following parts, as an entry in the response stream with the given name. If the listener is completed successfully withnull
, 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.
- the sequence of
-