use of io.engineblock.activityapi.cyclelog.buffers.results.CycleResultArray in project engineblock by engineblock.
the class ReorderingConcurrentResultBuffer method onCycleResultSegment.
@Override
public synchronized void onCycleResultSegment(CycleResultsSegment segment) {
if (resultFilter != null) {
segment = segment.filter(resultFilter);
}
if (!(segment instanceof CanSortCycles)) {
segment = new CycleResultArray(segment);
}
((CanSortCycles) segment).sort();
segments.add(segment);
segmentCount++;
currentCount += segment.getCount();
if (currentCount >= threshold) {
logger.trace("Reordering threshold met: " + currentCount + "/" + threshold + ", sorting and pushing. (" + segments.size() + " segments)");
Collections.sort(segments);
while (currentCount >= threshold) {
CycleResultsSegment head = segments.removeFirst();
downstream.onCycleResultSegment(head);
segmentCount--;
currentCount -= head.getCount();
}
}
}
Aggregations