Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
TransportChannel#sendResponse
refcount-neutral (#104044)
Refcount-neutral methods are much easier on the reader because they mean we can make obvious pairings between `incRef()` and `decRef()` calls. This commit removes the implicit `decRef()` invocation from `TransportChannel#sendResponse` to make it refcount-neutral.
- Loading branch information
1 parent
48ff111
commit 72e0c1f
Showing
14 changed files
with
152 additions
and
77 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
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
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
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
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
47 changes: 47 additions & 0 deletions
47
test/framework/src/main/java/org/elasticsearch/core/ReleasableRef.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,47 @@ | ||
/* | ||
* 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.core; | ||
|
||
import org.elasticsearch.transport.LeakTracker; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Adapter to use a {@link RefCounted} in a try-with-resources block. | ||
*/ | ||
public final class ReleasableRef<T extends RefCounted> implements Releasable { | ||
|
||
private final Releasable closeResource; | ||
private final T resource; | ||
|
||
private ReleasableRef(T resource) { | ||
this.resource = Objects.requireNonNull(resource); | ||
this.closeResource = LeakTracker.wrap(Releasables.assertOnce(resource::decRef)); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
closeResource.close(); | ||
} | ||
|
||
public static <T extends RefCounted> ReleasableRef<T> of(T resource) { | ||
return new ReleasableRef<>(resource); | ||
} | ||
|
||
public T get() { | ||
assert resource.hasReferences() : resource + " is closed"; | ||
return resource; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ReleasableRef[" + resource + ']'; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.