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;
}
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());
}
Aggregations