Search in sources :

Example 1 with HistoryDownloader

use of org.locationtech.geogig.osm.internal.history.HistoryDownloader in project GeoGig by boundlessgeo.

the class OSMHistoryImport method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(args.numThreads > 0 && args.numThreads < 7, "numthreads must be between 1 and 6");
    ConsoleReader console = cli.getConsole();
    final String osmAPIUrl = resolveAPIURL();
    final long startIndex;
    final long endIndex = args.endIndex;
    if (args.resume) {
        GeoGIG geogig = cli.getGeogig();
        long lastChangeset = getCurrentBranchChangeset(geogig);
        startIndex = 1 + lastChangeset;
    } else {
        startIndex = args.startIndex;
    }
    console.println(String.format("Obtaining OSM changesets %,d to %,d from %s", startIndex, args.endIndex, osmAPIUrl));
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("osm-history-fetch-thread-%d").build();
    final ExecutorService executor = Executors.newFixedThreadPool(args.numThreads, threadFactory);
    final File targetDir = resolveTargetDir();
    console.println("Downloading to " + targetDir.getAbsolutePath());
    console.flush();
    HistoryDownloader downloader;
    downloader = new HistoryDownloader(osmAPIUrl, targetDir, startIndex, endIndex, executor);
    Envelope env = parseBbox();
    Predicate<Changeset> filter = parseFilter(env);
    downloader.setChangesetFilter(filter);
    try {
        importOsmHistory(cli, console, downloader, env);
    } finally {
        executor.shutdownNow();
        try {
            executor.awaitTermination(30, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new CommandFailedException(e);
        }
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) HistoryDownloader(org.locationtech.geogig.osm.internal.history.HistoryDownloader) ConsoleReader(jline.console.ConsoleReader) Envelope(com.vividsolutions.jts.geom.Envelope) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) File(java.io.File) Changeset(org.locationtech.geogig.osm.internal.history.Changeset) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Aggregations

ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Envelope (com.vividsolutions.jts.geom.Envelope)1 File (java.io.File)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 ConsoleReader (jline.console.ConsoleReader)1 GeoGIG (org.locationtech.geogig.api.GeoGIG)1 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)1 Changeset (org.locationtech.geogig.osm.internal.history.Changeset)1 HistoryDownloader (org.locationtech.geogig.osm.internal.history.HistoryDownloader)1