You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2014/07/09 17:17:02 UTC
svn commit: r1609202 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/core/
lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
Author: simonw
Date: Wed Jul 9 15:17:02 2014
New Revision: 1609202
URL: http://svn.apache.org/r1609202
Log:
LUCENE-5810: NRTCachingDirectory now implements FilterDirectory
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java?rev=1609202&r1=1609201&r2=1609202&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java Wed Jul 9 15:17:02 2014
@@ -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
* 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
// 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";
@@ -154,7 +149,7 @@ public class NRTCachingDirectory extends
@Override
public synchronized boolean fileExists(String name) throws IOException {
- return cache.fileExists(name) || delegate.fileExists(name);
+ return cache.fileExists(name) || in.fileExists(name);
}
@Override
@@ -165,7 +160,7 @@ public class NRTCachingDirectory extends
if (cache.fileExists(name)) {
cache.deleteFile(name);
} else {
- delegate.deleteFile(name);
+ in.deleteFile(name);
}
}
@@ -174,7 +169,7 @@ public class NRTCachingDirectory extends
if (cache.fileExists(name)) {
return cache.fileLength(name);
} else {
- return delegate.fileLength(name);
+ return in.fileLength(name);
}
}
@@ -192,7 +187,7 @@ public class NRTCachingDirectory extends
System.out.println(" to cache");
}
try {
- delegate.deleteFile(name);
+ in.deleteFile(name);
} catch (IOException ioe) {
// This is fine: file may not exist
}
@@ -203,7 +198,7 @@ public class NRTCachingDirectory extends
} catch (IOException ioe) {
// This is fine: file may not exist
}
- return delegate.createOutput(name, context);
+ return in.createOutput(name, context);
}
}
@@ -215,7 +210,7 @@ public class NRTCachingDirectory extends
for(String fileName : fileNames) {
unCache(fileName);
}
- delegate.sync(fileNames);
+ in.sync(fileNames);
}
@Override
@@ -229,7 +224,7 @@ public class NRTCachingDirectory extends
}
return cache.openInput(name, context);
} else {
- return delegate.openInput(name, context);
+ return in.openInput(name, context);
}
}
@@ -246,7 +241,7 @@ public class NRTCachingDirectory extends
unCache(fileName);
}
cache.close();
- delegate.close();
+ in.close();
}
/** Subclass can override this to customize logic; return
@@ -278,7 +273,7 @@ public class NRTCachingDirectory extends
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);