Change makeInaccessible visibility

This commit is contained in:
Andrea Cavalli 2021-09-23 15:34:56 +02:00
parent d4c977047c
commit 6c849fae78
8 changed files with 27 additions and 138 deletions

View File

@ -18,7 +18,7 @@ public final class SearchResult<T, U> extends ResourceSupport<SearchResult<T, U>
public SearchResult(Flux<SearchResultItem<T, U>> results, TotalHitsCount totalHitsCount,
Drop<SearchResult<T, U>> drop) {
super(new CloseOnDrop<>(drop));
super(drop);
this.results = results;
this.totalHitsCount = totalHitsCount;
}
@ -49,30 +49,11 @@ public final class SearchResult<T, U> extends ResourceSupport<SearchResult<T, U>
protected Owned<SearchResult<T, U>> prepareSend() {
var results = this.results;
var totalHitsCount = this.totalHitsCount;
makeInaccessible();
return drop -> new SearchResult<>(results, totalHitsCount, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.results = null;
this.totalHitsCount = null;
}
private static class CloseOnDrop<V, W> implements Drop<SearchResult<V, W>> {
private final Drop<SearchResult<V, W>> delegate;
public CloseOnDrop(Drop<SearchResult<V, W>> drop) {
this.delegate = drop;
}
@Override
public void drop(SearchResult<V, W> obj) {
try {
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
}
}
}

View File

@ -23,7 +23,7 @@ public final class SearchResultKeys<T> extends ResourceSupport<SearchResultKeys<
public SearchResultKeys(Flux<SearchResultKey<T>> results, TotalHitsCount totalHitsCount,
Drop<SearchResultKeys<T>> drop) {
super(new SearchResultKeys.CloseOnDrop<>(drop));
super(drop);
this.results = results;
this.totalHitsCount = totalHitsCount;
}
@ -65,27 +65,9 @@ public final class SearchResultKeys<T> extends ResourceSupport<SearchResultKeys<
return drop -> new SearchResultKeys<>(results, totalHitsCount, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.results = null;
this.totalHitsCount = null;
}
private static class CloseOnDrop<U> implements Drop<SearchResultKeys<U>> {
private final Drop<SearchResultKeys<U>> delegate;
public CloseOnDrop(Drop<SearchResultKeys<U>> drop) {
this.delegate = drop;
}
@Override
public void drop(SearchResultKeys<U> obj) {
try {
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
}
}
}

View File

@ -193,11 +193,10 @@ public class LLRange extends ResourceSupport<LLRange, LLRange> {
minSend = this.min != null ? this.min.send() : null;
maxSend = this.max != null ? this.max.send() : null;
singleSend = this.single != null ? this.single.send() : null;
this.makeInaccessible();
return drop -> new LLRange(minSend, maxSend, singleSend, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.min = null;
this.max = null;
this.single = null;
@ -216,7 +215,6 @@ public class LLRange extends ResourceSupport<LLRange, LLRange> {
if (obj.min != null) obj.min.close();
if (obj.max != null) obj.max.close();
if (obj.single != null) obj.single.close();
obj.makeInaccessible();
delegate.drop(obj);
}
}

View File

@ -17,7 +17,7 @@ public final class LLSearchResultShard extends ResourceSupport<LLSearchResultSha
private TotalHitsCount totalHitsCount;
public LLSearchResultShard(Flux<LLKeyScore> results, TotalHitsCount totalHitsCount, Drop<LLSearchResultShard> drop) {
super(new LLSearchResultShard.CloseOnDrop(drop));
super(drop);
this.results = results;
this.totalHitsCount = totalHitsCount;
}
@ -65,30 +65,11 @@ public final class LLSearchResultShard extends ResourceSupport<LLSearchResultSha
protected Owned<LLSearchResultShard> prepareSend() {
var results = this.results;
var totalHitsCount = this.totalHitsCount;
makeInaccessible();
return drop -> new LLSearchResultShard(results, totalHitsCount, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.results = null;
this.totalHitsCount = null;
}
private static class CloseOnDrop implements Drop<LLSearchResultShard> {
private final Drop<LLSearchResultShard> delegate;
public CloseOnDrop(Drop<LLSearchResultShard> drop) {
this.delegate = drop;
}
@Override
public void drop(LLSearchResultShard obj) {
try {
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
}
}
}

View File

@ -16,7 +16,7 @@ public class LLIndexSearcher extends ResourceSupport<LLIndexSearcher, LLIndexSea
private IndexSearcher indexSearcher;
public LLIndexSearcher(IndexSearcher indexSearcher, Drop<LLIndexSearcher> drop) {
super(new LLIndexSearcher.CloseOnDrop(drop));
super(drop);
this.indexSearcher = indexSearcher;
}
@ -42,29 +42,10 @@ public class LLIndexSearcher extends ResourceSupport<LLIndexSearcher, LLIndexSea
@Override
protected Owned<LLIndexSearcher> prepareSend() {
var indexSearcher = this.indexSearcher;
makeInaccessible();
return drop -> new LLIndexSearcher(indexSearcher, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.indexSearcher = null;
}
private static class CloseOnDrop implements Drop<LLIndexSearcher> {
private final Drop<LLIndexSearcher> delegate;
public CloseOnDrop(Drop<LLIndexSearcher> drop) {
this.delegate = drop;
}
@Override
public void drop(LLIndexSearcher obj) {
try {
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
}
}
}

View File

@ -80,11 +80,10 @@ public interface LLIndexSearchers extends Resource<LLIndexSearchers> {
@Override
protected Owned<UnshardedIndexSearchers> prepareSend() {
Send<LLIndexSearcher> indexSearcher = this.indexSearcher.send();
this.makeInaccessible();
return drop -> new UnshardedIndexSearchers(indexSearcher, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.indexSearcher = null;
}
@ -98,12 +97,8 @@ public interface LLIndexSearchers extends Resource<LLIndexSearchers> {
@Override
public void drop(UnshardedIndexSearchers obj) {
try {
if (obj.indexSearcher != null) obj.indexSearcher.close();
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
if (obj.indexSearcher != null) obj.indexSearcher.close();
delegate.drop(obj);
}
}
}
@ -176,11 +171,10 @@ public interface LLIndexSearchers extends Resource<LLIndexSearchers> {
for (LLIndexSearcher indexSearcher : this.indexSearchers) {
indexSearchers.add(indexSearcher.send());
}
this.makeInaccessible();
return drop -> new ShardedIndexSearchers(indexSearchers, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.indexSearchers = null;
this.indexSearchersVals = null;
}
@ -196,20 +190,16 @@ public interface LLIndexSearchers extends Resource<LLIndexSearchers> {
@Override
public void drop(ShardedIndexSearchers obj) {
try {
assert !dropped;
if (obj.indexSearchers != null) {
for (LLIndexSearcher indexSearcher : obj.indexSearchers) {
if (indexSearcher.isAccessible()) {
indexSearcher.close();
}
assert !dropped;
if (obj.indexSearchers != null) {
for (LLIndexSearcher indexSearcher : obj.indexSearchers) {
if (indexSearcher.isAccessible()) {
indexSearcher.close();
}
}
dropped = true;
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
dropped = true;
delegate.drop(obj);
}
}
}

View File

@ -22,7 +22,7 @@ public final class LuceneSearchResult extends ResourceSupport<LuceneSearchResult
private Flux<LLKeyScore> results;
public LuceneSearchResult(TotalHitsCount totalHitsCount, Flux<LLKeyScore> results, Drop<LuceneSearchResult> drop) {
super(new LuceneSearchResult.CloseOnDrop(drop));
super(drop);
this.totalHitsCount = totalHitsCount;
this.results = results;
}
@ -70,31 +70,12 @@ public final class LuceneSearchResult extends ResourceSupport<LuceneSearchResult
protected Owned<LuceneSearchResult> prepareSend() {
var totalHitsCount = this.totalHitsCount;
var results = this.results;
makeInaccessible();
return drop -> new LuceneSearchResult(totalHitsCount, results, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.totalHitsCount = null;
this.results = null;
}
private static class CloseOnDrop implements Drop<LuceneSearchResult> {
private final Drop<LuceneSearchResult> delegate;
public CloseOnDrop(Drop<LuceneSearchResult> drop) {
this.delegate = drop;
}
@Override
public void drop(LuceneSearchResult obj) {
try {
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
}
}
}

View File

@ -41,11 +41,10 @@ public class NullableBuffer extends ResourceSupport<NullableBuffer, NullableBuff
@Override
protected Owned<NullableBuffer> prepareSend() {
var buffer = this.buffer == null ? null : this.buffer.send();
makeInaccessible();
return drop -> new NullableBuffer(buffer, drop);
}
private void makeInaccessible() {
protected void makeInaccessible() {
this.buffer = null;
}
@ -59,16 +58,12 @@ public class NullableBuffer extends ResourceSupport<NullableBuffer, NullableBuff
@Override
public void drop(NullableBuffer obj) {
try {
if (obj.buffer != null) {
if (obj.buffer.isAccessible()) {
obj.buffer.close();
}
if (obj.buffer != null) {
if (obj.buffer.isAccessible()) {
obj.buffer.close();
}
delegate.drop(obj);
} finally {
obj.makeInaccessible();
}
delegate.drop(obj);
}
}
}