Ticket #20416: 20416.2.patch

File 20416.2.patch, 6.3 KB (added by GerdP, 4 years ago)

like before, but without the change reg NullProgressMonitor.INSTANCE

  • src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

     
    323323                threadsNumber, Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY));
    324324        CompletionService<FetchResult> ecs = new ExecutorCompletionService<>(exec);
    325325        List<Future<FetchResult>> jobs = new ArrayList<>();
    326         while (!toFetch.isEmpty()) {
     326        while (!toFetch.isEmpty() && !isCanceled()) {
    327327            jobs.add(ecs.submit(new Fetcher(type, extractIdPackage(toFetch), progressMonitor)));
    328328        }
    329329        // Run the fetchers
     
    555555        public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
    556556            // This method is implemented because of the OsmServerReader inheritance, but not used,
    557557            // as the main target of this class is the call() method.
    558             return fetch(progressMonitor).dataSet;
     558            return fetch().dataSet;
    559559        }
    560560
    561561        @Override
    562562        public FetchResult call() throws Exception {
    563             return fetch(progressMonitor);
     563            return fetch();
    564564        }
    565565
    566566        /**
    567567         * fetches the requested primitives and updates the specified progress monitor.
    568          * @param progressMonitor the progress monitor
    569568         * @return the {@link FetchResult} of this operation
    570569         * @throws OsmTransferException if an error occurs while communicating with the API server
    571570         */
    572         protected FetchResult fetch(ProgressMonitor progressMonitor) throws OsmTransferException {
     571        protected FetchResult fetch() throws OsmTransferException {
    573572            try {
    574                 return multiGetIdPackage(type, pkg, progressMonitor);
     573                return multiGetIdPackage(type, pkg);
    575574            } catch (OsmApiException e) {
    576575                if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
    577576                    if (pkg.size() > 4) {
     
    585584                        return res;
    586585                    } else {
    587586                        Logging.info(tr("Server replied with response code 404, retrying with an individual request for each object."));
    588                         return singleGetIdPackage(type, pkg, progressMonitor);
     587                        return singleGetIdPackage(type, pkg);
    589588                    }
    590589                } else {
    591590                    throw e;
     
    605604         * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY},
    606605         * {@link OsmPrimitiveType#RELATION RELATION}
    607606         * @param pkg the package of ids
    608          * @param progressMonitor progress monitor
    609607         * @return the {@link FetchResult} of this operation
    610608         * @throws OsmTransferException if an error occurs while communicating with the API server
    611609         */
    612         protected FetchResult multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor)
    613                 throws OsmTransferException {
     610        protected FetchResult multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg) throws OsmTransferException {
     611            if (isCanceled())
     612                return new FetchResult(null, null);
    614613            String request = buildRequestString(type, pkg);
    615614            FetchResult result = null;
    616615            try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) {
     
    635634         * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY},
    636635         * {@link OsmPrimitiveType#RELATION RELATION}
    637636         * @param id the id
    638          * @param progressMonitor progress monitor
    639637         * @return the {@link DataSet} resulting of this operation
    640638         * @throws OsmTransferException if an error occurs while communicating with the API server
    641639         */
    642         protected DataSet singleGetId(OsmPrimitiveType type, long id, ProgressMonitor progressMonitor) throws OsmTransferException {
     640        protected DataSet singleGetId(OsmPrimitiveType type, long id) throws OsmTransferException {
    643641            String request = buildRequestString(type, Collections.singleton(id));
    644642            DataSet result = null;
    645643            try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) {
     
    667665         * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY},
    668666         * {@link OsmPrimitiveType#RELATION RELATION}
    669667         * @param pkg the set of ids
    670          * @param progressMonitor progress monitor
    671668         * @return the {@link FetchResult} of this operation
    672669         * @throws OsmTransferException if an error occurs while communicating with the API server
    673670         */
    674         protected FetchResult singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor)
     671        protected FetchResult singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg)
    675672                throws OsmTransferException {
    676673            FetchResult result = new FetchResult(new DataSet(), new HashSet<PrimitiveId>());
    677674            String baseUrl = OsmApi.getOsmApi().getBaseUrl();
    678675            for (long id : pkg) {
     676                if (isCanceled()) return result;
    679677                try {
    680678                    String msg;
    681679                    switch (type) {
     
    687685                        default: throw new AssertionError();
    688686                    }
    689687                    progressMonitor.setCustomText(msg);
    690                     result.dataSet.mergeFrom(singleGetId(type, id, progressMonitor));
     688                    result.dataSet.mergeFrom(singleGetId(type, id));
    691689                } catch (OsmApiException e) {
    692690                    if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
    693691                        Logging.info(tr("Server replied with response code 404 for id {0}. Skipping.", Long.toString(id)));
     
    699697            }
    700698            return result;
    701699        }
     700
     701        @Override
     702        public boolean isCanceled() {
     703            return super.isCanceled() || progressMonitor.isCanceled();
     704        }
    702705    }
    703706}