lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Britton, Colin" <cbrit...@metatomix.com>
Subject RE: Patch for IndexReader
Date Thu, 14 Feb 2002 23:03:35 GMT
A few days ago I posted a patch to add to IndexReader the ability to
check if an index is locked by passing a string or file object as well
as a directory. I added this so that I could have a cached index reader
that checked if an index was not locked, but modified before reloading
it - part of sharing the index between all users in my webapp. This is a
mod from the jhtml example and works well but to keep it clean I
modified IndexReader.isLocked(name) to take the name of the index not
the directory object of it. Is the patch needed? And if so will the
patch make it into 1.2 to save me patching my local copy of lucene.

Rgds
CB

My cached index code.....

	IndexReader getReader(String name) throws Exception {
			CachedIndex index = // look in cache
	 (CachedIndex) indexCache.get(name);

		try {
			if (index != null
				&& // check up-to-date
			 (index.modified ==
IndexReader.lastModified(name)))
				return index.reader; // cache hit
			else {
				if (IndexReader.isLocked(name))
					return index.reader; // cache
hit, modified but locked
				else {
					index = new CachedIndex(name);
// cache miss , get new
				}
			}
		} catch (Exception e) {
			//System.out.println(" caught a " + e.getClass()
+ "\n with message: " + e.getMessage());
			e.printStackTrace();
			return null;
		}





> -----Original Message-----
> From: Britton, Colin 
> Sent: Friday, February 08, 2002 1:43 PM
> To: lucene-dev@jakarta.apache.org
> Subject: Patch for IndexReader
> 
> 
> Here is a patch for IndexReader.isLocked() to support file 
> and string in the same way as IndexReader.indexExists()
> 
> It is in the body and as an attachment.
> 
> Rgds
> CB
> 
> Index: IndexReader.java 
> ===================================================================
> RCS file: 
> /home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/inde
> x/IndexRea
> der.java,v
> retrieving revision 1.6
> diff -u -r1.6 IndexReader.java
> --- IndexReader.java	21 Jan 2002 17:07:23 -0000	1.6
> +++ IndexReader.java	8 Feb 2002 18:40:03 -0000
> @@ -269,7 +269,28 @@
>     */
>      abstract public void close() throws IOException;
>  
> -  /**
> + /**
> +   * Returns <code>true</code> iff the index in the named 
> directory is
> +   * currently locked.
> +   * @param String the directory to check for a lock
> +   * @throws IOException if there is a problem with 
> accessing the index
> +   */
> +   public static boolean isLocked(String directory) throws 
> IOException
> {
> +    return (new File(directory, "write.lock")).exists();
> +  }
> +  
> + /**
> +   * Returns <code>true</code> iff the index in the named 
> directory is
> +   * currently locked.
> +   * @param File the directory to check for a lock
> +   * @throws IOException if there is a problem with 
> accessing the index
> +   */
> +  public static boolean isLocked(File directory) throws IOException {
> +    return (new File(directory, "write.lock")).exists();
> +  }
> +
> +
> + /**
>     * Returns <code>true</code> iff the index in the named 
> directory is
>     * currently locked.
>     * @param directory the directory to check for a lock
> 
> *****CVS exited normally with code 1*****
> 

--
To unsubscribe, e-mail:   <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>


Mime
View raw message