mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +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.List;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,13 +55,6 @@ public class BatchProcessor<T> {
|
|||||||
public synchronized void clearCurrentBatch() {
|
public synchronized void clearCurrentBatch() {
|
||||||
batchingQueue.clear();
|
batchingQueue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void flush(boolean blockUntilFinished) throws InterruptedException {
|
|
||||||
asyncProcessBatch();
|
|
||||||
if (blockUntilFinished) {
|
|
||||||
lastProcessingFuture.wait(millisTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void add(T item) throws InterruptedException {
|
public synchronized void add(T item) throws InterruptedException {
|
||||||
batchingQueue.add(item);
|
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 {
|
private synchronized void asyncProcessBatch() throws InterruptedException {
|
||||||
if (!batchingQueue.isEmpty()) {
|
if (!batchingQueue.isEmpty()) {
|
||||||
// wait for previous processing to finish
|
// wait for previous processing to finish
|
||||||
synchronized (lastProcessingFuture) {
|
waitCurrentFuture();
|
||||||
if (!lastProcessingFuture.isDone()) {
|
|
||||||
lastProcessingFuture.wait(millisTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if 'andThen' doesn't run, clear the processing queue
|
// if 'andThen' doesn't run, clear the processing queue
|
||||||
processingQueue.clear();
|
processingQueue.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user