use of org.apache.druid.query.AbstractPrioritizedCallable in project druid by druid-io.
the class ConcurrentGrouper method parallelSortAndGetGroupersIterator.
private List<CloseableIterator<Entry<KeyType>>> parallelSortAndGetGroupersIterator() {
// The number of groupers is same with the number of processing threads in the executor
final List<ListenableFuture<CloseableIterator<Entry<KeyType>>>> futures = groupers.stream().map(grouper -> executor.submit(new AbstractPrioritizedCallable<CloseableIterator<Entry<KeyType>>>(priority) {
@Override
public CloseableIterator<Entry<KeyType>> call() {
return grouper.iterator(true);
}
})).collect(Collectors.toList());
ListenableFuture<List<CloseableIterator<Entry<KeyType>>>> future = Futures.allAsList(futures);
try {
final long timeout = queryTimeoutAt - System.currentTimeMillis();
return hasQueryTimeout ? future.get(timeout, TimeUnit.MILLISECONDS) : future.get();
} catch (InterruptedException | CancellationException e) {
GuavaUtils.cancelAll(true, future, futures);
throw new QueryInterruptedException(e);
} catch (TimeoutException e) {
GuavaUtils.cancelAll(true, future, futures);
throw new QueryTimeoutException();
} catch (ExecutionException e) {
GuavaUtils.cancelAll(true, future, futures);
throw new RuntimeException(e.getCause());
}
}
Aggregations