Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 793769) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -468,7 +468,7 @@ * places if it is in "near real-time mode" (getReader() * has been called on this instance). */ - class ReaderPool { + public class ReaderPool { private final Map readerMap = new HashMap(); @@ -493,14 +493,14 @@ } // used only by asserts - synchronized boolean infoIsLive(SegmentInfo info) { + public synchronized boolean infoIsLive(SegmentInfo info) { int idx = segmentInfos.indexOf(info); assert idx != -1; assert segmentInfos.get(idx) == info; return true; } - synchronized SegmentInfo mapToLive(SegmentInfo info) { + public synchronized SegmentInfo mapToLive(SegmentInfo info) { int idx = segmentInfos.indexOf(info); if (idx != -1) { info = (SegmentInfo) segmentInfos.get(idx); @@ -508,12 +508,24 @@ return info; } - synchronized void release(SegmentReader sr) throws IOException { + /** + * Release the segment reader (i.e. decRef it and close if there + * are no more references. + * @param sr + * @throws IOException + */ + public synchronized void release(SegmentReader sr) throws IOException { release(sr, false); } + + /** + * Release the segment reader (i.e. decRef it and close if there + * are no more references. + * @param sr + * @throws IOException + */ + public synchronized void release(SegmentReader sr, boolean drop) throws IOException { - synchronized void release(SegmentReader sr, boolean drop) throws IOException { - final boolean pooled = readerMap.containsKey(sr.getSegmentInfo()); assert !pooled | readerMap.get(sr.getSegmentInfo()) == sr; @@ -582,7 +594,11 @@ } } - public synchronized void commit() throws IOException { + /** + * Commit all segment reader in the pool. + * @throws IOException + */ + synchronized void commit() throws IOException { Iterator iter = readerMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry ent = (Map.Entry) iter.next(); @@ -604,9 +620,11 @@ } } - // Returns a ref to a clone. NOTE: this clone is not - // enrolled in the pool, so you should simply close() - // it when you're done (ie, do not call release()). + /** + * Returns a ref to a clone. NOTE: this clone is not + * enrolled in the pool, so you should simply close() + * it when you're done (ie, do not call release()). + */ public synchronized SegmentReader getReadOnlyClone(SegmentInfo info, boolean doOpenStores, int termInfosIndexDivisor) throws IOException { SegmentReader sr = get(info, doOpenStores, BufferedIndexInput.BUFFER_SIZE, termInfosIndexDivisor); try { @@ -616,11 +634,31 @@ } } - // Returns a ref + /** + * Obtain a SegmentReader from the readerPool. The reader + * must be returned by calling the release method. + * + * @see #release(SegmentReader) + * @param info + * @param doOpenStores + * @return + * @throws IOException + */ public synchronized SegmentReader get(SegmentInfo info, boolean doOpenStores) throws IOException { return get(info, doOpenStores, BufferedIndexInput.BUFFER_SIZE, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR); } - + /** + * Obtain a SegmentReader from the readerPool. The reader + * must be returned by calling the release method. + * + * @see #release(SegmentReader) + * @param info + * @param doOpenStores + * @param readBufferSize + * @param termsIndexDivisor + * @return + * @throws IOException + */ public synchronized SegmentReader get(SegmentInfo info, boolean doOpenStores, int readBufferSize, int termsIndexDivisor) throws IOException { if (poolReaders) { @@ -664,6 +702,14 @@ } } + /** + * Get a reader pool. + * @return readerPool + */ + public ReaderPool getReaderPool() { + return readerPool; + } + synchronized void acquireWrite() { assert writeThread != Thread.currentThread(); while(writeThread != null || readCount > 0) Index: src/java/org/apache/lucene/index/SegmentInfo.java =================================================================== --- src/java/org/apache/lucene/index/SegmentInfo.java (revision 793769) +++ src/java/org/apache/lucene/index/SegmentInfo.java (working copy) @@ -28,7 +28,14 @@ import java.util.ArrayList; import java.util.Collections; -final class SegmentInfo { +/** + * Information about a segment such as it's name, directory, and files related + * to the segment. + * + * *
NOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public final class SegmentInfo { static final int NO = -1; // e.g. no norms; no deletes; static final int YES = 1; // e.g. have norms; have deletes; @@ -150,7 +157,7 @@ } // returns MapNOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public final class SegmentInfos extends Vector { /** The file format version, a negative number. */ /* Works since counter, the old 1st entry, is always >= 0 */ @@ -767,7 +774,7 @@ version = other.version; } - public final void rollbackCommit(Directory dir) throws IOException { + final void rollbackCommit(Directory dir) throws IOException { if (pendingSegnOutput != null) { try { pendingSegnOutput.close(); @@ -796,7 +803,7 @@ * end, so that it is not visible to readers. Once this * is called you must call {@link #finishCommit} to complete * the commit or {@link #rollbackCommit} to abort it. */ - public final void prepareCommit(Directory dir) throws IOException { + final void prepareCommit(Directory dir) throws IOException { if (pendingSegnOutput != null) throw new IllegalStateException("prepareCommit was already called"); write(dir); @@ -822,7 +829,7 @@ return files; } - public final void finishCommit(Directory dir) throws IOException { + final void finishCommit(Directory dir) throws IOException { if (pendingSegnOutput == null) throw new IllegalStateException("prepareCommit was not called"); boolean success = false; @@ -882,7 +889,7 @@ /** Writes & syncs to the Directory dir, taking care to * remove the segments file on exception */ - public final void commit(Directory dir) throws IOException { + final void commit(Directory dir) throws IOException { prepareCommit(dir); finishCommit(dir); } @@ -906,7 +913,7 @@ return userData; } - public void setUserData(Map data) { + void setUserData(Map data) { if (data == null) { userData = Collections.EMPTY_MAP; } else { Index: src/java/org/apache/lucene/index/SegmentReader.java =================================================================== --- src/java/org/apache/lucene/index/SegmentReader.java (revision 793769) +++ src/java/org/apache/lucene/index/SegmentReader.java (working copy) @@ -39,7 +39,11 @@ import org.apache.lucene.util.CloseableThreadLocal; /** @version $Id */ -class SegmentReader extends IndexReader implements Cloneable { +/** + *NOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public class SegmentReader extends IndexReader implements Cloneable { protected boolean readOnly; private SegmentInfo si;