Class BatchingExecutor<P extends BatchedWorkProcessor,W extends BatchedWork<? super P>>
- java.lang.Object
-
- org.hibernate.search.engine.backend.orchestration.spi.BatchingExecutor<P,W>
-
public final class BatchingExecutor<P extends BatchedWorkProcessor,W extends BatchedWork<? super P>> extends Object
An executor of works that accepts works from multiple threads, puts them in a queue, and processes them in batches in a single background thread.Useful when works can be merged together for optimization purposes (bulking in Elasticsearch), or when they should never be executed in parallel (writes to a Lucene index).
-
-
Constructor Summary
Constructors Constructor Description BatchingExecutor(String name, P processor, int maxTasksPerBatch, boolean fair, FailureHandler failureHandler, Consumer<? super W> blockingRetryProducer)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CompletableFuture<?>completion()voidstart(SimpleScheduledExecutor executorService)Start the executor, allowing works to be submitted throughsubmit(BatchedWork, OperationSubmitter).voidstop()Stop the executor, no longer allowing works to be submitted throughsubmit(BatchedWork, OperationSubmitter).voidsubmit(W work)Deprecated.Usesubmit(BatchedWork, OperationSubmitter)instead.voidsubmit(W work, OperationSubmitter operationSubmitter)Submit a work for execution.StringtoString()
-
-
-
Constructor Detail
-
BatchingExecutor
public BatchingExecutor(String name, P processor, int maxTasksPerBatch, boolean fair, FailureHandler failureHandler, Consumer<? super W> blockingRetryProducer)
- Parameters:
name- The name of the executor thread (and of this executor when reporting errors)processor- A task processor. May not be thread-safe.maxTasksPerBatch- The maximum number of tasks to process in a single batch. Higher values mean more opportunity for the processor to optimize execution, but higher heap consumption.fair- iftruetasks are always submitted to the processor in FIFO order, iffalsetasks submitted when the internal queue is full may be submitted out of order.failureHandler- A failure handler to report failures of the background thread.blockingRetryProducer- A retry work producer that would be called in case of offloading operation submitter and full queue.
-
-
Method Detail
-
start
public void start(SimpleScheduledExecutor executorService)
Start the executor, allowing works to be submitted throughsubmit(BatchedWork, OperationSubmitter).- Parameters:
executorService- An executor service with at least one thread.
-
stop
public void stop()
Stop the executor, no longer allowing works to be submitted throughsubmit(BatchedWork, OperationSubmitter).This will remove pending works from the queue.
-
submit
@Deprecated public void submit(W work) throws InterruptedException
Deprecated.Usesubmit(BatchedWork, OperationSubmitter)instead.- Throws:
InterruptedException
-
submit
public void submit(W work, OperationSubmitter operationSubmitter) throws InterruptedException
Submit a work for execution.Must not be called when the executor is stopped.
- Parameters:
work- A work to execute.operationSubmitter- How to handle request to submit operation when the queue is full.- Throws:
InterruptedException- If the current thread is interrupted while enqueuing the work.
-
completion
public CompletableFuture<?> completion()
- Returns:
- A future that completes when all works submitted to the executor so far are completely executed. Works submitted to the executor after entering this method may delay the wait.
-
-