Class LoggingChunkedRestResponseBodyPart
- All Implemented Interfaces:
ChunkedRestResponseBodyPart
-
Field Summary
Fields inherited from interface org.elasticsearch.rest.ChunkedRestResponseBodyPart
logger -
Constructor Summary
ConstructorsConstructorDescriptionLoggingChunkedRestResponseBodyPart(ChunkedRestResponseBodyPart inner, OutputStream loggerStream) -
Method Summary
Modifier and TypeMethodDescriptionencodeChunk(int sizeHint, Recycler<org.apache.lucene.util.BytesRef> recycler) Serializes approximately as many bytes of the response as request bysizeHintto aReleasableBytesReferencethat is created from buffers backed by the givenrecycler.voidgetNextPart(ActionListener<ChunkedRestResponseBodyPart> listener) Asynchronously retrieves the next part of the response body.booleanboolean
-
Constructor Details
-
LoggingChunkedRestResponseBodyPart
public LoggingChunkedRestResponseBodyPart(ChunkedRestResponseBodyPart inner, OutputStream loggerStream)
-
-
Method Details
-
isPartComplete
public boolean isPartComplete()- Specified by:
isPartCompletein interfaceChunkedRestResponseBodyPart- Returns:
trueif this body part contains no more chunks and the REST layer should check for a possible continuation by callingChunkedRestResponseBodyPart.isLastPart(), orfalseif the REST layer should request another chunk from this body usingChunkedRestResponseBodyPart.encodeChunk(int, org.elasticsearch.common.recycler.Recycler<org.apache.lucene.util.BytesRef>).
-
isLastPart
public boolean isLastPart()- Specified by:
isLastPartin interfaceChunkedRestResponseBodyPart- Returns:
trueif this is the last chunked body part in the response, orfalseif the REST layer should request further chunked bodies by callingChunkedRestResponseBodyPart.getNextPart(org.elasticsearch.action.ActionListener<org.elasticsearch.rest.ChunkedRestResponseBodyPart>).
-
getNextPart
Description copied from interface:ChunkedRestResponseBodyPartAsynchronously retrieves the next part of the response body. Called if
ChunkedRestResponseBodyPart.isLastPart()returnsfalse.Note that this is called on a transport thread: implementations must take care to dispatch any nontrivial work elsewhere.
Note that the
Taskcorresponding to any invocation ofElasticsearchClient.execute(org.elasticsearch.action.ActionType<Response>, Request)completes as soon as the client action returns its response, so it no longer exists when this method is called and cannot be used to receive cancellation notifications. Instead, if the HTTP channel is closed while sending a response then the REST layer will invokeRestResponse.close(). If the HTTP channel is closed while the REST layer is waiting for a continuation then theRestResponsewill not be closed until the continuation listener is completed. Implementations will typically explicitly create aCancellableTaskto represent the computation and transmission of the entireRestResponse, and will cancel this task if theRestResponseis closed prematurely.- Specified by:
getNextPartin interfaceChunkedRestResponseBodyPart- Parameters:
listener- Listener to complete with the next part of the body. By the point this is called we have already started to send the body of the response, so there's no good ways to handle an exception here. Completing the listener exceptionally will log an error, abort sending the response, and close the HTTP connection.
-
encodeChunk
public ReleasableBytesReference encodeChunk(int sizeHint, Recycler<org.apache.lucene.util.BytesRef> recycler) throws IOException Description copied from interface:ChunkedRestResponseBodyPartSerializes approximately as many bytes of the response as request bysizeHintto aReleasableBytesReferencethat is created from buffers backed by the givenrecycler.- Specified by:
encodeChunkin interfaceChunkedRestResponseBodyPart- Parameters:
sizeHint- how many bytes to approximately serialize for the given chunkrecycler- recycler used to acquire buffers- Returns:
- serialized chunk
- Throws:
IOException- on serialization failure
-
getResponseContentTypeString
- Specified by:
getResponseContentTypeStringin interfaceChunkedRestResponseBodyPart- Returns:
- the response Content-Type header value for this response body
-