Changeset 8425 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2015-05-24T23:41:24+02:00 (9 years ago)
Author:
wiktorn
Message:

Limit the tile expiration date between 1 hour to 1 month. Fix Sonar warning about log variable naming

Location:
trunk/src/org/openstreetmap/josm/data
Files:
2 edited

Legend:

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

    r8424 r8425  
    9696    private static ConcurrentMap<String, Boolean> useHead = new ConcurrentHashMap<>();
    9797
    98     private long now; // when the job started
     98    protected long now; // when the job started
    9999
    100100    private ICacheAccess<K, V> cache;
     
    398398    protected abstract V createCacheEntry(byte[] content);
    399399
    400     private CacheEntryAttributes parseHeaders(URLConnection urlConn) {
     400    protected CacheEntryAttributes parseHeaders(URLConnection urlConn) {
    401401        CacheEntryAttributes ret = new CacheEntryAttributes();
    402402
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r8424 r8425  
    77import java.io.IOException;
    88import java.net.URL;
     9import java.net.URLConnection;
    910import java.util.HashSet;
    1011import java.util.List;
     
    3839 */
    3940public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, BufferedImageCacheEntry> implements TileJob, ICachedLoaderListener  {
    40     private static final Logger log = FeatureAdapter.getLogger(TMSCachedTileLoaderJob.class.getCanonicalName());
     41    private static final Logger LOG = FeatureAdapter.getLogger(TMSCachedTileLoaderJob.class.getCanonicalName());
     42    private static final long MAXIMUM_EXPIRES = 30 /*days*/ * 24 /*hours*/ * 60 /*minutes*/ * 60 /*seconds*/ *1000L /*milliseconds*/;
     43    private static final long MINIMUM_EXPIRES = 1 /*hour*/ * 60 /*minutes*/ * 60 /*seconds*/ *1000L /*milliseconds*/;
    4144    private Tile tile;
    4245    private volatile URL url;
     46
    4347
    4448    // we need another deduplication of Tile Loader listeners, as for each submit, new TMSCachedTileLoaderJob was created
     
    105109                }
    106110            } catch (IOException e) {
    107                 log.log(Level.WARNING, "JCS TMS Cache - error creating URL for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    108                 log.log(Level.INFO, "Exception: ", e);
     111                LOG.log(Level.WARNING, "JCS TMS Cache - error creating URL for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
     112                LOG.log(Level.INFO, "Exception: ", e);
    109113            }
    110114        }
     
    119123                return content != null  || cacheData.getImage() != null || isNoTileAtZoom();
    120124            } catch (IOException e) {
    121                 log.log(Level.WARNING, "JCS TMS - error loading from cache for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
     125                LOG.log(Level.WARNING, "JCS TMS - error loading from cache for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    122126            }
    123127        }
     
    127131    private boolean isNoTileAtZoom() {
    128132        if (attributes == null) {
    129             log.warning("Cache attributes are null");
     133            LOG.warning("Cache attributes are null");
    130134        }
    131135        return attributes != null && attributes.isNoTileAtZoom();
     
    146150    private boolean handleNoTileAtZoom() {
    147151        if (isNoTileAtZoom()) {
    148             log.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);
     152            LOG.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);
    149153            tile.setError("No tile at this zoom level");
    150154            tile.putValue("tile-info", "no-tile");
     
    207211            }
    208212        } catch (IOException e) {
    209             log.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
     213            LOG.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    210214            tile.setError(e.getMessage());
    211215            tile.setLoaded(false);
     
    246250                return tile;
    247251            } catch (IOException e) {
    248                 log.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
     252                LOG.log(Level.WARNING, "JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});
    249253                return null;
    250254            }
     
    288292        submit(false);
    289293    }
     294
     295    @Override
     296    protected CacheEntryAttributes parseHeaders(URLConnection urlConn) {
     297        CacheEntryAttributes ret = super.parseHeaders(urlConn);
     298        // keep the expiration time between MINIMUM_EXPIRES and MAXIMUM_EXPIRES, so we will cache the tiles
     299        // at least for some short period of time, but not too long
     300        if (ret.getExpirationTime() < MINIMUM_EXPIRES) {
     301            ret.setExpirationTime(now + MINIMUM_EXPIRES);
     302        }
     303        if (ret.getExpirationTime() > MAXIMUM_EXPIRES) {
     304            ret.setExpirationTime(now + MAXIMUM_EXPIRES);
     305        }
     306        return ret;
     307    }
    290308}
Note: See TracChangeset for help on using the changeset viewer.