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:12:42 UTC

svn commit: r1609200 - /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java

Author: simonw
Date: Wed Jul  9 15:12:42 2014
New Revision: 1609200

URL: http://svn.apache.org/r1609200
Log:
LUCENE-5810: NRTCachingDirectory now implements FilterDirectory

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java?rev=1609200&r1=1609199&r2=1609200&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java Wed Jul  9 15:12:42 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";
@@ -160,7 +155,7 @@ public class NRTCachingDirectory extends
     if (cache.fileNameExists(name)) {
       cache.deleteFile(name);
     } else {
-      delegate.deleteFile(name);
+      in.deleteFile(name);
     }
   }
 
@@ -169,7 +164,7 @@ public class NRTCachingDirectory extends
     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
         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
       } 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
     for(String fileName : fileNames) {
       unCache(fileName);
     }
-    delegate.sync(fileNames);
+    in.sync(fileNames);
   }
 
   @Override
@@ -224,7 +219,7 @@ public class NRTCachingDirectory extends
       }
       return cache.openInput(name, context);
     } else {
-      return delegate.openInput(name, context);
+      return in.openInput(name, context);
     }
   }
   
@@ -241,7 +236,7 @@ public class NRTCachingDirectory extends
       unCache(fileName);
     }
     cache.close();
-    delegate.close();
+    in.close();
   }
 
   /** Subclass can override this to customize logic; return
@@ -273,7 +268,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);



Re: svn commit: r1609200 - /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java

Posted by Simon Willnauer <si...@gmail.com>.
oh yeah - crap... I will fix tomorrow

On Wed, Jul 9, 2014 at 6:01 PM, Alan Woodward <al...@flax.co.uk> wrote:
> Can't we just not override these methods?  They're doing the exact same thing that the superclass does...
>
>>
>>   @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);
>>   }
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: dev-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Re: svn commit: r1609200 - /lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/store/NRTCachingDirectory.java

Posted by Alan Woodward <al...@flax.co.uk>.
Can't we just not override these methods?  They're doing the exact same thing that the superclass does...

> 
>   @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);
>   }
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org