Search in sources :

Example 46 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project jackrabbit-oak by apache.

the class ChildNodeStateProvider method children.

Iterator<NodeStateEntry> children(boolean preferred) {
    PeekingIterator<NodeStateEntry> pitr = Iterators.peekingIterator(entries.iterator());
    if (!pitr.hasNext()) {
        return emptyIterator();
    }
    // Skip till current entry
    while (pitr.hasNext() && !pitr.peek().getPath().equals(path)) {
        pitr.next();
    }
    // Skip past the current find
    checkState(pitr.hasNext() && path.equals(pitr.next().getPath()), "Did not found path [%s] in leftover iterator. Possibly node state accessed " + "after main iterator has moved past it", path);
    // Prepare an iterator to fetch all child node paths i.e. immediate and there children
    return new AbstractIterator<NodeStateEntry>() {

        @Override
        protected NodeStateEntry computeNext() {
            while (pitr.hasNext() && isAncestor(path, pitr.peek().getPath())) {
                NodeStateEntry nextEntry = pitr.next();
                String nextEntryPath = nextEntry.getPath();
                if (isImmediateChild(nextEntryPath)) {
                    String nextEntryName = PathUtils.getName(nextEntryPath);
                    if (preferred && !preferredPathElements.contains(nextEntryName)) {
                        return endOfData();
                    }
                    return nextEntry;
                }
            }
            return endOfData();
        }
    };
}
Also used : NodeStateEntry(org.apache.jackrabbit.oak.index.indexer.document.NodeStateEntry) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 47 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project jackrabbit-oak by apache.

the class FlatFileStore method createBaseIterator.

private Iterator<NodeStateEntry> createBaseIterator() {
    LineIterator itr = new LineIterator(createReader(storeFile, compressionEnabled));
    closer.register(itr::close);
    return new AbstractIterator<NodeStateEntry>() {

        @Override
        protected NodeStateEntry computeNext() {
            if (itr.hasNext()) {
                return convert(itr.nextLine());
            }
            // End of iterator then close it
            LineIterator.closeQuietly(itr);
            return endOfData();
        }
    };
}
Also used : AbstractIterator(com.google.common.collect.AbstractIterator) LineIterator(org.apache.commons.io.LineIterator)

Example 48 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project atlasdb by palantir.

the class InMemoryKeyValueService method getRangeInternal.

private <T> ClosableIterator<RowResult<T>> getRangeInternal(TableReference tableRef, final RangeRequest range, final ResultProducer<T> resultProducer) {
    ConcurrentNavigableMap<Key, byte[]> tableMap = getTableMap(tableRef).entries;
    if (range.isReverse()) {
        tableMap = tableMap.descendingMap();
    }
    if (range.getStartInclusive().length != 0) {
        if (range.isReverse()) {
            Cell startCell = Cells.createLargestCellForRow(range.getStartInclusive());
            tableMap = tableMap.tailMap(new Key(startCell, Long.MIN_VALUE));
        } else {
            Cell startCell = Cells.createSmallestCellForRow(range.getStartInclusive());
            tableMap = tableMap.tailMap(new Key(startCell, Long.MIN_VALUE));
        }
    }
    if (range.getEndExclusive().length != 0) {
        if (range.isReverse()) {
            Cell endCell = Cells.createLargestCellForRow(range.getEndExclusive());
            tableMap = tableMap.headMap(new Key(endCell, Long.MAX_VALUE));
        } else {
            Cell endCell = Cells.createSmallestCellForRow(range.getEndExclusive());
            tableMap = tableMap.headMap(new Key(endCell, Long.MAX_VALUE));
        }
    }
    final PeekingIterator<Entry<Key, byte[]>> it = Iterators.peekingIterator(tableMap.entrySet().iterator());
    return ClosableIterators.wrap(new AbstractIterator<RowResult<T>>() {

        @Override
        protected RowResult<T> computeNext() {
            while (true) {
                if (!it.hasNext()) {
                    return endOfData();
                }
                ImmutableSortedMap.Builder<byte[], T> result = ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator());
                Key key = it.peek().getKey();
                byte[] row = key.row;
                Iterator<Entry<Key, byte[]>> cellIter = takeCell(it, key);
                collectValueForTimestamp(key.col, cellIter, result, range, resultProducer);
                while (it.hasNext()) {
                    if (!it.peek().getKey().matchesRow(row)) {
                        break;
                    }
                    key = it.peek().getKey();
                    cellIter = takeCell(it, key);
                    collectValueForTimestamp(key.col, cellIter, result, range, resultProducer);
                }
                SortedMap<byte[], T> columns = result.build();
                if (!columns.isEmpty()) {
                    return RowResult.create(row, columns);
                }
            }
        }
    });
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Entry(java.util.Map.Entry) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ClosableIterator(com.palantir.common.base.ClosableIterator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) PeekingIterator(com.google.common.collect.PeekingIterator) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 49 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project incubator-gobblin by apache.

