|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object
|
+--org.apache.lucene.index.IndexReader
|
+--org.apache.lucene.index.IdleTimeoutRefreshingIndexReader
This index reader delegates most tasks to the normal IndexReader
implementation. It adds support for refreshing a stale index
(one that has been modified since it was opened) without
requiring the consumer of the reader to be aware of all the details.
It also supplies a mechanism to close the underlying reader
when it has gone idle and re-open it when it is used again.
There are four configurable properties:
#minimumWaitToClose (static member)#waitToClose#timeout#refreshInterval
The minimumWaitToClose property can be configured using setMinimumWaitToClose(long).
Each of the other properties can be configured on a per instance basis using the property setters
setWaitToClose(long), setTimeout(long) and setRefreshInterval(long).
Defaults can be set on the command line by specifying long values as system properties using the keys
PROP_WAIT_TO_CLOSE, PROP_TIMEOUT and PROP_REFRESH_INTERVAL.
If those defaults are not set or don't parse as longs according to Long.getLong(String),
the default is to never timeout and never refresh (behavior analogous to a normal IndexReader with a
performance penalty due to the delegation model).
The defaults can also be manipulated at runtime using the static setters
setDefaultWaitToClose(long), setDefaultTimeout(long) and setDefaultRefreshInterval(long).
Runtime changes to the defaults will not affect already instantiated instances, use the
instance level setters instead.
The waitToClose property has a minimum setting determined by MINIMUM_WAIT_TO_CLOSE.
It is important that the closing reader have enough time to complete the servicing
of any existing requests before being closed. This strategy was chosen in lieu of completely
synchronizing all requests to the index reader. If the reader is closed to soon the consumers
will get an IOException since they will be attempting to read from closed files.
There were three methods of IndexReader that did not throw IOException.
These were wrapped to throw RuntimeException. See isDeleted(int), maxDoc() and numDocs().
I'm not sure this was a good strategy, but I wasn't sure what else to choose.
I'm not sure at the time of this writing whether this implementation works with a RAMDirectory implementation.
| Field Summary | |
static long |
DEFAULT_MINIMUM_WAIT_TO_CLOSE
The default minimum value of the waitToClose property
used if no default was specified and the system property is not set. |
static long |
DEFAULT_REFRESH_INTERVAL
The default value of the refreshInterval property. |
static long |
DEFAULT_TIMEOUT
The default value of the timeout property. |
static long |
DEFAULT_WAIT_TO_CLOSE
The default value of the waitToClose property. |
static String |
PROP_MINIMUM_WAIT_TO_CLOSE
The name of the minimumWaitToClose property. |
static String |
PROP_REFRESH_INTERVAL
The name of the refreshInterval property. |
static String |
PROP_TIMEOUT
The name of the timeout property. |
static String |
PROP_WAIT_TO_CLOSE
The name of the waitToClose property. |
| Constructor Summary | |
protected |
IdleTimeoutRefreshingIndexReader(Directory directory,
long timeout,
long refreshInterval,
long waitToClose)
Constructs an IdleTimeoutRefreshingIndexReader. |
| Method Summary | |
int |
docFreq(Term arg0)
Returns the number of documents containing the term t. |
protected void |
doClose()
Closes up any monitoring threads and the reader delegate if they exist. |
Document |
document(int arg0)
Returns the stored fields of the nth
Document in this index. |
protected void |
doDelete(int arg0)
|
static long |
getDefaultRefreshInterval()
Gets the default value for the refreshInterval property. |
static long |
getDefaultTimeout()
Gets the default value for the timeout property. |
static long |
getDefaultWaitToClose()
Gets the default value for the waitToClose property. |
Collection |
getFieldNames()
Returns a list of all unique field names that exist in the index pointed to by this IndexReader. |
Collection |
getFieldNames(boolean arg0)
Returns a list of all unique field names that exist in the index pointed to by this IndexReader. |
long |
getLastAccessed()
Gets the last accessed time for this reader. |
static long |
getMinimumWaitToClose()
Gets the minimum value for the waitToClose property. |
long |
getModifiedTimeOnOpen()
Gets the time this index reported as its last modified time when it was opened. |
long |
getRefreshInterval()
Gets the refresh interval used to check for changes to the index being read. |
long |
getTimeout()
Gets the idle timeout used to close inactive readers. |
long |
getWaitToClose()
Gets the wait time used to give consumers of this reader time to finish up before the underlying files are closed. |
boolean |
isDeleted(int arg0)
Returns true if document n has been deleted |
boolean |
isIdle()
Checks if the reader has been idle longer than the idle timeout. |
boolean |
isStale()
Checks if the index has changed since it was opened. |
int |
maxDoc()
Returns one greater than the largest possible document number. |
byte[] |
norms(String arg0)
Returns the byte-encoded normalization factor for the named field of every document. |
int |
numDocs()
Returns the number of documents in this index. |
static IndexReader |
open(Directory directory)
Overrides IndexReader.open(Directory) to create an
IdleTimeoutRefreshingIndexReader. |
static IdleTimeoutRefreshingIndexReader |
open(Directory directory,
long timeout,
long refreshInterval,
long waitToClose)
Constructs and returns an IdleTimeoutRefreshingIndexReader. |
static IndexReader |
open(File file)
Overrides IndexReader.open(File) to create an
IdleTimeoutRefreshingIndexReader. |
static IdleTimeoutRefreshingIndexReader |
open(File file,
long timeout,
long refreshInterval,
long waitToClose)
Constructs and returns an IdleTimeoutRefreshingIndexReader. |
static IndexReader |
open(String filepath)
Overrides IndexReader.open(String) to create an
IdleTimeoutRefreshingIndexReader. |
static IdleTimeoutRefreshingIndexReader |
open(String filepath,
long timeout,
long refreshInterval,
long waitToClose)
Constructs and returns an IdleTimeoutRefreshingIndexReader. |
static void |
setDefaultRefreshInterval(long refreshInterval)
Sets the default value for the refreshInterval property. |
static void |
setDefaultTimeout(long timeout)
Sets the default value for the timeout property. |
static void |
setDefaultWaitToClose(long waitToClose)
Sets the default value for the waitToClose property. |
static void |
setMinimumWaitToClose(long minWaitToClose)
Sets the minimum value for the waitToClose property. |
void |
setRefreshInterval(long refreshInterval)
Sets the refresh interval used to check for changes to the index being read. |
void |
setTimeout(long timeout)
Sets the idle timeout used to close inactive readers. |
void |
setWaitToClose(long waitToClose)
Sets the wait time used to give consumers of this reader time to finish up before the underlying files are closed. |
TermDocs |
termDocs()
Returns an unpositioned TermDocs enumerator. |
TermDocs |
termDocs(Term arg0)
Returns an enumeration of all the documents which contain term. |
TermPositions |
termPositions()
Returns an unpositioned TermPositions enumerator. |
TermPositions |
termPositions(Term arg0)
Returns an enumeration of all the documents which contain term. |
TermEnum |
terms()
Returns an enumeration of all the terms in the index. |
TermEnum |
terms(Term arg0)
Returns an enumeration of all terms after a given term. |
| Methods inherited from class org.apache.lucene.index.IndexReader |
close, delete, delete, finalize, indexExists, indexExists, indexExists, isLocked, isLocked, lastModified, lastModified, lastModified, unlock |
| Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final String PROP_MINIMUM_WAIT_TO_CLOSE
minimumWaitToClose property.
public static final String PROP_WAIT_TO_CLOSE
waitToClose property.
public static final String PROP_TIMEOUT
timeout property.
public static final String PROP_REFRESH_INTERVAL
refreshInterval property.
public static final long DEFAULT_MINIMUM_WAIT_TO_CLOSE
waitToClose property
used if no default was specified and the system property is not set.
public static final long DEFAULT_WAIT_TO_CLOSE
waitToClose property.
used if no default was specified and the system property is not set.
public static final long DEFAULT_TIMEOUT
timeout property.
used if no default was specified and the system property is not set.
public static final long DEFAULT_REFRESH_INTERVAL
refreshInterval property.
used if no default was specified and the system property is not set.
| Constructor Detail |
protected IdleTimeoutRefreshingIndexReader(Directory directory,
long timeout,
long refreshInterval,
long waitToClose)
directory - The directory to pass to the IndexReader implementation.timeout - The idle timeout in milliseconds.refreshInterval - The refresh interval in milliseconds.waitToClose - The time in milliseconds to wait before closing a timed out or refreshed index.| Method Detail |
public static IdleTimeoutRefreshingIndexReader open(Directory directory,
long timeout,
long refreshInterval,
long waitToClose)
directory - The directory to pass to the IndexReader implementation.timeout - The idle timeout in milliseconds.refreshInterval - The refresh interval in milliseconds.waitToClose - The time in milliseconds to wait before closing a timed out or refreshed index.
public static IndexReader open(Directory directory)
IndexReader.open(Directory) to create an
IdleTimeoutRefreshingIndexReader. Uses the default timings.
directory - The directory to pass to the IndexReader implementation.
public static IdleTimeoutRefreshingIndexReader open(File file,
long timeout,
long refreshInterval,
long waitToClose)
throws IOException
file - The File that points to the index to read.timeout - The idle timeout in milliseconds.refreshInterval - The refresh interval in milliseconds.waitToClose - The time in milliseconds to wait before closing a timed out or refreshed index.
IOException
public static IndexReader open(File file)
throws IOException
IndexReader.open(File) to create an
IdleTimeoutRefreshingIndexReader. Uses the default timings.
file - The File that points to the index to read.
IOException
public static IdleTimeoutRefreshingIndexReader open(String filepath,
long timeout,
long refreshInterval,
long waitToClose)
throws IOException
filepath - The path that points to the index to read.timeout - The idle timeout in milliseconds.refreshInterval - The refresh interval in milliseconds.waitToClose - The time in milliseconds to wait before closing a timed out or refreshed index.
IOException
public static IndexReader open(String filepath)
throws IOException
IndexReader.open(String) to create an
IdleTimeoutRefreshingIndexReader. Uses the default timings.
filepath - The path that points to the index to read.
IOExceptionpublic boolean isIdle()
true if the reader is idle.public boolean isStale()
true if the index has changed.
false if the index has not changed or an IOException
prevented verification of the index's last modified time.protected void doClose()
doClose in class IndexReaderIndexReader#doClose()
public int docFreq(Term arg0)
throws IOException
IndexReadert.
docFreq in class IndexReaderIOExceptionIndexReader.docFreq(Term)
public Document document(int arg0)
throws IOException
IndexReadernth
Document in this index.
document in class IndexReaderIOExceptionIndexReader.document(int)
public Collection getFieldNames()
throws IOException
IndexReader
getFieldNames in class IndexReaderIOException - if there is a problem with accessing the indexIndexReader.getFieldNames()
public Collection getFieldNames(boolean arg0)
throws IOException
IndexReader
getFieldNames in class IndexReaderarg0 - true if only indexed fields should be returned;
false if only unindexed fields should be returned.
IOException - if there is a problem with accessing the indexIndexReader.getFieldNames(boolean)public boolean isDeleted(int arg0)
IndexReader
isDeleted in class IndexReaderRuntimeException - if the method is accessed while
the delegate reader is not open.IndexReader.isDeleted(int)public int maxDoc()
IndexReader
maxDoc in class IndexReaderRuntimeException - if the method is accessed while
the delegate reader is not open.IndexReader.maxDoc()
public byte[] norms(String arg0)
throws IOException
IndexReader
norms in class IndexReaderIOExceptionIndexReader.norms(String)public int numDocs()
IndexReader
numDocs in class IndexReaderRuntimeException - if the method is accessed while
the delegate reader is not open.IndexReader.numDocs()
public TermDocs termDocs()
throws IOException
IndexReaderTermDocs enumerator.
termDocs in class IndexReaderIOExceptionIndexReader.termDocs()
public TermDocs termDocs(Term arg0)
throws IOException
IndexReaderterm. For each document, the document number, the frequency of
the term in that document is also provided, for use in search scoring.
Thus, this method implements the mapping:
The enumeration is ordered by document number. Each document number is greater than all that precede it in the enumeration.
termDocs in class IndexReaderIOExceptionIndexReader.termDocs(Term)
public TermPositions termPositions()
throws IOException
IndexReaderTermPositions enumerator.
termPositions in class IndexReaderIOExceptionIndexReader.termPositions()
public TermPositions termPositions(Term arg0)
throws IOException
IndexReaderterm. For each document, in addition to the document number
and frequency of the term in that document, a list of all of the ordinal
positions of the term in the document is available. Thus, this method
implements the mapping:
This positional information faciliates phrase and proximity searching.
The enumeration is ordered by document number. Each document number is greater than all that precede it in the enumeration.
termPositions in class IndexReaderIOExceptionIndexReader.termPositions(Term)
public TermEnum terms()
throws IOException
IndexReader
terms in class IndexReaderIOExceptionIndexReader.terms()
public TermEnum terms(Term arg0)
throws IOException
IndexReader
terms in class IndexReaderIOExceptionIndexReader.terms(Term)
protected void doDelete(int arg0)
throws IOException
doDelete in class IndexReaderIOExceptionIndexReader#doDelete(int)public long getWaitToClose()
public void setWaitToClose(long waitToClose)
Sets the wait time used to give consumers of this reader time to finish up before the underlying files are closed.
If the time is less than getMinimumWaitToClose(),
getMinimumWaitToClose() will be used instead.
waitToClose - The time to wait in milliseconds.public long getRefreshInterval()
public void setRefreshInterval(long refreshInterval)
Sets the refresh interval used to check for changes to the index being read. This is the time between checks.
Setting this value to 0 will prevent monitoring for refreshes.
This number should be reasonably high to prevent constant checking of file modification times on the disk.
refreshInterval - The time to wait in milliseconds.public long getTimeout()
public void setTimeout(long timeout)
Sets the idle timeout used to close inactive readers.
Setting this value to 0 will prevent monitoring for idle readers.
This number should be reasonably high to prevent constant opening and closing of files on the disk.
timeout - The time to wait in milliseconds.public static long getMinimumWaitToClose()
Gets the minimum value for the waitToClose property.
If this property has not been set, the system property with the key
PROP_MINIMUM_WAIT_TO_CLOSE will be checked.
If the system property is not set or cannot be parsed, DEFAULT_MINIMUM_WAIT_TO_CLOSE
will be used.
Long#getLong(String,String)public static void setMinimumWaitToClose(long minWaitToClose)
waitToClose property.
minWaitToClose - The minimum time in milliseconds.public static long getDefaultWaitToClose()
Gets the default value for the waitToClose property.
If this property has not been set, the system property with the key
PROP_WAIT_TO_CLOSE will be checked.
If the system property is not set or cannot be parsed, DEFAULT_WAIT_TO_CLOSE
will be used.
Long#getLong(String,String)public static void setDefaultWaitToClose(long waitToClose)
waitToClose property.
waitToClose - The default time in milliseconds.public static long getDefaultRefreshInterval()
Gets the default value for the refreshInterval property.
If this property has not been set, the system property with the key
PROP_REFRESH_INTERVAL will be checked.
If the system property is not set or cannot be parsed, DEFAULT_REFRESH_INTERVAL
will be used.
Long#getLong(String,String)public static void setDefaultRefreshInterval(long refreshInterval)
refreshInterval property.
refreshInterval - The default time in milliseconds.public static long getDefaultTimeout()
Gets the default value for the timeout property.
If this property has not been set, the system property with the key
PROP_TIMEOUT will be checked.
If the system property is not set or cannot be parsed, DEFAULT_TIMEOUT
will be used.
Long#getLong(String,String)public static void setDefaultTimeout(long timeout)
timeout property.
timeout - The default time in milliseconds.public long getLastAccessed()
public long getModifiedTimeOnOpen()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||