SOLR-8995: use lambdas for CoreCloseListener

This commit is contained in:
Noble Paul 2016-09-29 11:33:22 +05:30
parent 5c5c0c93ae
commit e8767daa7b
4 changed files with 9 additions and 24 deletions

View File

@ -18,7 +18,6 @@ package org.apache.lucene.index;
import java.io.IOException;
import org.apache.lucene.index.IndexReader.ReaderClosedListener;
import org.apache.lucene.search.Sort;
import org.apache.lucene.util.Bits;
@ -77,12 +76,12 @@ public abstract class LeafReader extends IndexReader {
*
* @lucene.experimental
*/
public static interface CoreClosedListener {
public interface CoreClosedListener {
/** Invoked when the shared core of the original {@code
* SegmentReader} has closed. The provided {@code
* ownerCoreCacheKey} will be the same key as the one
* returned by {@link LeafReader#getCoreCacheKey()}. */
public void onClose(Object ownerCoreCacheKey) throws IOException;
void onClose(Object ownerCoreCacheKey) throws IOException;
}
private static class CoreClosedListenerWrapper implements ReaderClosedListener {

View File

@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import org.apache.lucene.index.LeafReader.CoreClosedListener;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.ReaderUtil;
@ -316,12 +315,7 @@ public class LRUQueryCache implements QueryCache, Accountable {
ramBytesUsed += HASHTABLE_RAM_BYTES_PER_ENTRY;
assert previous == null;
// we just created a new leaf cache, need to register a close listener
context.reader().addCoreClosedListener(new CoreClosedListener() {
@Override
public void onClose(Object ownerCoreCacheKey) {
clearCoreCacheKey(ownerCoreCacheKey);
}
});
context.reader().addCoreClosedListener(this::clearCoreCacheKey);
}
leafCache.putIfAbsent(query, set);
evictIfNecessary();

View File

@ -47,13 +47,10 @@ public class AssertingLeafReader extends FilterLeafReader {
assert in.numDeletedDocs() + in.numDocs() == in.maxDoc();
assert !in.hasDeletions() || in.numDeletedDocs() > 0 && in.numDocs() < in.maxDoc();
addCoreClosedListener(new CoreClosedListener() {
@Override
public void onClose(Object ownerCoreCacheKey) throws IOException {
final Object expectedKey = getCoreCacheKey();
assert expectedKey == ownerCoreCacheKey
: "Core closed listener called on a different key " + expectedKey + " <> " + ownerCoreCacheKey;
}
addCoreClosedListener(ownerCoreCacheKey -> {
final Object expectedKey = getCoreCacheKey();
assert expectedKey == ownerCoreCacheKey
: "Core closed listener called on a different key " + expectedKey + " <> " + ownerCoreCacheKey;
});
}

View File

@ -33,9 +33,9 @@ import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.index.PointValues.IntersectVisitor;
import org.apache.lucene.index.PointValues.Relation;
import org.apache.lucene.index.PointValues;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.SegmentReader;
import org.apache.lucene.index.SortedDocValues;
@ -112,12 +112,7 @@ class FieldCacheImpl implements FieldCache {
}
// per-segment fieldcaches don't purge until the shared core closes.
final SegmentReader.CoreClosedListener purgeCore = new SegmentReader.CoreClosedListener() {
@Override
public void onClose(Object ownerCoreCacheKey) {
FieldCacheImpl.this.purgeByCacheKey(ownerCoreCacheKey);
}
};
final SegmentReader.CoreClosedListener purgeCore = ownerCoreCacheKey -> FieldCacheImpl.this.purgeByCacheKey(ownerCoreCacheKey);
private void initReader(LeafReader reader) {
reader.addCoreClosedListener(purgeCore);