forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RestChunkedToXContentListener version that releases transport res…
…ponses (elastic#102607) This is needed as part of elastic#102030, we need to be able to release search/multi-search and maybe other transport messages after they've been serialized as REST responses.
- Loading branch information
1 parent
441b644
commit f896249
Showing
4 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
.../src/main/java/org/elasticsearch/rest/action/RestRefCountedChunkedToXContentListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.rest.action; | ||
|
||
import org.elasticsearch.common.xcontent.ChunkedToXContent; | ||
import org.elasticsearch.core.RefCounted; | ||
import org.elasticsearch.core.Releasable; | ||
import org.elasticsearch.core.Releasables; | ||
import org.elasticsearch.rest.RestChannel; | ||
|
||
/** | ||
* Same as {@link RestChunkedToXContentListener} but decrements the ref count on the response it receives by one after serialization of the | ||
* response. | ||
*/ | ||
public class RestRefCountedChunkedToXContentListener<Response extends ChunkedToXContent & RefCounted> extends RestChunkedToXContentListener< | ||
Response> { | ||
public RestRefCountedChunkedToXContentListener(RestChannel channel) { | ||
super(channel); | ||
} | ||
|
||
@Override | ||
protected Releasable releasableFromResponse(Response response) { | ||
response.mustIncRef(); | ||
return Releasables.assertOnce(response::decRef); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters