flag calc
This commit is contained in:
parent
bf693c3fbc
commit
aaf91195b1
3 changed files with 34 additions and 53 deletions
|
|
@ -86,7 +86,7 @@ public class PipelinePackageManager {
|
|||
Pipeline pipeline = PipeLineBuilderV2.first(saveSubjectQueueFactory.getObject(), idEnricherQueueFactory.getObject())
|
||||
.handler(saveSubjectHandler)
|
||||
.poison(SubjectPayload.POISON)
|
||||
.handlerResult(flagsEnricherV2)
|
||||
// .handlerResult(flagsEnricherV2)
|
||||
.andThen()
|
||||
.stage(sendSignalQueueFactory.getObject())
|
||||
.handler(fidIdEnricherHandler)
|
||||
|
|
|
|||
|
|
@ -124,10 +124,10 @@ public class Stage<X extends StagePayload, Z extends StagePayload> implements Ru
|
|||
|
||||
void putQuiet(BlockingQueue<Z> q, Z b) {
|
||||
try {
|
||||
q.put(b);
|
||||
if (consumer != null) {
|
||||
consumer.accept(b);
|
||||
}
|
||||
q.put(b);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.nio.charset.Charset;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -39,15 +39,31 @@ public final class XmlMergeCoordinator implements IPipeLineTerminator<PartFilePa
|
|||
this.mergedDir = Path.of(config.getLoadDir() + File.separator + "tmp_folder" + File.separator + "merged" + File.separator);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setPollingQueue(BlockingQueue<PartFilePayload> mergerQueue) {
|
||||
this.inQueue = mergerQueue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SignalXmlFilePayload> doneFuture() {
|
||||
return done;
|
||||
public void run() {
|
||||
try {
|
||||
Files.createDirectories(mergedDir);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
PartFilePayload part = inQueue.poll(5, TimeUnit.SECONDS);
|
||||
if (part == null) {
|
||||
continue;
|
||||
}
|
||||
if (part.isPoison()) {
|
||||
log.debug("Got poison");
|
||||
done.complete(new SignalXmlFilePayload(out));
|
||||
return;
|
||||
}
|
||||
mergeBatch(Collections.singletonList(part));
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (Exception e) {
|
||||
log.error("Error: {}", ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeBatch(List<PartFilePayload> inputs) throws Exception {
|
||||
|
|
@ -71,7 +87,7 @@ public final class XmlMergeCoordinator implements IPipeLineTerminator<PartFilePa
|
|||
w.close();
|
||||
}
|
||||
for (PartFilePayload p : inputs) Files.deleteIfExists(p.getPartPath());
|
||||
inputs.clear();
|
||||
// inputs.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -121,47 +137,12 @@ public final class XmlMergeCoordinator implements IPipeLineTerminator<PartFilePa
|
|||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<PartFilePayload> batch = new ArrayList<>(batchSize);
|
||||
try {
|
||||
Files.createDirectories(mergedDir);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
PartFilePayload part = inQueue.poll(5, TimeUnit.SECONDS);
|
||||
public void setPollingQueue(BlockingQueue<PartFilePayload> mergerQueue) {
|
||||
this.inQueue = mergerQueue;
|
||||
}
|
||||
|
||||
if (part == null) {
|
||||
continue;
|
||||
}
|
||||
if (part.isPoison()) {
|
||||
done.complete(new SignalXmlFilePayload(out));
|
||||
return;
|
||||
}
|
||||
batch.add(part);
|
||||
// добираем до batchSize, но не ждём бесконечно
|
||||
while (batch.size() < batchSize) {
|
||||
PartFilePayload p = inQueue.poll(1, TimeUnit.SECONDS);
|
||||
if (p == null) {
|
||||
break;
|
||||
}
|
||||
if (p.isPoison()) {
|
||||
mergeBatch(batch);
|
||||
done.complete(new SignalXmlFilePayload(out));
|
||||
return;
|
||||
}
|
||||
batch.add(p);
|
||||
}
|
||||
if (!batch.isEmpty()) {
|
||||
mergeBatch(batch);
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (Exception e) {
|
||||
log.error("Error: {}", ExceptionUtils.getStackTrace(e));
|
||||
batch.clear();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public CompletableFuture<SignalXmlFilePayload> doneFuture() {
|
||||
return done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue