java.lang.Object
org.apache.lucene.index.DocumentsWriterPerThreadPool
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<DocumentsWriterPerThread>
final class DocumentsWriterPerThreadPool
extends Object
implements Iterable<DocumentsWriterPerThread>, Closeable
DocumentsWriterPerThreadPool controls DocumentsWriterPerThread instances and
their thread assignments during indexing. Each DocumentsWriterPerThread is once a
obtained from the pool exclusively used for indexing a single document or list of documents by
the obtaining thread. Each indexing thread must obtain such a DocumentsWriterPerThread to
make progress. Depending on the DocumentsWriterPerThreadPool implementation DocumentsWriterPerThread assignments might differ from document to document.
Once a DocumentsWriterPerThread is selected for flush the DocumentsWriterPerThread will be checked out of the thread pool and won't be reused for
indexing. See checkout(DocumentsWriterPerThread).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final Supplier<DocumentsWriterPerThread> private final Set<DocumentsWriterPerThread> private int -
Constructor Summary
ConstructorsConstructorDescriptionDocumentsWriterPerThreadPool(Supplier<DocumentsWriterPerThread> dwptFactory) -
Method Summary
Modifier and TypeMethodDescription(package private) booleancheckout(DocumentsWriterPerThread perThread) Removes the given DWPT from the pool unless it's already been removed before.voidclose()private booleancontains(DocumentsWriterPerThread state) private void(package private) List<DocumentsWriterPerThread> filterAndLock(Predicate<DocumentsWriterPerThread> predicate) Filters all DWPTs the given predicate applies to and that can be checked out of the pool viacheckout(DocumentsWriterPerThread).(package private) DocumentsWriterPerThreadThis method is used by DocumentsWriter/FlushControl to obtain a DWPT to do an indexing operation (add/updateDocument).(package private) booleanisRegistered(DocumentsWriterPerThread perThread) Returnstrueif this DWPT is still part of the pooliterator()(package private) void(package private) voidprivate DocumentsWriterPerThreadReturns a new already lockedDocumentsWriterPerThread(package private) intsize()Returns the active number ofDocumentsWriterPerThreadinstances.(package private) voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
dwpts
-
freeList
-
dwptFactory
-
takenWriterPermits
private int takenWriterPermits -
closed
private volatile boolean closed
-
-
Constructor Details
-
DocumentsWriterPerThreadPool
DocumentsWriterPerThreadPool(Supplier<DocumentsWriterPerThread> dwptFactory)
-
-
Method Details
-
size
int size()Returns the active number ofDocumentsWriterPerThreadinstances. -
lockNewWriters
void lockNewWriters() -
unlockNewWriters
void unlockNewWriters() -
newWriter
Returns a new already lockedDocumentsWriterPerThread- Returns:
- a new
DocumentsWriterPerThread
-
getAndLock
DocumentsWriterPerThread getAndLock()This method is used by DocumentsWriter/FlushControl to obtain a DWPT to do an indexing operation (add/updateDocument). -
ensureOpen
private void ensureOpen() -
contains
-
marksAsFreeAndUnlock
-
iterator
- Specified by:
iteratorin interfaceIterable<DocumentsWriterPerThread>
-
filterAndLock
Filters all DWPTs the given predicate applies to and that can be checked out of the pool viacheckout(DocumentsWriterPerThread). All DWPTs returned from this method are already locked andisRegistered(DocumentsWriterPerThread)will returntruefor all returned DWPTs -
checkout
Removes the given DWPT from the pool unless it's already been removed before.- Returns:
trueiff the given DWPT has been removed. Otherwisefalse
-
isRegistered
Returnstrueif this DWPT is still part of the pool -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-