otis 2003/10/13 07:22:27 Modified: src/java/org/apache/lucene/index IndexReader.java IndexWriter.java Log: - Added WRITE_LOCK_NAME and COMMIT_LOCK_NAME, so that their names are not hard-coded in half a dozen places in the code. Revision Changes Path 1.19 +11 -6 jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java Index: IndexReader.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/IndexReader.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- IndexReader.java 25 Sep 2003 21:41:51 -0000 1.18 +++ IndexReader.java 13 Oct 2003 14:22:27 -0000 1.19 @@ -76,6 +76,9 @@ document in the index. These document numbers are ephemeral--they may change as documents are added to and deleted from an index. Clients should thus not rely on a given document having the same number between sessions. + + @author Doug Cutting + @version $Id$ */ public abstract class IndexReader { protected IndexReader(Directory directory) { @@ -104,7 +107,9 @@ /** Returns an IndexReader reading the index in the given Directory. */ public static IndexReader open(final Directory directory) throws IOException{ synchronized (directory) { // in- & inter-process sync - return (IndexReader)new Lock.With(directory.makeLock("commit.lock"), IndexWriter.COMMIT_LOCK_TIMEOUT) { + return (IndexReader)new Lock.With( + directory.makeLock("IndexWriter.COMMIT_LOCK_NAME"), + IndexWriter.COMMIT_LOCK_TIMEOUT) { public Object doBody() throws IOException { IndexReader result = null; @@ -264,7 +269,7 @@ */ public final synchronized void delete(int docNum) throws IOException { if (writeLock == null) { - Lock writeLock = directory.makeLock("write.lock"); + Lock writeLock = directory.makeLock("IndexWriter.WRITE_LOCK_NAME"); if (!writeLock.obtain(IndexWriter.WRITE_LOCK_TIMEOUT)) // obtain write lock throw new IOException("Index locked for write: " + writeLock); this.writeLock = writeLock; @@ -355,8 +360,8 @@ */ public static boolean isLocked(Directory directory) throws IOException { return - directory.makeLock("write.lock").isLocked() || - directory.makeLock("commit.lock").isLocked(); + directory.makeLock("IndexWriter.WRITE_LOCK_NAME").isLocked() || + directory.makeLock("IndexWriter.COMMIT_LOCK_NAME").isLocked(); } @@ -378,7 +383,7 @@ * currently accessing this index. */ public static void unlock(Directory directory) throws IOException { - directory.makeLock("write.lock").release(); - directory.makeLock("commit.lock").release(); + directory.makeLock("IndexWriter.WRITE_LOCK_NAME").release(); + directory.makeLock("IndexWriter.COMMIT_LOCK_NAME").release(); } } 1.17 +6 -3 jakarta-lucene/src/java/org/apache/lucene/index/IndexWriter.java Index: IndexWriter.java =================================================================== RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/IndexWriter.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- IndexWriter.java 25 Sep 2003 22:01:51 -0000 1.16 +++ IndexWriter.java 13 Oct 2003 14:22:27 -0000 1.17 @@ -89,6 +89,9 @@ public class IndexWriter { public static long WRITE_LOCK_TIMEOUT = 1000; public static long COMMIT_LOCK_TIMEOUT = 10000; + + public static final String WRITE_LOCK_NAME = "write.lock"; + public static final String COMMIT_LOCK_NAME = "commit.lock"; private Directory directory; // where this index resides private Analyzer analyzer; // how to analyze text @@ -166,13 +169,13 @@ directory = d; analyzer = a; - Lock writeLock = directory.makeLock("write.lock"); + Lock writeLock = directory.makeLock("IndexWriter.WRITE_LOCK_NAME"); if (!writeLock.obtain(WRITE_LOCK_TIMEOUT)) // obtain write lock throw new IOException("Index locked for write: " + writeLock); this.writeLock = writeLock; // save it synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock("commit.lock"), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock("COMMIT_LOCK_NAME"), COMMIT_LOCK_TIMEOUT) { public Object doBody() throws IOException { if (create) segmentInfos.write(directory); @@ -395,7 +398,7 @@ directory)); synchronized (directory) { // in- & inter-process sync - new Lock.With(directory.makeLock("commit.lock"), COMMIT_LOCK_TIMEOUT) { + new Lock.With(directory.makeLock("COMMIT_LOCK_NAME"), COMMIT_LOCK_TIMEOUT) { public Object doBody() throws IOException { segmentInfos.write(directory); // commit before deleting deleteSegments(segmentsToDelete); // delete now-unused segments
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]