Ticket #20416: 20416.2.patch
File 20416.2.patch, 6.3 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
323 323 threadsNumber, Utils.newThreadFactory(getClass() + "-%d", Thread.NORM_PRIORITY)); 324 324 CompletionService<FetchResult> ecs = new ExecutorCompletionService<>(exec); 325 325 List<Future<FetchResult>> jobs = new ArrayList<>(); 326 while (!toFetch.isEmpty() ) {326 while (!toFetch.isEmpty() && !isCanceled()) { 327 327 jobs.add(ecs.submit(new Fetcher(type, extractIdPackage(toFetch), progressMonitor))); 328 328 } 329 329 // Run the fetchers … … 555 555 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 556 556 // This method is implemented because of the OsmServerReader inheritance, but not used, 557 557 // as the main target of this class is the call() method. 558 return fetch( progressMonitor).dataSet;558 return fetch().dataSet; 559 559 } 560 560 561 561 @Override 562 562 public FetchResult call() throws Exception { 563 return fetch( progressMonitor);563 return fetch(); 564 564 } 565 565 566 566 /** 567 567 * fetches the requested primitives and updates the specified progress monitor. 568 * @param progressMonitor the progress monitor569 568 * @return the {@link FetchResult} of this operation 570 569 * @throws OsmTransferException if an error occurs while communicating with the API server 571 570 */ 572 protected FetchResult fetch( ProgressMonitor progressMonitor) throws OsmTransferException {571 protected FetchResult fetch() throws OsmTransferException { 573 572 try { 574 return multiGetIdPackage(type, pkg , progressMonitor);573 return multiGetIdPackage(type, pkg); 575 574 } catch (OsmApiException e) { 576 575 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 577 576 if (pkg.size() > 4) { … … 585 584 return res; 586 585 } else { 587 586 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); 589 588 } 590 589 } else { 591 590 throw e; … … 605 604 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 606 605 * {@link OsmPrimitiveType#RELATION RELATION} 607 606 * @param pkg the package of ids 608 * @param progressMonitor progress monitor609 607 * @return the {@link FetchResult} of this operation 610 608 * @throws OsmTransferException if an error occurs while communicating with the API server 611 609 */ 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); 614 613 String request = buildRequestString(type, pkg); 615 614 FetchResult result = null; 616 615 try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) { … … 635 634 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 636 635 * {@link OsmPrimitiveType#RELATION RELATION} 637 636 * @param id the id 638 * @param progressMonitor progress monitor639 637 * @return the {@link DataSet} resulting of this operation 640 638 * @throws OsmTransferException if an error occurs while communicating with the API server 641 639 */ 642 protected DataSet singleGetId(OsmPrimitiveType type, long id , ProgressMonitor progressMonitor) throws OsmTransferException {640 protected DataSet singleGetId(OsmPrimitiveType type, long id) throws OsmTransferException { 643 641 String request = buildRequestString(type, Collections.singleton(id)); 644 642 DataSet result = null; 645 643 try (InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE)) { … … 667 665 * @param type The primitive type. Must be one of {@link OsmPrimitiveType#NODE NODE}, {@link OsmPrimitiveType#WAY WAY}, 668 666 * {@link OsmPrimitiveType#RELATION RELATION} 669 667 * @param pkg the set of ids 670 * @param progressMonitor progress monitor671 668 * @return the {@link FetchResult} of this operation 672 669 * @throws OsmTransferException if an error occurs while communicating with the API server 673 670 */ 674 protected FetchResult singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg , ProgressMonitor progressMonitor)671 protected FetchResult singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg) 675 672 throws OsmTransferException { 676 673 FetchResult result = new FetchResult(new DataSet(), new HashSet<PrimitiveId>()); 677 674 String baseUrl = OsmApi.getOsmApi().getBaseUrl(); 678 675 for (long id : pkg) { 676 if (isCanceled()) return result; 679 677 try { 680 678 String msg; 681 679 switch (type) { … … 687 685 default: throw new AssertionError(); 688 686 } 689 687 progressMonitor.setCustomText(msg); 690 result.dataSet.mergeFrom(singleGetId(type, id , progressMonitor));688 result.dataSet.mergeFrom(singleGetId(type, id)); 691 689 } catch (OsmApiException e) { 692 690 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 693 691 Logging.info(tr("Server replied with response code 404 for id {0}. Skipping.", Long.toString(id))); … … 699 697 } 700 698 return result; 701 699 } 700 701 @Override 702 public boolean isCanceled() { 703 return super.isCanceled() || progressMonitor.isCanceled(); 704 } 702 705 } 703 706 }