lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r231098 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/FSDirectory.java
Date Tue, 09 Aug 2005 20:12:57 GMT
Author: dnaber
Date: Tue Aug  9 13:12:50 2005
New Revision: 231098

URL: http://svn.apache.org/viewcvs?rev=231098&view=rev
Log:
use setter/getter instead of system property; catch security
exception so Lucene can be used inside an applet

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/viewcvs/lucene/java/trunk/CHANGES.txt?rev=231098&r1=231097&r2=231098&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Tue Aug  9 13:12:50 2005
@@ -53,6 +53,8 @@
       org.apache.lucene.mergeFactor,
     See BooleanQuery for getter/setter methods:
       org.apache.lucene.maxClauseCount
+    See FSDirectory for getter/setter methods:
+      disableLuceneLocks
     (Daniel Naber)
  
 New features

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=231098&r1=231097&r2=231098&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Tue Aug  9 13:12:50
2005
@@ -26,12 +26,9 @@
 import java.util.Hashtable;
 
 import org.apache.lucene.index.IndexFileNameFilter;
-import org.apache.lucene.util.Constants;
 
 /**
  * Straightforward implementation of {@link Directory} as a directory of files.
- * <p>If the system property 'disableLuceneLocks' has the String value of
- * "true", lock creation will be disabled.
  *
  * @see Directory
  * @author Doug Cutting
@@ -47,8 +44,24 @@
    */
   private static final Hashtable DIRECTORIES = new Hashtable();
 
-  private static final boolean DISABLE_LOCKS =
-      Boolean.getBoolean("disableLuceneLocks") || Constants.JAVA_1_1;
+  private static boolean disableLocks = false;
+
+  /**
+   * Set whether Lucene's use of lock files is disabled. By default, 
+   * lock files are enabled. They should only be disabled if the index
+   * is on a read-only medium like a CD-ROM.
+   */
+  public static void setDisableLocks(boolean doDisableLocks) {
+    FSDirectory.disableLocks = doDisableLocks;
+  }
+
+  /**
+   * Returns whether Lucene's use of lock files is disabled.
+   * @return true if locks are disabled, false if locks are enabled.
+   */
+  public static boolean getDisableLocks() {
+    return FSDirectory.disableLocks;
+  }
 
   /**
    * Directory specified by <code>org.apache.lucene.lockDir</code>
@@ -59,7 +72,7 @@
       System.getProperty("java.io.tmpdir"));
 
   /** The default class which implements filesystem-based directories. */
-  private static final Class IMPL;
+  private static Class IMPL;
   static {
     try {
       String name =
@@ -68,6 +81,12 @@
       IMPL = Class.forName(name);
     } catch (ClassNotFoundException e) {
       throw new RuntimeException("cannot load FSDirectory class: " + e.toString());
+    } catch (SecurityException se) {
+      try {
+        IMPL = Class.forName(FSDirectory.class.getName());
+      } catch (ClassNotFoundException e) {
+        throw new RuntimeException("cannot load default FSDirectory class: " + e.toString());
+      }
     }
   }
 
@@ -310,12 +329,7 @@
   {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
 
   /** Constructs a {@link Lock} with the specified name.  Locks are implemented
-   * with {@link File#createNewFile() }.
-   *
-   * <p>In JDK 1.1 or if system property <I>disableLuceneLocks</I> is the
-   * string "true", locks are disabled.  Assigning this property any other
-   * string will <B>not</B> prevent creation of lock files.  This is useful for
-   * using Lucene on read-only medium, such as CD-ROM.
+   * with {@link File#createNewFile()}.
    *
    * @param name the name of the lock file
    * @return an instance of <code>Lock</code> holding the lock
@@ -330,7 +344,7 @@
 
     return new Lock() {
       public boolean obtain() throws IOException {
-        if (DISABLE_LOCKS)
+        if (disableLocks)
           return true;
 
         if (!lockDir.exists()) {
@@ -342,12 +356,12 @@
         return lockFile.createNewFile();
       }
       public void release() {
-        if (DISABLE_LOCKS)
+        if (disableLocks)
           return;
         lockFile.delete();
       }
       public boolean isLocked() {
-        if (DISABLE_LOCKS)
+        if (disableLocks)
           return false;
         return lockFile.exists();
       }



Mime
View raw message