X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fgui%2Fmap%2FTileDownloader.java;h=7ec6d91eb58db07faaa8c8a52421f5da5a8cf544;hp=7c7540066c839d86105f71a0a95b3af1398d17de;hb=HEAD;hpb=2302358503c38817e19f6e529f6c9e530aac0e86 diff --git a/src/tim/prune/gui/map/TileDownloader.java b/src/tim/prune/gui/map/TileDownloader.java index 7c75400..16466f3 100644 --- a/src/tim/prune/gui/map/TileDownloader.java +++ b/src/tim/prune/gui/map/TileDownloader.java @@ -21,10 +21,13 @@ public class TileDownloader implements Runnable private int _layer = 0; private int _x = 0, _y = 0; private int _zoom = 0; + /** Hashset of all blocked / 404 tiles to avoid requesting them again */ private static final HashSet BLOCKED_URLS = new HashSet(); /** Hashset of all currently loading tiles to avoid requesting them again */ private static final HashSet LOADING_URLS = new HashSet(); + /** Flag to maintain whether connection is active or not */ + private static boolean CONNECTION_ACTIVE = true; /** @@ -60,10 +63,12 @@ public class TileDownloader implements Runnable if (inManager != null && inUrl != null) { String url = inUrl.toString(); - // System.out.println("Trigger load: " + url); - if (!BLOCKED_URLS.contains(url) && !LOADING_URLS.contains(url)) + if (BLOCKED_URLS.contains(url)) + { + System.out.println("Already blocked: " + url); + } + else if (!LOADING_URLS.contains(url)) { - // System.out.println("Not blocked: " + url); LOADING_URLS.add(url); new Thread(new TileDownloader(inManager, inUrl, inLayer, inX, inY, inZoom)).start(); } @@ -98,6 +103,17 @@ public class TileDownloader implements Runnable // Pass back to manager so it can be stored in its memory cache _manager.notifyImageLoaded(tile, _layer, _x, _y, _zoom); + + if (!CONNECTION_ACTIVE) + { + // We've just come back online, so forget which tiles gave 404 before + System.out.println("Deleting blocked urls, currently holds " + BLOCKED_URLS.size()); + synchronized(this.getClass()) + { + BLOCKED_URLS.clear(); + } + CONNECTION_ACTIVE = true; + } } } catch (IOException e) @@ -108,6 +124,7 @@ public class TileDownloader implements Runnable BLOCKED_URLS.add(_url.toString()); } try {in.close();} catch (Exception e2) {} + CONNECTION_ACTIVE = false; // lost connection? } LOADING_URLS.remove(_url.toString()); }