lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r488722 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/FSDirectory.java
Date Tue, 19 Dec 2006 16:31:07 GMT
Author: yonik
Date: Tue Dec 19 08:31:06 2006
New Revision: 488722

URL: http://svn.apache.org/viewvc?view=rev&rev=488722
Log:
remove FSIndexOutput finalizer, move FSIndexInput finalizer to it's Descriptor: LUCENE-750

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=488722&r1=488721&r2=488722
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Dec 19 08:31:06 2006
@@ -327,6 +327,10 @@
      to the List of clauses and replaced the internal synchronized Vector
      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
   1. Added TestTermScorer.java (Grant Ingersoll)
   2. Added TestWindowsMMap.java (Benson Margulies via Mike McCandless)

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=488722&r1=488721&r2=488722
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Tue Dec 19 08:31:06
2006
@@ -496,26 +496,40 @@
 
 class FSIndexInput extends BufferedIndexInput {
 
-  private class Descriptor extends RandomAccessFile {
-    public long position;
+  private static class Descriptor extends RandomAccessFile {
+    // remember if the file is open, so that we don't try to close it
+    // more than once
+    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 Descriptor file = null;
-  
-  // remember if the file is open, so that we don't try to close it
-  // more than once
-  private boolean isOpen;       
-  
+  private final Descriptor file;
   boolean isClone;
-  private long length;
 
   public FSIndexInput(File path) throws IOException {
     file = new Descriptor(path, "r");
-    isOpen = true;
-    length = file.length();
   }
 
   /** IndexInput methods */
@@ -539,27 +553,15 @@
   }
 
   public void close() throws IOException {
-    // only close the file if this is not a clone and the
-    // file has not been closed yet
-    if (!isClone && isOpen) {
-      file.close();
-      isOpen = false;
-    }
+    // only close the file if this is not a clone
+    if (!isClone) file.close();
   }
 
   protected void seekInternal(long position) {
   }
 
   public long length() {
-    return length;
-  }
-
-  protected void finalize() throws Throwable {
-    try {
-      close();            // close the file
-    } finally {
-      super.finalize();
-    }
+    return file.length;
   }
 
   public Object clone() {
@@ -609,14 +611,6 @@
   }
   public long length() throws IOException {
     return file.length();
-  }
-
-  protected void finalize() throws Throwable {
-    try {
-      close();          // close the file
-    } finally {
-      super.finalize();
-    }
   }
 
 }



Mime
View raw message