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 bysizeHint
to aReleasableBytesReference
that is created from buffers backed by the givenrecycler
.void
getNextPart
(ActionListener<ChunkedRestResponseBodyPart> listener) Asynchronously retrieves the next part of the response body.boolean
boolean
-
Constructor Details
-
LoggingChunkedRestResponseBodyPart
public LoggingChunkedRestResponseBodyPart(ChunkedRestResponseBodyPart inner, OutputStream loggerStream)
-
-
Method Details
-
isPartComplete
public boolean isPartComplete()- Specified by:
isPartComplete
in interfaceChunkedRestResponseBodyPart
- Returns:
true
if this body part contains no more chunks and the REST layer should check for a possible continuation by callingChunkedRestResponseBodyPart.isLastPart()
, orfalse
if 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:
isLastPart
in interfaceChunkedRestResponseBodyPart
- Returns:
true
if this is the last chunked body part in the response, orfalse
if the REST layer should request further chunked bodies by callingChunkedRestResponseBodyPart.getNextPart(org.elasticsearch.action.ActionListener<org.elasticsearch.rest.ChunkedRestResponseBodyPart>)
.
-
getNextPart
Description copied from interface:ChunkedRestResponseBodyPart
Asynchronously 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
Task
corresponding 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 theRestResponse
will not be closed until the continuation listener is completed. Implementations will typically explicitly create aCancellableTask
to represent the computation and transmission of the entireRestResponse
, and will cancel this task if theRestResponse
is closed prematurely.- Specified by:
getNextPart
in 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:ChunkedRestResponseBodyPart
Serializes approximately as many bytes of the response as request bysizeHint
to aReleasableBytesReference
that is created from buffers backed by the givenrecycler
.- Specified by:
encodeChunk
in 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:
getResponseContentTypeString
in interfaceChunkedRestResponseBodyPart
- Returns:
- the response Content-Type header value for this response body
-