mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-06 21:00:22 +00:00
batch processor update
This commit is contained in:
parent
eb7bbfd75c
commit
61bb6785fc
@ -17,10 +17,13 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@ -52,13 +55,6 @@ public class BatchProcessor<T> {
|
||||
public synchronized void clearCurrentBatch() {
|
||||
batchingQueue.clear();
|
||||
}
|
||||
|
||||
public synchronized void flush(boolean blockUntilFinished) throws InterruptedException {
|
||||
asyncProcessBatch();
|
||||
if (blockUntilFinished) {
|
||||
lastProcessingFuture.wait(millisTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void add(T item) throws InterruptedException {
|
||||
batchingQueue.add(item);
|
||||
@ -67,14 +63,29 @@ public class BatchProcessor<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void flush(boolean blockUntilFinished) throws InterruptedException {
|
||||
asyncProcessBatch();
|
||||
if (blockUntilFinished) {
|
||||
waitCurrentFuture();
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void waitCurrentFuture() throws InterruptedException {
|
||||
synchronized (lastProcessingFuture) {
|
||||
if (!lastProcessingFuture.isDone()) {
|
||||
try {
|
||||
lastProcessingFuture.get(millisTimeout, TimeUnit.MILLISECONDS);
|
||||
} catch (ExecutionException | TimeoutException ex) {
|
||||
// ignore timeout
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void asyncProcessBatch() throws InterruptedException {
|
||||
if (!batchingQueue.isEmpty()) {
|
||||
// wait for previous processing to finish
|
||||
synchronized (lastProcessingFuture) {
|
||||
if (!lastProcessingFuture.isDone()) {
|
||||
lastProcessingFuture.wait(millisTimeout);
|
||||
}
|
||||
}
|
||||
waitCurrentFuture();
|
||||
|
||||
// if 'andThen' doesn't run, clear the processing queue
|
||||
processingQueue.clear();
|
||||
|
Loading…
x
Reference in New Issue
Block a user