use of org.codice.ddf.ui.searchui.query.controller.search.CacheQueryRunnable in project ddf by codice.
the class SearchController method executeQuery.
/**
* Execute all of the queries contained within the {@link SearchRequest}.
*
* @param request {@link SearchRequest} containing a query for 1 or more sources
* @param session Cometd {@link ServerSession}
*/
public void executeQuery(final SearchRequest request, final ServerSession session, final Subject subject) {
final Search search = new Search(request, actionRegistry);
final Map<String, Result> results = Collections.synchronizedMap(new HashMap<String, Result>());
final Future<FilteringSolrIndex> solrIndexFuture;
if (shouldNormalizeRelevance(request)) {
// Create in memory Solr instance asynchronously
solrIndexFuture = executorService.submit(new FilteringSolrIndexCallable(request, filterAdapter));
} else {
solrIndexFuture = Futures.immediateFuture(null);
}
final Future cacheFuture;
if (!cacheDisabled) {
// Send any previously cached results
cacheFuture = executorService.submit(new CacheQueryRunnable(this, request, subject, search, session, results, solrIndexFuture));
} else {
cacheFuture = Futures.immediateFuture(null);
}
long deadline = System.currentTimeMillis() + request.getQuery().getTimeoutMillis();
Map<String, Future> futures = new HashMap<>(request.getSourceIds().size());
for (final String sourceId : request.getSourceIds()) {
// Send the latest results from each source
futures.put(sourceId, executorService.submit(new SourceQueryRunnable(this, sourceId, request, subject, results, search, session, cacheFuture, solrIndexFuture)));
}
for (Map.Entry<String, Future> entry : futures.entrySet()) {
executorService.submit(() -> {
String sourceId = entry.getKey();
Future future = entry.getValue();
try {
long timeRemaining = Math.max(0, deadline - System.currentTimeMillis());
future.get(timeRemaining, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
LOGGER.info("Query interrupted for source {}", sourceId, e);
failSource(request, session, search, sourceId, e);
} catch (TimeoutException e) {
LOGGER.info("Query timed out for source {}", sourceId, e);
failSource(request, session, search, sourceId, e);
} catch (ExecutionException e) {
LOGGER.info("Query failed for source {}", sourceId, e.getCause());
failSource(request, session, search, sourceId, e);
}
});
}
}
Aggregations