Search in sources :

Example 1 with BulkOpListener

use of org.locationtech.geogig.storage.BulkOpListener in project GeoGig by boundlessgeo.

the class WorkingTree method insertBlobs.

@SuppressWarnings("rawtypes")
private List<Future<Integer>> insertBlobs(final FeatureSource source, final Query baseQuery, final ExecutorService executorService, final ProgressListener listener, @Nullable final Long collectionSize, int nTasks, RevTreeBuilder2 builder) {
    int partitionSize = 0;
    BulkOpListener bulkOpListener;
    if (collectionSize == null) {
        nTasks = 1;
        partitionSize = Integer.MAX_VALUE;
        bulkOpListener = BulkOpListener.NOOP_LISTENER;
    } else {
        final int total = collectionSize.intValue();
        partitionSize = total / nTasks;
        bulkOpListener = new BulkOpListener() {

            int inserted = 0;

            @Override
            public synchronized void inserted(ObjectId object, @Nullable Integer storageSizeBytes) {
                listener.setProgress((float) (++inserted * 100) / total);
            }
        };
    }
    List<Future<Integer>> results = Lists.newArrayList();
    for (int i = 0; i < nTasks; i++) {
        Integer offset = nTasks == 1 ? null : i * partitionSize;
        Integer limit = nTasks == 1 ? null : partitionSize;
        if (i == nTasks - 1) {
            // let the last task take any remaining
            limit = null;
        // feature
        }
        results.add(executorService.submit(new BlobInsertTask(source, offset, limit, bulkOpListener, builder)));
    }
    return results;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Future(java.util.concurrent.Future) BulkOpListener(org.locationtech.geogig.storage.BulkOpListener)

Example 2 with BulkOpListener

use of org.locationtech.geogig.storage.BulkOpListener in project GeoGig by boundlessgeo.

the class BinaryPackedObjects method ingest.

/**
     * @return the number of objects parsed from the input stream
     */
public IngestResults ingest(final InputStream in, final Callback callback) {
    Iterator<RevObject> objects = streamToObjects(in);
    BulkOpListener listener = new BulkOpListener() {

        @Override
        public void inserted(final ObjectId objectId, @Nullable Integer storageSizeBytes) {
            callback.callback(new Supplier<RevObject>() {

                @Override
                public RevObject get() {
                    return database.get(objectId);
                }
            });
        }
    };
    CountingListener countingListener = BulkOpListener.newCountingListener();
    listener = BulkOpListener.composite(countingListener, listener);
    database.putAll(objects, listener);
    return new IngestResults(countingListener.inserted(), countingListener.found());
}
Also used : CountingListener(org.locationtech.geogig.storage.BulkOpListener.CountingListener) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) BulkOpListener(org.locationtech.geogig.storage.BulkOpListener) Nullable(javax.annotation.Nullable)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)2 BulkOpListener (org.locationtech.geogig.storage.BulkOpListener)2 Future (java.util.concurrent.Future)1 Nullable (javax.annotation.Nullable)1 RevObject (org.locationtech.geogig.api.RevObject)1 CountingListener (org.locationtech.geogig.storage.BulkOpListener.CountingListener)1