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

This commit is contained in:
Andrzej Bialecki 2017-01-07 13:22:37 +01:00
parent 1a95c5acd0
commit e5f39f62f7
1 changed files with 25 additions and 35 deletions

View File

@ -74,21 +74,28 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements SolrCor
}
}
/**
* 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) {
return ((MetricsDirectory)dir).getDelegate();
} else {
return dir;
}
}
@Override
public void doneWithDirectory(Directory dir) throws IOException {
// unwrap
if (dir instanceof MetricsDirectory) {
dir = ((MetricsDirectory)dir).getDelegate();
}
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,6 +185,8 @@ 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);
}
@ -198,10 +202,7 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements SolrCor
@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);
}
@ -220,17 +221,9 @@ public class MetricsDirectoryFactory extends DirectoryFactory implements SolrCor
in.initCoreContainer(cc);
}
@Override
protected Directory getBaseDir(Directory dir) {
return in.getBaseDir(dir);
}
@Override
public void incRef(Directory dir) {
// unwrap
if (dir instanceof MetricsDirectory) {
dir = ((MetricsDirectory)dir).getDelegate();
}
dir = unwrap(dir);
in.incRef(dir);
}
@ -248,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);
}