mirror of https://github.com/apache/lucene.git
remove FSIndexOutput finalizer, move FSIndexInput finalizer to it's Descriptor: LUCENE-750
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@488722 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
19ba76b0d4
commit
30c8ce4f10
|
@ -327,6 +327,10 @@ Optimizations
|
||||||
to the List of clauses and replaced the internal synchronized Vector
|
to the List of clauses and replaced the internal synchronized Vector
|
||||||
with an unsynchronized List. (Yonik Seeley)
|
with an unsynchronized List. (Yonik Seeley)
|
||||||
|
|
||||||
|
16. LUCENE-750: Remove finalizers from FSIndexOutput and move the
|
||||||
|
FSIndexInput finalizer to the actual file so all clones don't
|
||||||
|
register a new finalizer. (Yonik Seeley)
|
||||||
|
|
||||||
Test Cases
|
Test Cases
|
||||||
1. Added TestTermScorer.java (Grant Ingersoll)
|
1. Added TestTermScorer.java (Grant Ingersoll)
|
||||||
2. Added TestWindowsMMap.java (Benson Margulies via Mike McCandless)
|
2. Added TestWindowsMMap.java (Benson Margulies via Mike McCandless)
|
||||||
|
|
|
@ -496,26 +496,40 @@ public class FSDirectory extends Directory {
|
||||||
|
|
||||||
class FSIndexInput extends BufferedIndexInput {
|
class FSIndexInput extends BufferedIndexInput {
|
||||||
|
|
||||||
private class Descriptor extends RandomAccessFile {
|
private static class Descriptor extends RandomAccessFile {
|
||||||
public long position;
|
|
||||||
public Descriptor(File file, String mode) throws IOException {
|
|
||||||
super(file, mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Descriptor file = null;
|
|
||||||
|
|
||||||
// remember if the file is open, so that we don't try to close it
|
// remember if the file is open, so that we don't try to close it
|
||||||
// more than once
|
// more than once
|
||||||
private boolean isOpen;
|
private boolean isOpen;
|
||||||
|
long position;
|
||||||
|
final long length;
|
||||||
|
|
||||||
|
public Descriptor(File file, String mode) throws IOException {
|
||||||
|
super(file, mode);
|
||||||
|
isOpen=true;
|
||||||
|
length=length();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (isOpen) {
|
||||||
|
isOpen=false;
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void finalize() throws Throwable {
|
||||||
|
try {
|
||||||
|
close();
|
||||||
|
} finally {
|
||||||
|
super.finalize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Descriptor file;
|
||||||
boolean isClone;
|
boolean isClone;
|
||||||
private long length;
|
|
||||||
|
|
||||||
public FSIndexInput(File path) throws IOException {
|
public FSIndexInput(File path) throws IOException {
|
||||||
file = new Descriptor(path, "r");
|
file = new Descriptor(path, "r");
|
||||||
isOpen = true;
|
|
||||||
length = file.length();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** IndexInput methods */
|
/** IndexInput methods */
|
||||||
|
@ -539,27 +553,15 @@ class FSIndexInput extends BufferedIndexInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
// only close the file if this is not a clone and the
|
// only close the file if this is not a clone
|
||||||
// file has not been closed yet
|
if (!isClone) file.close();
|
||||||
if (!isClone && isOpen) {
|
|
||||||
file.close();
|
|
||||||
isOpen = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void seekInternal(long position) {
|
protected void seekInternal(long position) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public long length() {
|
public long length() {
|
||||||
return length;
|
return file.length;
|
||||||
}
|
|
||||||
|
|
||||||
protected void finalize() throws Throwable {
|
|
||||||
try {
|
|
||||||
close(); // close the file
|
|
||||||
} finally {
|
|
||||||
super.finalize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object clone() {
|
public Object clone() {
|
||||||
|
@ -611,12 +613,4 @@ class FSIndexOutput extends BufferedIndexOutput {
|
||||||
return file.length();
|
return file.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finalize() throws Throwable {
|
|
||||||
try {
|
|
||||||
close(); // close the file
|
|
||||||
} finally {
|
|
||||||
super.finalize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue