Changeset 17494 in josm


Ignore:
Timestamp:
2021-02-20T01:05:00+01:00 (4 years ago)
Author:
wiktorn
Message:

Remove unneeded WMS download threads.

Once the WMS layer is destroyed, remove threadpool, as it will never be GC as the
threads are alive.

Refactor fetching tiles from different zoom levels for easier debugging.

See: #20443, #20497

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r17492 r17494  
    15701570            ts.overloadTiles();
    15711571        }
    1572         int[] otherZooms = {1, 2, -1, -2, -3, -4, -5};
    1573         for (int zoomOffset : otherZooms) {
    1574             if (!getDisplaySettings().isAutoZoom()) {
    1575                 break;
    1576             }
    1577             int newzoom = displayZoomLevel + zoomOffset;
    1578             if (newzoom < getMinZoomLvl() || newzoom > getMaxZoomLvl()) {
    1579                 continue;
    1580             }
    1581             if (missedTiles.isEmpty()) {
    1582                 break;
    1583             }
    1584             List<Tile> newlyMissedTiles = new LinkedList<>();
    1585             for (Tile missed : missedTiles) {
    1586                 if (zoomOffset > 0 && "no-tile".equals(missed.getValue("tile-info"))) {
    1587                     // Don't try to paint from higher zoom levels when tile is overzoomed
    1588                     newlyMissedTiles.add(missed);
    1589                     continue;
    1590                 }
    1591                 TileSet ts2 = new TileSet(tileSource.getCoveringTileRange(missed, newzoom));
    1592                 // Instantiating large TileSets is expensive. If there are no loaded tiles, don't bother even trying.
    1593                 if (ts2.allLoadedTiles().isEmpty()) {
    1594                     if (zoomOffset > 0) {
    1595                         newlyMissedTiles.add(missed);
    1596                         continue;
    1597                     } else {
    1598                         /*
    1599                          *  We have negative zoom offset. Try to load tiles from lower zoom levels, as they may be not present
    1600                          *  in tile cache (e.g. when user panned the map or opened layer above zoom level, for which tiles are present.
    1601                          *  This will ensure, that tileCache is populated with tiles from lower zoom levels so it will be possible to
    1602                          *  use them to paint overzoomed tiles.
    1603                          *  See: #14562
    1604                          */
    1605                         ts2.loadAllTiles(false);
    1606                     }
    1607                 }
    1608                 if (ts2.tooLarge()) {
    1609                     continue;
    1610                 }
    1611                 newlyMissedTiles.addAll(this.paintTileImages(g, ts2, newzoom, missed));
    1612             }
    1613             missedTiles = newlyMissedTiles;
    1614         }
     1572        if (getDisplaySettings().isAutoZoom()) {
     1573            int[] otherZooms = {1, 2, -1, -2, -3, -4, -5};
     1574
     1575            for(int otherZoom: otherZooms) {
     1576                missedTiles = tryLoadFromDifferentZoom(g, displayZoomLevel, missedTiles, otherZoom);
     1577                if (missedTiles.isEmpty()) {
     1578                    break;
     1579                }
     1580            }
     1581        }
     1582
    16151583        if (Logging.isDebugEnabled() && !missedTiles.isEmpty()) {
    16161584            Logging.debug("still missed {0} in the end", missedTiles.size());
     
    16551623            }
    16561624        }
     1625    }
     1626
     1627    private List<Tile> tryLoadFromDifferentZoom(Graphics2D g, int displayZoomLevel, List<Tile> missedTiles,
     1628            int zoomOffset) {
     1629
     1630        int newzoom = displayZoomLevel + zoomOffset;
     1631        if (newzoom < getMinZoomLvl() || newzoom > getMaxZoomLvl()) {
     1632            return missedTiles;
     1633        }
     1634
     1635        List<Tile> newlyMissedTiles = new LinkedList<>();
     1636        for (Tile missed : missedTiles) {
     1637            if (zoomOffset > 0 && "no-tile".equals(missed.getValue("tile-info"))) {
     1638                // Don't try to paint from higher zoom levels when tile is overzoomed
     1639                newlyMissedTiles.add(missed);
     1640                continue;
     1641            }
     1642            TileSet ts2 = new TileSet(tileSource.getCoveringTileRange(missed, newzoom));
     1643            // Instantiating large TileSets is expensive. If there are no loaded tiles, don't bother even trying.
     1644            if (ts2.allLoadedTiles().isEmpty()) {
     1645                if (zoomOffset > 0) {
     1646                    newlyMissedTiles.add(missed);
     1647                    continue;
     1648                } else {
     1649                    /*
     1650                     *  We have negative zoom offset. Try to load tiles from lower zoom levels, as they may be not present
     1651                     *  in tile cache (e.g. when user panned the map or opened layer above zoom level, for which tiles are present.
     1652                     *  This will ensure, that tileCache is populated with tiles from lower zoom levels so it will be possible to
     1653                     *  use them to paint overzoomed tiles.
     1654                     *  See: #14562
     1655                     */
     1656                    ts2.loadAllTiles(false);
     1657                }
     1658            }
     1659            if (ts2.tooLarge()) {
     1660                continue;
     1661            }
     1662            newlyMissedTiles.addAll(this.paintTileImages(g, ts2, newzoom, missed));
     1663        }
     1664        return newlyMissedTiles;
    16571665    }
    16581666
     
    18631871        public void cancel() {
    18641872            if (tileLoader instanceof TMSCachedTileLoader) {
    1865                 ((TMSCachedTileLoader) tileLoader).cancelOutstandingTasks();
     1873                TMSCachedTileLoader cachedTileLoader = (TMSCachedTileLoader) tileLoader;
     1874                cachedTileLoader.cancelOutstandingTasks();
     1875                cachedTileLoader.getDownloadExecutor().shutdown();
    18661876            }
    18671877        }
     
    18791889            } else {
    18801890                Logging.warn("Tile loading failure: " + tile + " - " + tile.getErrorMessage());
     1891            }
     1892            if (tileLoader instanceof TMSCachedTileLoader) {
     1893                TMSCachedTileLoader cachedTileLoader = (TMSCachedTileLoader) tileLoader;
     1894                cachedTileLoader.cancelOutstandingTasks();
     1895                cachedTileLoader.getDownloadExecutor().shutdown();
    18811896            }
    18821897        }
     
    19361951        MapView.removeZoomChangeListener(this);
    19371952        adjustAction.destroy();
     1953        if (tileLoader instanceof TMSCachedTileLoader) {
     1954            TMSCachedTileLoader cachedTileLoader = (TMSCachedTileLoader) tileLoader;
     1955            cachedTileLoader.getDownloadExecutor().shutdown();
     1956        }
    19381957    }
    19391958
Note: See TracChangeset for help on using the changeset viewer.