Skip to content

Apache Lucene open-source search software

LUCENE-5810: NRTCachingDirectory now implements FilterDirectory

Simon Willnauer130a9ea87dd7
diff --git a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
index 9388ad7d53a..9cda79a7840 100644
--- a/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
@@ -63,11 +63,10 @@ import org.apache.lucene.util.IOUtils;
* @lucene.experimental
*/
-public class NRTCachingDirectory extends Directory {
+public class NRTCachingDirectory extends FilterDirectory {
private final RAMDirectory cache = new RAMDirectory();
- private final Directory delegate;
private final long maxMergeSizeBytes;
private final long maxCachedBytes;
@@ -80,43 +79,39 @@ public class NRTCachingDirectory extends Directory {
* maxMergeSizeMB, and 2) the total cached bytes is <=
* maxCachedMB */
public NRTCachingDirectory(Directory delegate, double maxMergeSizeMB, double maxCachedMB) {
- this.delegate = delegate;
+ super(delegate);
maxMergeSizeBytes = (long) (maxMergeSizeMB*1024*1024);
maxCachedBytes = (long) (maxCachedMB*1024*1024);
}
- public Directory getDelegate() {
- return delegate;
- }
-
@Override
public LockFactory getLockFactory() {
- return delegate.getLockFactory();
+ return in.getLockFactory();
}
@Override
public void setLockFactory(LockFactory lf) throws IOException {
- delegate.setLockFactory(lf);
+ in.setLockFactory(lf);
}
@Override
public String getLockID() {
- return delegate.getLockID();
+ return in.getLockID();
}
@Override
public Lock makeLock(String name) {
- return delegate.makeLock(name);
+ return in.makeLock(name);
}
@Override
public void clearLock(String name) throws IOException {
- delegate.clearLock(name);
+ in.clearLock(name);
}
@Override
public String toString() {
- return "NRTCachingDirectory(" + delegate + "; maxCacheMB=" + (maxCachedBytes/1024/1024.) + " maxMergeSizeMB=" + (maxMergeSizeBytes/1024/1024.) + ")";
+ return "NRTCachingDirectory(" + in + "; maxCacheMB=" + (maxCachedBytes/1024/1024.) + " maxMergeSizeMB=" + (maxMergeSizeBytes/1024/1024.) + ")";
}
@Override
@@ -130,7 +125,7 @@ public class NRTCachingDirectory extends Directory {
// yet been called, because so far everything is a cached write,
// in this case, we don't want to throw a NoSuchDirectoryException
try {
- for(String f : delegate.listAll()) {
+ for(String f : in.listAll()) {
// Cannot do this -- if lucene calls createOutput but
// file already exists then this falsely trips:
//assert !files.contains(f): "file \"" + f + "\" is in both dirs";
@@ -160,7 +155,7 @@ public class NRTCachingDirectory extends Directory {
if (cache.fileNameExists(name)) {
cache.deleteFile(name);
} else {
- delegate.deleteFile(name);
+ in.deleteFile(name);
}
}
@@ -169,7 +164,7 @@ public class NRTCachingDirectory extends Directory {
if (cache.fileNameExists(name)) {
return cache.fileLength(name);
} else {
- return delegate.fileLength(name);
+ return in.fileLength(name);
}
}
@@ -187,7 +182,7 @@ public class NRTCachingDirectory extends Directory {
System.out.println(" to cache");
}
try {
- delegate.deleteFile(name);
+ in.deleteFile(name);
} catch (IOException ioe) {
// This is fine: file may not exist
}
@@ -198,7 +193,7 @@ public class NRTCachingDirectory extends Directory {
} catch (IOException ioe) {
// This is fine: file may not exist
}
- return delegate.createOutput(name, context);
+ return in.createOutput(name, context);
}
}
@@ -210,7 +205,7 @@ public class NRTCachingDirectory extends Directory {
for(String fileName : fileNames) {
unCache(fileName);
}
- delegate.sync(fileNames);
+ in.sync(fileNames);
}
@Override
@@ -224,7 +219,7 @@ public class NRTCachingDirectory extends Directory {
}
return cache.openInput(name, context);
} else {
- return delegate.openInput(name, context);
+ return in.openInput(name, context);
}
}
@@ -241,7 +236,7 @@ public class NRTCachingDirectory extends Directory {
unCache(fileName);
}
cache.close();
- delegate.close();
+ in.close();
}
/** Subclass can override this to customize logic; return
@@ -273,7 +268,7 @@ public class NRTCachingDirectory extends Directory {
return;
}
final IOContext context = IOContext.DEFAULT;
- final IndexOutput out = delegate.createOutput(fileName, context);
+ final IndexOutput out = in.createOutput(fileName, context);
IndexInput in = null;
try {
in = cache.openInput(fileName, context);