@Override public ListFlowFileStatus cancelListFlowFileRequest(final String requestIdentifier) { logger.info("Canceling ListFlowFile Request with ID {}", requestIdentifier); final ListFlowFileRequest request = listRequestMap.remove(requestIdentifier); if (request != null) { request.cancel(); } return request; }
for (final Map.Entry<String, ListFlowFileRequest> entry : listRequestMap.entrySet()) { final ListFlowFileRequest request = entry.getValue(); final boolean completed = request.getState() == ListFlowFileState.COMPLETE || request.getState() == ListFlowFileState.FAILURE; if (completed && System.currentTimeMillis() - request.getLastUpdated() > TimeUnit.MINUTES.toMillis(5L)) { toDrop.add(entry.getKey()); final ListFlowFileRequest listRequest = new ListFlowFileRequest(requestIdentifier, maxResults, size());
@Override public void run() { int position = 0; final List<FlowFileSummary> summaries = new ArrayList<>(); // Create an ArrayList that contains all of the contents of the active queue. // We do this so that we don't have to hold the lock any longer than absolutely necessary. // We cannot simply pull the first 'maxResults' records from the queue, however, because the // Iterator provided by PriorityQueue does not return records in order. So we would have to either // use a writeLock and 'pop' the first 'maxResults' records off the queue or use a read lock and // do a shallow copy of the queue. The shallow copy is generally quicker because it doesn't have to do // the sorting to put the records back. So even though this has an expensive of Java Heap to create the // extra collection, we are making this trade-off to avoid locking the queue any longer than required. final List<FlowFileRecord> allFlowFiles = getListableFlowFiles(); final QueuePrioritizer prioritizer = new QueuePrioritizer(getPriorities()); listRequest.setState(ListFlowFileState.CALCULATING_LIST); // sort the FlowFileRecords so that we have the list in the same order as on the queue. allFlowFiles.sort(prioritizer); for (final FlowFileRecord flowFile : allFlowFiles) { summaries.add(summarize(flowFile, ++position)); if (summaries.size() >= maxResults) { break; } } logger.debug("{} Finished listing FlowFiles for active queue with a total of {} results out of {} FlowFiles", this, summaries.size(), allFlowFiles.size()); listRequest.setFlowFileSummaries(summaries); listRequest.setState(ListFlowFileState.COMPLETE); } }, "List FlowFiles for Connection " + getIdentifier());