Changeset 30850 in osm for applications/viewer/jmapviewer/src
- Timestamp:
- 2014-12-15T19:02:31+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r30849 r30850 133 133 File tileCacheDir; 134 134 File tileFile = null; 135 Long fileAge = null; 135 Long fileMtime = null; 136 Long now = null; // current time in milliseconds (keep consistent value for the whole run) 136 137 137 138 public FileLoadJob(Tile tile) { … … 153 154 tile.loading = true; 154 155 } 156 now = System.currentTimeMillis(); 155 157 tileCacheDir = getSourceCacheDir(tile.getSource()); 156 158 157 159 if (loadTileFromFile(recheckAfter)) { 158 log.log(Level.FINE ST, "TMS - found in tile cache: {0}", tile);160 log.log(Level.FINE, "TMS - found in tile cache: {0}", tile); 159 161 tile.setLoaded(true); 160 162 listener.tileLoadingFinished(tile, true); … … 174 176 tile.error = false; 175 177 listener.tileLoadingFinished(tile, true); 176 log.log(Level.FINE ST, "TMS - found stale tile in cache: {0}", tile);178 log.log(Level.FINE, "TMS - found stale tile in cache: {0}", tile); 177 179 } else { 178 180 // failed completely … … 193 195 try { 194 196 URLConnection urlConn = loadTileFromOsm(tile); 195 if (file Age != null) {197 if (fileMtime != null && now - fileMtime <= maxCacheFileAge) { 196 198 switch (tile.getSource().getTileUpdate()) { 197 199 case IfModifiedSince: 198 urlConn.setIfModifiedSince(file Age);200 urlConn.setIfModifiedSince(fileMtime); 199 201 break; 200 202 case LastModified: 201 if (!isOsmTileNewer(file Age)) {202 log.log(Level.FINE ST, "TMS - LastModified test: local version is up to date: {0}", tile);203 tileFile.setLastModified( System.currentTimeMillis());203 if (!isOsmTileNewer(fileMtime)) { 204 log.log(Level.FINE, "TMS - LastModified test: local version is up to date: {0}", tile); 205 tileFile.setLastModified(now); 204 206 return true; 205 207 } … … 216 218 case ETag: 217 219 if (hasOsmTileETag(fileETag)) { 218 log.log(Level.FINE ST, "TMS - ETag test: local version is up to date: {0}", tile);219 tileFile.setLastModified( System.currentTimeMillis());220 log.log(Level.FINE, "TMS - ETag test: local version is up to date: {0}", tile); 221 tileFile.setLastModified(now); 220 222 return true; 221 223 } … … 229 231 switch (tile.getSource().getTileUpdate()) { 230 232 case IfModifiedSince: 231 log.log(Level.FINE ST, "TMS - IfModifiedSince test: local version is up to date: {0}", tile);233 log.log(Level.FINE, "TMS - IfModifiedSince test: local version is up to date: {0}", tile); 232 234 break; 233 235 case IfNoneMatch: 234 log.log(Level.FINE ST, "TMS - IfNoneMatch test: local version is up to date: {0}", tile);236 log.log(Level.FINE, "TMS - IfNoneMatch test: local version is up to date: {0}", tile); 235 237 break; 236 238 } 237 239 if (loadTileFromFile(maxCacheFileAge)) { 238 tileFile.setLastModified( System.currentTimeMillis());240 tileFile.setLastModified(now); 239 241 return true; 240 242 } … … 246 248 if ("no-tile".equals(tile.getValue("tile-info"))) 247 249 { 248 log.log(Level.FINE ST, "TMS - No tile: tile-info=no-tile: {0}", tile);250 log.log(Level.FINE, "TMS - No tile: tile-info=no-tile: {0}", tile); 249 251 tile.setError("No tile at this zoom level"); 250 252 return true; … … 259 261 tile.loadImage(new ByteArrayInputStream(buffer)); 260 262 saveTileToFile(buffer); 261 log.log(Level.FINE ST, "TMS - downloaded tile from server: {0}", tile.getUrl());263 log.log(Level.FINE, "TMS - downloaded tile from server: {0}", tile.getUrl()); 262 264 return true; 263 265 } … … 285 287 loadTagsFromFile(); 286 288 287 file Age = tileFile.lastModified();288 if ( System.currentTimeMillis() - fileAge > maxAge)289 fileMtime = tileFile.lastModified(); 290 if (now - fileMtime > maxAge) 289 291 return false; 290 292 … … 308 310 tileFile.delete(); 309 311 tileFile = null; 310 file Age = null;312 fileMtime = null; 311 313 } 312 314 return false; … … 361 363 // System.out.println("Tile age: " + new 362 364 // Date(urlConn.getLastModified()) + " / " 363 // + new Date(file Age));365 // + new Date(fileMtime)); 364 366 long lastModified = urlConn.getLastModified(); 365 367 if (lastModified == 0) … … 377 379 // System.out.println("Tile age: " + new 378 380 // Date(urlConn.getLastModified()) + " / " 379 // + new Date(file Age));381 // + new Date(fileMtime)); 380 382 String osmETag = urlConn.getHeaderField("ETag"); 381 383 if (osmETag == null) … … 401 403 f.write(rawData); 402 404 } catch (Exception e) { 403 System.err.println("Failed to save tile content: " +e.getLocalizedMessage());405 log.log(Level.SEVERE, "Failed to save tile content: {0}", e.getLocalizedMessage()); 404 406 } 405 407 }
Note:
See TracChangeset
for help on using the changeset viewer.