the class HiveDatasetFinder method getDatasetsIterator.

@Override
public Iterator<HiveDataset> getDatasetsIterator() throws IOException {
    return new AbstractIterator<HiveDataset>() {

        private Iterator<DbAndTable> tables = getTables().iterator();

        @Override
        protected HiveDataset computeNext() {
            while (this.tables.hasNext()) {
                DbAndTable dbAndTable = this.tables.next();
                try (AutoReturnableObject<IMetaStoreClient> client = HiveDatasetFinder.this.clientPool.getClient()) {
                    Table table = client.get().getTable(dbAndTable.getDb(), dbAndTable.getTable());
                    Config datasetConfig = getDatasetConfig(table);
                    if (ConfigUtils.getBoolean(datasetConfig, HIVE_DATASET_IS_BLACKLISTED_KEY, DEFAULT_HIVE_DATASET_IS_BLACKLISTED_KEY)) {
                        continue;
                    }
                    if (HiveDatasetFinder.this.eventSubmitter.isPresent()) {
                        SlaEventSubmitter.builder().datasetUrn(dbAndTable.toString()).eventSubmitter(HiveDatasetFinder.this.eventSubmitter.get()).eventName(DATASET_FOUND).build().submit();
                    }
                    return createHiveDataset(table, datasetConfig);
                } catch (IllegalArgumentException e) {
                    Throwables.propagate(e);
                } catch (Throwable t) {
                    log.error(String.format("Failed to create HiveDataset for table %s.%s", dbAndTable.getDb(), dbAndTable.getTable()), t);
                    if (HiveDatasetFinder.this.eventSubmitter.isPresent()) {
                        SlaEventSubmitter.builder().datasetUrn(dbAndTable.toString()).eventSubmitter(HiveDatasetFinder.this.eventSubmitter.get()).eventName(DATASET_ERROR).additionalMetadata(FAILURE_CONTEXT, t.toString()).build().submit();
                    }
                }
            }
            return endOfData();
        }
    };
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) Config(com.typesafe.config.Config) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) AbstractIterator(com.google.common.collect.AbstractIterator) IMetaStoreClient(org.apache.hadoop.hive.metastore.IMetaStoreClient)

Example 50 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project guava by google.

the class DirectedGraphConnections method incidentEdgeIterator.

@Override
public Iterator<EndpointPair<N>> incidentEdgeIterator(N thisNode) {
    checkNotNull(thisNode);
    Iterator<EndpointPair<N>> resultWithDoubleSelfLoop;
    if (orderedNodeConnections == null) {
        resultWithDoubleSelfLoop = Iterators.concat(Iterators.transform(predecessors().iterator(), (N predecessor) -> EndpointPair.ordered(predecessor, thisNode)), Iterators.transform(successors().iterator(), (N successor) -> EndpointPair.ordered(thisNode, successor)));
    } else {
        resultWithDoubleSelfLoop = Iterators.transform(orderedNodeConnections.iterator(), (NodeConnection<N> connection) -> {
            if (connection instanceof NodeConnection.Succ) {
                return EndpointPair.ordered(thisNode, connection.node);
            } else {
                return EndpointPair.ordered(connection.node, thisNode);
            }
        });
    }
    AtomicBoolean alreadySeenSelfLoop = new AtomicBoolean(false);
    return new AbstractIterator<EndpointPair<N>>() {

        @Override
        @CheckForNull
        protected EndpointPair<N> computeNext() {
            while (resultWithDoubleSelfLoop.hasNext()) {
                EndpointPair<N> edge = resultWithDoubleSelfLoop.next();
                if (edge.nodeU().equals(edge.nodeV())) {
                    if (!alreadySeenSelfLoop.getAndSet(true)) {
                        return edge;
                    }
                } else {
                    return edge;
                }
            }
            return endOfData();
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractIterator(com.google.common.collect.AbstractIterator)

Aggregations

AbstractIterator (com.google.common.collect.AbstractIterator)55 IOException (java.io.IOException)15 Iterator (java.util.Iterator)14 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 File (java.io.File)5 EOFException (java.io.EOFException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 SMALLINT (com.facebook.presto.common.type.SmallintType.SMALLINT)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Deque (java.util.Deque)3 Set (java.util.Set)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 Test (org.junit.Test)3 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)2 TopicId (co.cask.cdap.proto.id.TopicId)2