Changeset 8649 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-08-08T18:32:10+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r8643 r8649 174 174 if (first || force) { 175 175 ensureCacheElement(); 176 if (!force && cacheElement != null && isCacheElementValid() && isObjectLoadable()) { 177 // we got something in cache, and it's valid, so lets return it 178 log.log(Level.FINE, "JCS - Returning object from cache: {0}", getCacheKey()); 179 finishLoading(LoadResult.SUCCESS); 180 return; 181 } 182 // object not in cache, so submit work to separate thread 176 // submit all jobs to separate thread, so calling thread is not blocked with IO when loading from disk 183 177 downloadJobExecutor.execute(this); 184 178 } … … 229 223 currentThread.setName("JCS Downloading: " + getUrl()); 230 224 try { 225 // try to fetch from cache 226 if (!force && cacheElement != null && isCacheElementValid() && isObjectLoadable()) { 227 // we got something in cache, and it's valid, so lets return it 228 log.log(Level.FINE, "JCS - Returning object from cache: {0}", getCacheKey()); 229 finishLoading(LoadResult.SUCCESS); 230 return; 231 } 232 231 233 // try to load object from remote resource 232 234 if (loadObject()) { … … 306 308 } 307 309 308 HttpURLConnection urlConn = getURLConnection( );310 HttpURLConnection urlConn = getURLConnection(getUrl()); 309 311 310 312 if (isObjectLoadable() && … … 314 316 if (isObjectLoadable() && attributes.getEtag() != null) { 315 317 urlConn.addRequestProperty("If-None-Match", attributes.getEtag()); 318 } 319 320 // follow redirects 321 for (int i = 0; i < 5; i++) { 322 if (urlConn.getResponseCode() == 302) { 323 urlConn = getURLConnection(new URL(urlConn.getHeaderField("Location"))); 324 } else { 325 break; 326 } 316 327 } 317 328 if (urlConn.getResponseCode() == 304) { … … 447 458 } 448 459 449 private HttpURLConnection getURLConnection( ) throws IOException {450 HttpURLConnection urlConn = (HttpURLConnection) getUrl().openConnection();460 private HttpURLConnection getURLConnection(URL url) throws IOException { 461 HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); 451 462 urlConn.setRequestProperty("Accept", "text/html, image/png, image/jpeg, image/gif, */*"); 452 463 urlConn.setReadTimeout(readTimeout); // 30 seconds read timeout … … 465 476 466 477 private boolean isCacheValidUsingHead() throws IOException { 467 HttpURLConnection urlConn = getURLConnection( );478 HttpURLConnection urlConn = getURLConnection(getUrl()); 468 479 urlConn.setRequestMethod("HEAD"); 480 for (int i = 0; i < 5; i++) { 481 if (urlConn.getResponseCode() == 302) { 482 urlConn = getURLConnection(new URL(urlConn.getHeaderField("Location"))); 483 } else { 484 break; 485 } 486 } 469 487 long lastModified = urlConn.getLastModified(); 470 488 return (attributes.getEtag() != null && attributes.getEtag().equals(urlConn.getRequestProperty("ETag"))) || -
trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java
r8647 r8649 37 37 */ 38 38 public class TemplatedWMSTileSource extends TMSTileSource implements TemplatedTileSource { 39 private Map<String, String> headers = new ConcurrentHashMap<>();39 private final Map<String, String> headers = new ConcurrentHashMap<>(); 40 40 private final Set<String> serverProjections; 41 41 private EastNorth topLeftCorner; 42 42 private Bounds worldBounds; 43 private int[] tileXMax; 44 private int[] tileYMax; 43 45 44 46 private static final Pattern PATTERN_HEADER = Pattern.compile("\\{header\\(([^,]+),([^}]+)\\)\\}"); … … 89 91 EastNorth max = proj.latlon2eastNorth(worldBounds.getMax()); 90 92 this.topLeftCorner = new EastNorth(min.east(), max.north()); 93 94 LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon()); 95 tileXMax = new int[getMaxZoom() + 1]; 96 tileYMax = new int[getMaxZoom() + 1]; 97 for(int zoom = getMinZoom(); zoom <= getMaxZoom(); zoom++) { 98 TileXY maxTileIndex = latLonToTileXY(bottomRight.toCoordinate(), zoom); 99 tileXMax[zoom] = maxTileIndex.getXIndex(); 100 tileYMax[zoom] = maxTileIndex.getYIndex(); 101 } 91 102 } 92 103 … … 229 240 @Override 230 241 public int getTileXMax(int zoom) { 231 LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon()); 232 return latLonToTileXY(bottomRight.toCoordinate(), zoom).getXIndex(); 242 return tileXMax[zoom]; 233 243 } 234 244 … … 240 250 @Override 241 251 public int getTileYMax(int zoom) { 242 LatLon bottomRight = new LatLon(worldBounds.getMinLat(), worldBounds.getMaxLon()); 243 return latLonToTileXY(bottomRight.toCoordinate(), zoom).getYIndex(); 252 return tileYMax[zoom]; 244 253 } 245 254
Note:
See TracChangeset
for help on using the changeset viewer.