Merge pull request #912 from jtrax/bugfixes

Fixed scrolling through an online map ends up "downloading forever"
This commit is contained in:
vshcherb 2014-10-09 01:01:25 +02:00
commit 4dd0445aa1
4 changed files with 17 additions and 2 deletions

View file

@ -40,6 +40,7 @@ public class MapTileDownloader {
private ThreadPoolExecutor threadPoolExecutor; private ThreadPoolExecutor threadPoolExecutor;
private List<IMapDownloaderCallback> callbacks = new ArrayList<IMapDownloaderCallback>(); private List<IMapDownloaderCallback> callbacks = new ArrayList<IMapDownloaderCallback>();
private Set<File> pendingToDownload;
private Set<File> currentlyDownloaded; private Set<File> currentlyDownloaded;
private int currentErrors = 0; private int currentErrors = 0;
@ -109,6 +110,7 @@ public class MapTileDownloader {
TimeUnit.SECONDS, new LIFOBlockingDeque<Runnable>()); TimeUnit.SECONDS, new LIFOBlockingDeque<Runnable>());
// 1.6 method but very useful to kill non-running threads // 1.6 method but very useful to kill non-running threads
// threadPoolExecutor.allowCoreThreadTimeOut(true); // threadPoolExecutor.allowCoreThreadTimeOut(true);
pendingToDownload = Collections.synchronizedSet(new HashSet<File>());
currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>()); currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>());
} }
@ -125,6 +127,10 @@ public class MapTileDownloader {
return callbacks; return callbacks;
} }
public boolean isFilePendingToDownload(File f){
return pendingToDownload.contains(f);
}
public boolean isFileCurrentlyDownloaded(File f){ public boolean isFileCurrentlyDownloaded(File f){
return currentlyDownloaded.contains(f); return currentlyDownloaded.contains(f);
} }
@ -157,7 +163,9 @@ public class MapTileDownloader {
return; return;
} }
if (!isFileCurrentlyDownloaded(request.fileToSave)) { if (!isFileCurrentlyDownloaded(request.fileToSave)
&& !isFilePendingToDownload(request.fileToSave)) {
pendingToDownload.add(request.fileToSave);
threadPoolExecutor.execute(new DownloadMapWorker(request)); threadPoolExecutor.execute(new DownloadMapWorker(request));
} }
} }
@ -179,6 +187,7 @@ public class MapTileDownloader {
} }
currentlyDownloaded.add(request.fileToSave); currentlyDownloaded.add(request.fileToSave);
pendingToDownload.remove(request.fileToSave);
if(log.isDebugEnabled()){ if(log.isDebugEnabled()){
log.debug("Start downloading tile : " + request.url); //$NON-NLS-1$ log.debug("Start downloading tile : " + request.url); //$NON-NLS-1$
} }

View file

@ -3,6 +3,7 @@
<name>OsmAnd</name> <name>OsmAnd</name>
<comment></comment> <comment></comment>
<projects> <projects>
<project>SherlockBar</project>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>

View file

@ -141,6 +141,10 @@ public class AsyncLoadingThread extends Thread {
requests.push(req); requests.push(req);
} }
public boolean isFilePendingToDownload(File fileToSave) {
return resourceManger.getMapTileDownloader().isFilePendingToDownload(fileToSave);
}
public boolean isFileCurrentlyDownloaded(File fileToSave) { public boolean isFileCurrentlyDownloaded(File fileToSave) {
return resourceManger.getMapTileDownloader().isFileCurrentlyDownloaded(fileToSave); return resourceManger.getMapTileDownloader().isFileCurrentlyDownloaded(fileToSave);
} }

View file

@ -351,7 +351,8 @@ public class ResourceManager {
if (cacheOfImages.size() > maxImgCacheSize) { if (cacheOfImages.size() > maxImgCacheSize) {
clearTiles(); clearTiles();
} }
if (req.dirWithTiles.canRead() && !asyncLoadingThread.isFileCurrentlyDownloaded(req.fileToSave)) { if (req.dirWithTiles.canRead() && !asyncLoadingThread.isFileCurrentlyDownloaded(req.fileToSave)
&& !asyncLoadingThread.isFilePendingToDownload(req.fileToSave)) {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Start loaded file : " + req.tileId + " " + Thread.currentThread().getName()); //$NON-NLS-1$ //$NON-NLS-2$ log.debug("Start loaded file : " + req.tileId + " " + Thread.currentThread().getName()); //$NON-NLS-1$ //$NON-NLS-2$