Changeset 8673 in josm


Ignore:
Timestamp:
2015-08-20T23:01:54+02:00 (9 years ago)
Author:
wiktorn
Message:

Bing fixes.

  • Pass and handle error on url creation (attribution not loaded yet). Closes: #11776
  • Properly identify "no tiles at this zoom level" situation in tile sets. This tiles are never marked as loaded. Closes: #11785
Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/HostLimitQueue.java

    r8624 r8673  
    22package org.openstreetmap.josm.data.cache;
    33
     4import java.io.IOException;
     5import java.net.URL;
    46import java.util.Iterator;
    57import java.util.Map;
     
    5759                    }
    5860                } else {
    59                     Main.info("TMS - Skipping job {0} because host limit reached", job.getUrl());
     61                    URL url = null;
     62                    try {
     63                        url = job.getUrl();
     64                    } catch (IOException e) {
     65                    }
     66                    Main.info("TMS - Skipping job {0} because host limit reached", url);
    6067                }
    6168            }
     
    9198
    9299    private  Semaphore getSemaphore(JCSCachedTileLoaderJob<?, ?> job) {
    93         String host = job.getUrl().getHost();
     100        String host;
     101        try {
     102            host = job.getUrl().getHost();
     103        } catch (IOException e) {
     104            // do not pass me illegal URL's
     105            throw new IllegalArgumentException(e);
     106        }
    94107        Semaphore limit = hostSemaphores.get(host);
    95108        if (limit == null) {
  • trunk/src/org/openstreetmap/josm/data/cache/ICachedLoaderJob.java

    r8624 r8673  
    22package org.openstreetmap.josm.data.cache;
    33
     4import java.io.IOException;
    45import java.net.URL;
    56
     
    2122     * method to get download URL for Job
    2223     * @return URL that should be fetched
     24     * @throws IOException when could not determine the URL of the tile
    2325     *
    2426     */
    25     URL getUrl();
     27    URL getUrl() throws IOException;
    2628
    2729    /**
     
    4244     * @param listener cache loader listener
    4345     * @param force true if the load should skip all the caches (local & remote)
     46     * @throws IOException on failure from getUrl() call
    4447     */
    45     void submit(ICachedLoaderListener listener, boolean force);
     48    void submit(ICachedLoaderListener listener, boolean force) throws IOException;
    4649}
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r8649 r8673  
    149149
    150150    @Override
    151     public void submit(ICachedLoaderListener listener, boolean force) {
     151    public void submit(ICachedLoaderListener listener, boolean force) throws IOException {
    152152        this.force = force;
    153153        boolean first = false;
     
    160160        if (deduplicationKey == null) {
    161161            log.log(Level.WARNING, "No url returned for: {0}, skipping", getCacheKey());
    162             return;
     162            throw new IllegalArgumentException("No url returned");
    163163        }
    164164        synchronized (inProgress) {
     
    173173
    174174        if (first || force) {
    175             ensureCacheElement();
    176175            // submit all jobs to separate thread, so calling thread is not blocked with IO when loading from disk
    177176            downloadJobExecutor.execute(this);
     
    214213     */
    215214    protected String getServerKey() {
    216         return getUrl().getHost();
     215        return getUrlNoException().getHost();
    217216    }
    218217
     
    221220        final Thread currentThread = Thread.currentThread();
    222221        final String oldName = currentThread.getName();
    223         currentThread.setName("JCS Downloading: " + getUrl());
     222        currentThread.setName("JCS Downloading: " + getUrlNoException());
     223        ensureCacheElement();
    224224        try {
    225225            // try to fetch from cache
     
    239239                    // try to get stale entry in cache
    240240                    finishLoading(LoadResult.SUCCESS);
    241                     log.log(Level.FINE, "JCS - found stale object in cache: {0}", getUrl());
     241                    log.log(Level.FINE, "JCS - found stale object in cache: {0}", getUrlNoException());
    242242                } else {
    243243                    // failed completely
     
    254254        Set<ICachedLoaderListener> listeners = null;
    255255        synchronized (inProgress) {
    256             listeners = inProgress.remove(getUrl().toString());
     256            listeners = inProgress.remove(getUrlNoException().toString());
    257257        }
    258258        if (listeners == null) {
    259             log.log(Level.WARNING, "Listener not found for URL: {0}. Listener not notified!", getUrl());
     259            log.log(Level.WARNING, "Listener not found for URL: {0}. Listener not notified!", getUrlNoException());
    260260            return;
    261261        }
     
    275275            if (now > expires) {
    276276                log.log(Level.FINE, "JCS - Object {0} has expired -> valid to {1}, now is: {2}",
    277                         new Object[]{getUrl(), Long.toString(expires), Long.toString(now)});
     277                        new Object[]{getUrlNoException(), Long.toString(expires), Long.toString(now)});
    278278                return false;
    279279            }
     
    281281                now - attributes.getLastModification() > DEFAULT_EXPIRE_TIME) {
    282282            // check by file modification date
    283             log.log(Level.FINE, "JCS - Object has expired, maximum file age reached {0}", getUrl());
     283            log.log(Level.FINE, "JCS - Object has expired, maximum file age reached {0}", getUrlNoException());
    284284            return false;
    285285        } else if (now - attributes.getCreateTime() > DEFAULT_EXPIRE_TIME) {
    286             log.log(Level.FINE, "JCS - Object has expired, maximum time since object creation reached {0}", getUrl());
     286            log.log(Level.FINE, "JCS - Object has expired, maximum time since object creation reached {0}", getUrlNoException());
    287287            return false;
    288288        }
     
    380380            }
    381381        } catch (FileNotFoundException e) {
    382             log.log(Level.FINE, "JCS - Caching empty object as server returned 404 for: {0}", getUrl());
     382            log.log(Level.FINE, "JCS - Caching empty object as server returned 404 for: {0}", getUrlNoException());
    383383            attributes.setResponseCode(404);
    384384            attributes.setErrorMessage(e.toString());
     
    390390            return doCache;
    391391        } catch (IOException e) {
    392             log.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrl());
     392            log.log(Level.FINE, "JCS - IOExecption during communication with server for: {0}", getUrlNoException());
    393393            attributes.setErrorMessage(e.toString());
    394394            attributes.setResponseCode(499); // set dummy error code
     
    401401        } catch (Exception e) {
    402402            attributes.setErrorMessage(e.toString());
    403             log.log(Level.WARNING, "JCS - Exception during download {0}",  getUrl());
     403            log.log(Level.WARNING, "JCS - Exception during download {0}",  getUrlNoException());
    404404            Main.warn(e);
    405405        }
    406         log.log(Level.WARNING, "JCS - Silent failure during download: {0}", getUrl());
     406        log.log(Level.WARNING, "JCS - Silent failure during download: {0}", getUrlNoException());
    407407        return false;
    408408
     
    517517        finishLoading(LoadResult.CANCELED);
    518518    }
     519
     520    private URL getUrlNoException() {
     521        try {
     522            return getUrl();
     523        } catch (IOException e) {
     524            return null;
     525        }
     526    }
    519527}
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r8643 r8673  
    106106     */
    107107    @Override
    108     public URL getUrl() {
     108    public URL getUrl() throws IOException {
    109109        if (url == null) {
    110             try {
    111                 synchronized (this) {
    112                     if (url == null)
    113                         url = new URL(tile.getUrl());
    114                 }
    115             } catch (IOException e) {
    116                 LOG.log(Level.WARNING, "JCS TMS Cache - error creating URL for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    117                 LOG.log(Level.INFO, "Exception: ", e);
     110            synchronized (this) {
     111                if (url == null)
     112                    url = new URL(tile.getUrl());
    118113            }
    119114        }
     
    152147    public void submit(boolean force) {
    153148        tile.initLoading();
    154         super.submit(this, force);
     149        try {
     150            super.submit(this, force);
     151        } catch (Exception e) {
     152            // if we fail to submit the job, mark tile as loaded and set error message
     153            tile.finishLoading();
     154            tile.setError(e.getMessage());
     155        }
    155156    }
    156157
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r8659 r8673  
    13051305        result.hasLoadingTiles = allTiles.size() < ts.size();
    13061306        for (Tile t : allTiles) {
     1307            if ("no-tile".equals(t.getValue("tile-info"))) {
     1308                result.hasOverzoomedTiles = true;
     1309            }
     1310
    13071311            if (t.isLoaded()) {
    13081312                if (!t.hasError()) {
    13091313                    result.hasVisibleTiles = true;
    13101314                }
    1311                 if ("no-tile".equals(t.getValue("tile-info"))) {
    1312                     result.hasOverzoomedTiles = true;
    1313                 }
    1314             } else {
     1315            } else if (t.isLoading()) {
    13151316                result.hasLoadingTiles = true;
    13161317            }
     
    14101411            // If all tiles at displayZoomLevel is loaded, load all tiles at next zoom level
    14111412            // to make sure there're really no more zoom levels
     1413            // loading is done in the next if section
    14121414            if (zoom == displayZoomLevel && !tsi.hasLoadingTiles && zoom < dts.maxZoom) {
    14131415                zoom++;
     
    14161418            // When we have overzoomed tiles and all tiles at current zoomlevel is loaded,
    14171419            // load tiles at previovus zoomlevels until we have all tiles on screen is loaded.
     1420            // loading is done in the next if section
    14181421            while (zoom > dts.minZoom && tsi.hasOverzoomedTiles && !tsi.hasLoadingTiles) {
    14191422                zoom--;
Note: See TracChangeset for help on using the changeset viewer.