use of org.apache.druid.java.util.common.io.Closer in project druid by druid-io.
the class CloseableIterators method mergeSorted.
public static <T> CloseableIterator<T> mergeSorted(List<? extends CloseableIterator<? extends T>> iterators, Comparator<T> comparator) {
Preconditions.checkNotNull(comparator);
final Closer closer = Closer.create();
iterators.forEach(closer::register);
final Iterator<T> innerIterator = Iterators.mergeSorted(iterators, comparator);
return wrap(innerIterator, closer);
}
use of org.apache.druid.java.util.common.io.Closer in project druid by druid-io.
the class MergeSequence method closeAll.
private static <T> void closeAll(final PriorityQueue<Yielder<T>> pQueue) throws IOException {
Closer closer = Closer.create();
while (!pQueue.isEmpty()) {
final Yielder<T> yielder = pQueue.poll();
if (yielder != null) {
// Note: yielder can be null if our comparator threw an exception during queue.add.
closer.register(yielder);
}
}
closer.close();
}
use of org.apache.druid.java.util.common.io.Closer in project druid by druid-io.
the class ParallelMergeCombiningSequence method closeAllCursors.
private static <T> void closeAllCursors(final Collection<BatchedResultsCursor<T>> cursors) {
Closer closer = Closer.create();
closer.registerAll(cursors);
CloseableUtils.closeAndSuppressExceptions(closer, e -> LOG.warn(e, "Failed to close result cursors"));
}
use of org.apache.druid.java.util.common.io.Closer in project druid by druid-io.
the class CloseableUtils method closeAll.
/**
* Close all the provided {@param closeables}, from first to last.
*/
public static <T extends Closeable> void closeAll(Iterable<T> closeables) throws IOException {
final Closer closer = Closer.create();
// Register in reverse order, so we close from first to last.
closer.registerAll(Lists.reverse(Lists.newArrayList(closeables)));
closer.close();
}
use of org.apache.druid.java.util.common.io.Closer in project druid by druid-io.
the class ResourcePool method close.
@Override
public void close() {
closed.set(true);
final ConcurrentMap<K, ImmediateCreationResourceHolder<K, V>> mapView = pool.asMap();
Closer closer = Closer.create();
for (Iterator<Map.Entry<K, ImmediateCreationResourceHolder<K, V>>> iterator = mapView.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<K, ImmediateCreationResourceHolder<K, V>> e = iterator.next();
iterator.remove();
closer.register(e.getValue());
}
try {
closer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations