Search in sources :

Example 1 with PreOrderDiffWalk

use of org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk in project GeoGig by boundlessgeo.

the class DiffCount method _call.

@Override
protected DiffObjectCount _call() {
    checkState(oldRefSpec != null, "old ref spec not provided");
    checkState(newRefSpec != null, "new ref spec not provided");
    final RevTree oldTree = getTree(oldRefSpec);
    final RevTree newTree = getTree(newRefSpec);
    DiffObjectCount diffCount;
    StagingDatabase index = stagingDatabase();
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(oldTree, newTree, index, index);
    DiffCountConsumer counter = new DiffCountConsumer(index);
    PreOrderDiffWalk.Consumer filter = counter;
    if (!pathFilters.isEmpty()) {
        filter = new PathFilteringDiffConsumer(pathFilters, counter);
    }
    visitor.walk(filter);
    diffCount = counter.get();
    return diffCount;
}
Also used : DiffObjectCount(org.locationtech.geogig.api.plumbing.diff.DiffObjectCount) PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) DiffCountConsumer(org.locationtech.geogig.api.plumbing.diff.DiffCountConsumer) RevTree(org.locationtech.geogig.api.RevTree) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)

Example 2 with PreOrderDiffWalk

use of org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk in project GeoGig by boundlessgeo.

the class DiffTree method _call.

/**
     * Finds differences between the two specified trees.
     * 
     * @return an iterator to a set of differences between the two trees
     * @see DiffEntry
     */
@Override
protected Iterator<DiffEntry> _call() throws IllegalArgumentException {
    checkNotNull(oldRefSpec, "old version not specified");
    checkNotNull(newRefSpec, "new version not specified");
    final RevTree oldTree = resolveTree(oldRefSpec);
    final RevTree newTree = resolveTree(newRefSpec);
    if (oldTree.equals(newTree)) {
        return Iterators.emptyIterator();
    }
    ObjectDatabase leftSource = resolveSource(oldTree.getId());
    ObjectDatabase rightSource = resolveSource(newTree.getId());
    final PreOrderDiffWalk visitor = new PreOrderDiffWalk(oldTree, newTree, leftSource, rightSource);
    final BlockingQueue<DiffEntry> queue = new ArrayBlockingQueue<>(100);
    final DiffEntryProducer diffProducer = new DiffEntryProducer(queue);
    diffProducer.setReportTrees(this.reportTrees);
    diffProducer.setRecursive(this.recursive);
    final List<RuntimeException> producerErrors = new LinkedList<>();
    Thread producerThread = new Thread("DiffTree producer thread") {

        @Override
        public void run() {
            Consumer consumer = diffProducer;
            if (customFilter != null) {
                // evaluated the latest
                consumer = new PreOrderDiffWalk.FilteringConsumer(consumer, customFilter);
            }
            if (changeTypeFilter != null) {
                consumer = new ChangeTypeFilteringDiffConsumer(changeTypeFilter, consumer);
            }
            if (boundsFilter != null) {
                consumer = new BoundsFilteringDiffConsumer(boundsFilter, consumer, stagingDatabase());
            }
            if (!pathFilters.isEmpty()) {
                // evaluated the former
                consumer = new PathFilteringDiffConsumer(pathFilters, consumer);
            }
            try {
                visitor.walk(consumer);
            } catch (RuntimeException e) {
                LOGGER.error("Error traversing diffs", e);
                producerErrors.add(e);
            } finally {
                diffProducer.finished = true;
            }
        }
    };
    producerThread.setDaemon(true);
    producerThread.start();
    Iterator<DiffEntry> consumerIterator = new AbstractIterator<DiffEntry>() {

        @Override
        protected DiffEntry computeNext() {
            if (!producerErrors.isEmpty()) {
                throw new RuntimeException("Error in producer thread", producerErrors.get(0));
            }
            BlockingQueue<DiffEntry> entries = queue;
            boolean finished = diffProducer.isFinished();
            boolean empty = entries.isEmpty();
            while (!finished || !empty) {
                try {
                    DiffEntry entry = entries.poll(10, TimeUnit.MILLISECONDS);
                    if (entry != null) {
                        return entry;
                    }
                    finished = diffProducer.isFinished();
                    empty = entries.isEmpty();
                } catch (InterruptedException e) {
                    throw Throwables.propagate(e);
                }
            }
            return endOfData();
        }

        @Override
        protected void finalize() {
            diffProducer.finished = true;
        }
    };
    return consumerIterator;
}
Also used : PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) LinkedList(java.util.LinkedList) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Consumer(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.Consumer) ForwardingConsumer(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.ForwardingConsumer) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer) BoundsFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.BoundsFilteringDiffConsumer) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) BoundsFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.BoundsFilteringDiffConsumer) AbstractIterator(com.google.common.collect.AbstractIterator) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 3 with PreOrderDiffWalk

use of org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk in project GeoGig by boundlessgeo.

the class DiffBounds method _call.

@Override
protected DiffSummary<BoundingBox, BoundingBox> _call() {
    checkArgument(cached && oldVersion == null || !cached, String.format("compare index allows only one revision to check against, got %s / %s", oldVersion, newVersion));
    checkArgument(newVersion == null || oldVersion != null, "If new rev spec is specified then old rev spec is mandatory");
    final String leftRefSpec = fromNullable(oldVersion).or(Ref.HEAD);
    final String rightRefSpec = fromNullable(newVersion).or(cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD);
    RevTree left = resolveTree(leftRefSpec);
    RevTree right = resolveTree(rightRefSpec);
    ObjectDatabase leftSource = resolveSafeDb(leftRefSpec);
    ObjectDatabase rightSource = resolveSafeDb(rightRefSpec);
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    CoordinateReferenceSystem crs = resolveCrs();
    BoundsWalk walk = new BoundsWalk(crs, stagingDatabase());
    PreOrderDiffWalk.Consumer consumer = walk;
    if (!pathFilters.isEmpty()) {
        consumer = new PathFilteringDiffConsumer(pathFilters, walk);
    }
    visitor.walk(consumer);
    DiffSummary<BoundingBox, BoundingBox> diffBounds = walk.getResult();
    return diffBounds;
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) BoundingBox(org.opengis.geometry.BoundingBox) PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)

Aggregations

RevTree (org.locationtech.geogig.api.RevTree)3 PathFilteringDiffConsumer (org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)3 PreOrderDiffWalk (org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk)3 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)2 AbstractIterator (com.google.common.collect.AbstractIterator)1 LinkedList (java.util.LinkedList)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BoundsFilteringDiffConsumer (org.locationtech.geogig.api.plumbing.diff.BoundsFilteringDiffConsumer)1 DiffCountConsumer (org.locationtech.geogig.api.plumbing.diff.DiffCountConsumer)1 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)1 DiffObjectCount (org.locationtech.geogig.api.plumbing.diff.DiffObjectCount)1 Consumer (org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.Consumer)1 ForwardingConsumer (org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.ForwardingConsumer)1 StagingDatabase (org.locationtech.geogig.storage.StagingDatabase)1 BoundingBox (org.opengis.geometry.BoundingBox)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1