lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject lucene-solr:branch_6x: SOLR-9928 Unwrap Directory consistently whenever it's passed as an argument.
Date Sat, 07 Jan 2017 18:15:59 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 31db19d3e -> e275e9129


SOLR-9928 Unwrap Directory consistently whenever it's passed as an argument.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/e275e912
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e275e912
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e275e912

Branch: refs/heads/branch_6x
Commit: e275e91293e2ecb0356415a178c7ccd38a7182ff
Parents: 31db19d
Author: Andrzej Bialecki <ab@apache.org>
Authored: Sat Jan 7 13:22:37 2017 +0100
Committer: Andrzej Bialecki <ab@apache.org>
Committed: Sat Jan 7 19:15:51 2017 +0100

----------------------------------------------------------------------
 .../solr/core/MetricsDirectoryFactory.java      | 54 +++++++++-----------
 1 file changed, 25 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e275e912/solr/core/src/java/org/apache/solr/core/MetricsDirectoryFactory.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/core/MetricsDirectoryFactory.java b/solr/core/src/java/org/apache/solr/core/MetricsDirectoryFactory.java
index c3cdaf7..2414655 100644
--- a/solr/core/src/java/org/apache/solr/core/MetricsDirectoryFactory.java
+++ b/solr/core/src/java/org/apache/solr/core/MetricsDirectoryFactory.java
@@ -74,21 +74,28 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements
SolrCor
     }
   }
 
-  @Override
-  public void doneWithDirectory(Directory dir) throws IOException {
-    // unwrap
+  /**
+   * Unwrap just one level if the argument is a {@link MetricsDirectory}
+   * @param dir directory
+   * @return delegate if the instance was a {@link MetricsDirectory}, otherwise unchanged.
+   */
+  private static Directory unwrap(Directory dir) {
     if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory)dir).getDelegate();
+      return ((MetricsDirectory)dir).getDelegate();
+    } else {
+      return dir;
     }
+  }
+
+  @Override
+  public void doneWithDirectory(Directory dir) throws IOException {
+    dir = unwrap(dir);
     in.doneWithDirectory(dir);
   }
 
   @Override
   public void addCloseListener(Directory dir, CachingDirectoryFactory.CloseListener closeListener)
{
-    // unwrap
-    if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory)dir).getDelegate();
-    }
+    dir = unwrap(dir);
     in.addCloseListener(dir, closeListener);
   }
 
@@ -115,19 +122,13 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements
SolrCor
 
   @Override
   public void remove(Directory dir) throws IOException {
-    // unwrap
-    if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory)dir).getDelegate();
-    }
+    dir = unwrap(dir);
     in.remove(dir);
   }
 
   @Override
   public void remove(Directory dir, boolean afterCoreClose) throws IOException {
-    // unwrap
-    if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory)dir).getDelegate();
-    }
+    dir = unwrap(dir);
     in.remove(dir, afterCoreClose);
   }
 
@@ -152,8 +153,9 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements
SolrCor
   }
 
   @Override
-  public long size(Directory directory) throws IOException {
-    return in.size(directory);
+  public long size(Directory dir) throws IOException {
+    dir = unwrap(dir);
+    return in.size(dir);
   }
 
   @Override
@@ -183,14 +185,14 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements
SolrCor
 
   @Override
   public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext)
throws IOException {
+    fromDir = unwrap(fromDir);
+    toDir = unwrap(toDir);
     in.move(fromDir, toDir, fileName, ioContext);
   }
 
   @Override
   public void renameWithOverwrite(Directory dir, String fileName, String toName) throws IOException
{
-    if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory) dir).getDelegate();
-    }
+    dir = unwrap(dir);
     in.renameWithOverwrite(dir, fileName, toName);
   }
 
@@ -221,10 +223,7 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements
SolrCor
 
   @Override
   public void incRef(Directory dir) {
-    // unwrap
-    if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory)dir).getDelegate();
-    }
+    dir = unwrap(dir);
     in.incRef(dir);
   }
 
@@ -242,10 +241,7 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements
SolrCor
 
   @Override
   public void release(Directory dir) throws IOException {
-    // unwrap
-    if (dir instanceof MetricsDirectory) {
-      dir = ((MetricsDirectory)dir).getDelegate();
-    }
+    dir = unwrap(dir);
     in.release(dir);
   }
 


Mime
View raw message