Apache Lucene open-source search software
LUCENE-621 - new static methods for modifing default lock timeouts
Chris M. Hostetter13bb6026a77a
diff --git a/CHANGES.txt b/CHANGES.txtindex 3ee39eb3d5d..c0ab5bcbbc8 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -34,7 +34,15 @@ API Changessubclass allows explain methods to produce Explanations which model"matching" independent of having a positive value.(Chris Hostetter)-++ 6. LUCENE-621: New static methods IndexWriter.setDefaultWriteLockTimeout+ and IndexWriter.setDefaultCommitLockTimeout for overriding default+ timeout values for all future instances of IndexWriter (as well+ as for any other classes that may refrence the static values,+ ie: IndexReader).+ (Michael McCandless via Chris Hostetter)++Bug fixes1. Fixed the web application demo (built with "ant war-demo") whichdiff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.javaindex c1d9ef64922..901a1fa4194 100644--- a/src/java/org/apache/lucene/index/IndexWriter.java+++ b/src/java/org/apache/lucene/index/IndexWriter.java@@ -60,15 +60,17 @@ public class IndexWriter {/*** Default value for the write lock timeout (1,000).+ * @see #setDefaultWriteLockTimeout*/- public final static long WRITE_LOCK_TIMEOUT = 1000;+ public static long WRITE_LOCK_TIMEOUT = 1000;private long writeLockTimeout = WRITE_LOCK_TIMEOUT;/*** Default value for the commit lock timeout (10,000).+ * @see #setDefaultCommitLockTimeout*/- public final static long COMMIT_LOCK_TIMEOUT = 10000;+ public static long COMMIT_LOCK_TIMEOUT = 10000;private long commitLockTimeout = COMMIT_LOCK_TIMEOUT;@@ -370,7 +372,8 @@ public class IndexWriter {}/**- * Sets the maximum time to wait for a commit lock (in milliseconds).+ * Sets the maximum time to wait for a commit lock (in milliseconds) for this instance of IndexWriter. @see+ * @see #setDefaultCommitLockTimeout to change the default value for all instances of IndexWriter.*/public void setCommitLockTimeout(long commitLockTimeout) {this.commitLockTimeout = commitLockTimeout;@@ -384,7 +387,22 @@ public class IndexWriter {}/**- * Sets the maximum time to wait for a write lock (in milliseconds).+ * Sets the default (for any instance of IndexWriter) maximum time to wait for a commit lock (in milliseconds)+ */+ public static void setDefaultCommitLockTimeout(long commitLockTimeout) {+ IndexWriter.COMMIT_LOCK_TIMEOUT = commitLockTimeout;+ }++ /**+ * @see #setDefaultCommitLockTimeout+ */+ public static long getDefaultCommitLockTimeout() {+ return IndexWriter.COMMIT_LOCK_TIMEOUT;+ }++ /**+ * Sets the maximum time to wait for a write lock (in milliseconds) for this instance of IndexWriter. @see+ * @see #setDefaultWriteLockTimeout to change the default value for all instances of IndexWriter.*/public void setWriteLockTimeout(long writeLockTimeout) {this.writeLockTimeout = writeLockTimeout;@@ -397,6 +415,21 @@ public class IndexWriter {return writeLockTimeout;}+ /**+ * Sets the default (for any instance of IndexWriter) maximum time to wait for a write lock (in+ * milliseconds).+ */+ public static void setDefaultWriteLockTimeout(long writeLockTimeout) {+ IndexWriter.WRITE_LOCK_TIMEOUT = writeLockTimeout;+ }++ /**+ * @see #setDefaultWriteLockTimeout+ */+ public static long getDefaultWriteLockTimeout() {+ return IndexWriter.WRITE_LOCK_TIMEOUT;+ }+/** Flushes all changes to an index and closes all associated files. */public synchronized void close() throws IOException {flushRamSegments();diff --git a/src/test/org/apache/lucene/index/TestIndexWriter.java b/src/test/org/apache/lucene/index/TestIndexWriter.javaindex b9d3a83864e..e167b695beb 100644--- a/src/test/org/apache/lucene/index/TestIndexWriter.java+++ b/src/test/org/apache/lucene/index/TestIndexWriter.java@@ -27,8 +27,16 @@ public class TestIndexWriter extends TestCaseIndexReader reader = null;int i;+ IndexWriter.setDefaultWriteLockTimeout(2000);+ IndexWriter.setDefaultCommitLockTimeout(2000);+ assertEquals(2000, IndexWriter.getDefaultWriteLockTimeout());+ assertEquals(2000, IndexWriter.getDefaultCommitLockTimeout());+writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);+ IndexWriter.setDefaultWriteLockTimeout(1000);+ IndexWriter.setDefaultCommitLockTimeout(1000);+// add 100 documentsfor (i = 0; i < 100; i++) {addDoc(writer);