Search in sources :

Example 31 with Closer

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);
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer)

Example 32 with 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();
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer)

Example 33 with Closer

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"));
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer)

Example 34 with Closer

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();
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer)

Example 35 with Closer

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);
    }
}
Also used : Closer(org.apache.druid.java.util.common.io.Closer) IOException(java.io.IOException) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

Closer (org.apache.druid.java.util.common.io.Closer)58 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)17 File (java.io.File)12 ISE (org.apache.druid.java.util.common.ISE)10 List (java.util.List)9 GroupByQueryConfig (org.apache.druid.query.groupby.GroupByQueryConfig)8 ByteBuffer (java.nio.ByteBuffer)7 Nullable (javax.annotation.Nullable)7 QueryableIndex (org.apache.druid.segment.QueryableIndex)7 Test (org.junit.Test)7 GroupByQueryRunnerFactory (org.apache.druid.query.groupby.GroupByQueryRunnerFactory)6 ReferenceCountingSegment (org.apache.druid.segment.ReferenceCountingSegment)6 ImmutableList (com.google.common.collect.ImmutableList)5 Map (java.util.Map)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Closeable (java.io.Closeable)4 ExecutionException (java.util.concurrent.ExecutionException)4 CloseableIterator (org.apache.druid.java.util.common.parsers.CloseableIterator)4 BaseProgressIndicator (org.apache.druid.segment.BaseProgressIndicator)4