Mailing List Archive

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/index/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*****
RE: Patch for IndexReader [ In reply to ]
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>
Re: Patch for IndexReader [ In reply to ]
This addition looks fine to me - the isLocked(Directory) method already
exists in IndexReader, so this is good for completion.

I will commit this tomorrow morning unless somebody sends me an email
by then with arguments against this patch.

Thanks,
Otis


--- "Britton, Colin" <cbritton@metatomix.com> wrote:
> 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/index/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*****
>

> ATTACHMENT part 2 application/octet-stream name=lucene_patch.diff
> --
> To unsubscribe, e-mail:
> <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:lucene-dev-help@jakarta.apache.org>


__________________________________________________
Do You Yahoo!?
Got something to say? Say it better with Yahoo! Video Mail
http://mail.yahoo.com

--
To unsubscribe, e-mail: <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-dev-help@jakarta.apache.org>
Re: Patch for IndexReader [ In reply to ]
Aloha,

public static boolean isLocked(Directory directory) already exists, so
I'll leave that as is.

Thanks,
Otis


--- "Britton, Colin" <cbritton@metatomix.com> wrote:
> 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/index/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*****
>

> ATTACHMENT part 2 application/octet-stream name=lucene_patch.diff
> --
> To unsubscribe, e-mail:
> <mailto:lucene-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:lucene-dev-help@jakarta.apache.org>


__________________________________________________
Do You Yahoo!?
Got something to say? Say it better with Yahoo! Video Mail
http://mail.yahoo.com

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