Search in sources :

Example 1 with FlowFileFilterResult

use of org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult in project nifi by apache.

the class StandardFlowFileQueue method poll.

@Override
public List<FlowFileRecord> poll(final FlowFileFilter filter, final Set<FlowFileRecord> expiredRecords) {
    long bytesPulled = 0L;
    int flowFilesPulled = 0;
    writeLock.lock();
    try {
        migrateSwapToActive();
        final long expirationMillis = expirationPeriod.get().getMillis();
        final List<FlowFileRecord> selectedFlowFiles = new ArrayList<>();
        final List<FlowFileRecord> unselected = new ArrayList<>();
        while (true) {
            FlowFileRecord flowFile = this.activeQueue.poll();
            if (flowFile == null) {
                break;
            }
            final boolean isExpired = isLaterThan(getExpirationDate(flowFile, expirationMillis));
            if (isExpired) {
                expiredRecords.add(flowFile);
                bytesPulled += flowFile.getSize();
                flowFilesPulled++;
                if (expiredRecords.size() >= MAX_EXPIRED_RECORDS_PER_ITERATION) {
                    break;
                } else {
                    continue;
                }
            } else if (flowFile.isPenalized()) {
                this.activeQueue.add(flowFile);
                flowFile = null;
                // just stop searching because the rest are all penalized.
                break;
            }
            final FlowFileFilterResult result = filter.filter(flowFile);
            if (result.isAccept()) {
                bytesPulled += flowFile.getSize();
                flowFilesPulled++;
                incrementUnacknowledgedQueueSize(1, flowFile.getSize());
                selectedFlowFiles.add(flowFile);
            } else {
                unselected.add(flowFile);
            }
            if (!result.isContinue()) {
                break;
            }
        }
        this.activeQueue.addAll(unselected);
        incrementActiveQueueSize(-flowFilesPulled, -bytesPulled);
        return selectedFlowFiles;
    } finally {
        writeLock.unlock("poll(Filter, Set)");
    }
}
Also used : FlowFileFilterResult(org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult) ArrayList(java.util.ArrayList) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord)

Aggregations

ArrayList (java.util.ArrayList)1 FlowFileRecord (org.apache.nifi.controller.repository.FlowFileRecord)1 FlowFileFilterResult (org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult)1