Package org.apache.lucene.index
Class DocumentsWriterPerThreadPool
- java.lang.Object
-
- org.apache.lucene.index.DocumentsWriterPerThreadPool
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Iterable<DocumentsWriterPerThread>
final class DocumentsWriterPerThreadPool extends java.lang.Object implements java.lang.Iterable<DocumentsWriterPerThread>, java.io.Closeable
DocumentsWriterPerThreadPoolcontrolsDocumentsWriterPerThreadinstances and their thread assignments during indexing. EachDocumentsWriterPerThreadis 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 aDocumentsWriterPerThreadto make progress. Depending on theDocumentsWriterPerThreadPoolimplementationDocumentsWriterPerThreadassignments might differ from document to document.Once a
DocumentsWriterPerThreadis selected for flush theDocumentsWriterPerThreadwill be checked out of the thread pool and won't be reused for indexing. Seecheckout(DocumentsWriterPerThread).
-
-
Field Summary
Fields Modifier and Type Field Description private booleanclosedprivate java.util.function.Supplier<DocumentsWriterPerThread>dwptFactoryprivate java.util.Set<DocumentsWriterPerThread>dwptsprivate java.util.Deque<DocumentsWriterPerThread>freeListprivate inttakenWriterPermits
-
Constructor Summary
Constructors Constructor Description DocumentsWriterPerThreadPool(java.util.function.Supplier<DocumentsWriterPerThread> dwptFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) booleancheckout(DocumentsWriterPerThread perThread)Removes the given DWPT from the pool unless it's already been removed before.voidclose()private voidensureOpen()(package private) java.util.List<DocumentsWriterPerThread>filterAndLock(java.util.function.Predicate<DocumentsWriterPerThread> predicate)Filters all DWPTs the given predicate applies to and that can be checked out of the pool viacheckout(DocumentsWriterPerThread).(package private) DocumentsWriterPerThreadgetAndLock()This 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 pooljava.util.Iterator<DocumentsWriterPerThread>iterator()(package private) voidlockNewWriters()(package private) voidmarksAsFreeAndUnlock(DocumentsWriterPerThread state)private DocumentsWriterPerThreadnewWriter()Returns a new already lockedDocumentsWriterPerThread(package private) intsize()Returns the active number ofDocumentsWriterPerThreadinstances.(package private) voidunlockNewWriters()
-
-
-
Field Detail
-
dwpts
private final java.util.Set<DocumentsWriterPerThread> dwpts
-
freeList
private final java.util.Deque<DocumentsWriterPerThread> freeList
-
dwptFactory
private final java.util.function.Supplier<DocumentsWriterPerThread> dwptFactory
-
takenWriterPermits
private int takenWriterPermits
-
closed
private boolean closed
-
-
Constructor Detail
-
DocumentsWriterPerThreadPool
DocumentsWriterPerThreadPool(java.util.function.Supplier<DocumentsWriterPerThread> dwptFactory)
-
-
Method Detail
-
size
int size()
Returns the active number ofDocumentsWriterPerThreadinstances.
-
lockNewWriters
void lockNewWriters()
-
unlockNewWriters
void unlockNewWriters()
-
newWriter
private DocumentsWriterPerThread 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()
-
marksAsFreeAndUnlock
void marksAsFreeAndUnlock(DocumentsWriterPerThread state)
-
iterator
public java.util.Iterator<DocumentsWriterPerThread> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<DocumentsWriterPerThread>
-
filterAndLock
java.util.List<DocumentsWriterPerThread> filterAndLock(java.util.function.Predicate<DocumentsWriterPerThread> predicate)
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
boolean checkout(DocumentsWriterPerThread perThread)
Removes the given DWPT from the pool unless it's already been removed before.- Returns:
trueiff the given DWPT has been removed. Otherwisefalse
-
isRegistered
boolean isRegistered(DocumentsWriterPerThread perThread)
Returnstrueif this DWPT is still part of the pool
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-