- 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
DocumentsWriterPerThreadPool
controlsDocumentsWriterPerThread
instances and their thread assignments during indexing. EachDocumentsWriterPerThread
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 aDocumentsWriterPerThread
to make progress. Depending on theDocumentsWriterPerThreadPool
implementationDocumentsWriterPerThread
assignments might differ from document to document.Once a
DocumentsWriterPerThread
is selected for flush theDocumentsWriterPerThread
will 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 boolean
closed
private java.util.function.Supplier<DocumentsWriterPerThread>
dwptFactory
private java.util.Set<DocumentsWriterPerThread>
dwpts
private LockableConcurrentApproximatePriorityQueue<DocumentsWriterPerThread>
freeList
private int
takenWriterPermits
-
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) boolean
checkout(DocumentsWriterPerThread perThread)
Removes the given DWPT from the pool unless it's already been removed before.void
close()
private boolean
contains(DocumentsWriterPerThread state)
private void
ensureOpen()
(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) DocumentsWriterPerThread
getAndLock()
This method is used by DocumentsWriter/FlushControl to obtain a DWPT to do an indexing operation (add/updateDocument).(package private) boolean
isRegistered(DocumentsWriterPerThread perThread)
Returnstrue
if this DWPT is still part of the pooljava.util.Iterator<DocumentsWriterPerThread>
iterator()
(package private) void
lockNewWriters()
(package private) void
marksAsFreeAndUnlock(DocumentsWriterPerThread state)
private DocumentsWriterPerThread
newWriter()
Returns a new already lockedDocumentsWriterPerThread
(package private) int
size()
Returns the active number ofDocumentsWriterPerThread
instances.(package private) void
unlockNewWriters()
-
-
-
Field Detail
-
dwpts
private final java.util.Set<DocumentsWriterPerThread> dwpts
-
freeList
private final LockableConcurrentApproximatePriorityQueue<DocumentsWriterPerThread> freeList
-
dwptFactory
private final java.util.function.Supplier<DocumentsWriterPerThread> dwptFactory
-
takenWriterPermits
private int takenWriterPermits
-
closed
private volatile boolean closed
-
-
Constructor Detail
-
DocumentsWriterPerThreadPool
DocumentsWriterPerThreadPool(java.util.function.Supplier<DocumentsWriterPerThread> dwptFactory)
-
-
Method Detail
-
size
int size()
Returns the active number ofDocumentsWriterPerThread
instances.
-
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()
-
contains
private boolean contains(DocumentsWriterPerThread state)
-
marksAsFreeAndUnlock
void marksAsFreeAndUnlock(DocumentsWriterPerThread state)
-
iterator
public java.util.Iterator<DocumentsWriterPerThread> iterator()
- Specified by:
iterator
in 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 returntrue
for all returned DWPTs
-
checkout
boolean checkout(DocumentsWriterPerThread perThread)
Removes the given DWPT from the pool unless it's already been removed before.- Returns:
true
iff the given DWPT has been removed. Otherwisefalse
-
isRegistered
boolean isRegistered(DocumentsWriterPerThread perThread)
Returnstrue
if this DWPT is still part of the pool
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
-