TileLoader/TileDataSource: add cancel() method
- used to force closing sockets when changing theme or tilesource
This commit is contained in:
@@ -105,8 +105,8 @@ public abstract class TileLayer extends Layer implements UpdateListener {
|
||||
public void onDetach() {
|
||||
for (TileLoader loader : mTileLoader) {
|
||||
loader.pause();
|
||||
loader.interrupt();
|
||||
loader.cleanup();
|
||||
loader.finish();
|
||||
loader.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,9 +117,12 @@ public abstract class TileLayer extends Layer implements UpdateListener {
|
||||
|
||||
protected void pauseLoaders(boolean wait) {
|
||||
for (TileLoader loader : mTileLoader) {
|
||||
loader.cancel();
|
||||
|
||||
if (!loader.isPausing())
|
||||
loader.pause();
|
||||
}
|
||||
|
||||
if (!wait)
|
||||
return;
|
||||
|
||||
|
||||
@@ -23,8 +23,13 @@ import org.oscim.backend.canvas.Bitmap;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.utils.PausableThread;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class TileLoader extends PausableThread implements ITileDataSink {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(TileLoader.class);
|
||||
|
||||
private static int id;
|
||||
|
||||
private final String THREAD_NAME;
|
||||
@@ -77,7 +82,9 @@ public abstract class TileLoader extends PausableThread implements ITileDataSink
|
||||
return mTileManager.hasTileJobs();
|
||||
}
|
||||
|
||||
public abstract void cleanup();
|
||||
public abstract void dispose();
|
||||
|
||||
public abstract void cancel();
|
||||
|
||||
/**
|
||||
* Callback to be called by TileDataSource when finished
|
||||
@@ -85,15 +92,12 @@ public abstract class TileLoader extends PausableThread implements ITileDataSink
|
||||
*/
|
||||
@Override
|
||||
public void completed(QueryResult result) {
|
||||
boolean success = result == SUCCESS;
|
||||
boolean ok = (result == SUCCESS);
|
||||
|
||||
if (isCanceled())
|
||||
success = false;
|
||||
if (ok && (isCanceled() || isInterrupted()))
|
||||
ok = false;
|
||||
|
||||
if (isInterrupted())
|
||||
success = false;
|
||||
|
||||
mTileManager.jobCompleted(mTile, success);
|
||||
mTileManager.jobCompleted(mTile, ok);
|
||||
mTile = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,11 @@ public class BitmapTileLoader extends TileLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,13 @@ class S3DBTileLoader extends TileLoader {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
mTileDataSource.destroy();
|
||||
public void dispose() {
|
||||
mTileDataSource.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
mTileDataSource.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -83,7 +83,12 @@ public class TestTileLayer extends TileLayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,9 +81,15 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
public void dispose() {
|
||||
if (mTileDataSource != null)
|
||||
mTileDataSource.destroy();
|
||||
mTileDataSource.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
if (mTileDataSource != null)
|
||||
mTileDataSource.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,7 +155,7 @@ public class VectorTileLoader extends TileLoader implements IRenderTheme.Callbac
|
||||
}
|
||||
|
||||
public void setDataSource(ITileDataSource dataSource) {
|
||||
cleanup();
|
||||
dispose();
|
||||
mTileDataSource = dataSource;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010, 2011, 2012 mapsforge.org
|
||||
* Copyright 2012 Hannes Janetzek
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@@ -19,22 +18,20 @@ package org.oscim.tiling;
|
||||
|
||||
import org.oscim.layers.tile.MapTile;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface ITileDataSource {
|
||||
|
||||
/**
|
||||
* Starts a database query with the given parameters.
|
||||
*
|
||||
* @param tile
|
||||
* the tile to read.
|
||||
* the tile to load.
|
||||
* @param mapDataSink
|
||||
* the callback which handles the extracted map elements.
|
||||
* the callback to handle the extracted map elements.
|
||||
*/
|
||||
abstract void query(MapTile tile, ITileDataSink mapDataSink);
|
||||
|
||||
abstract void destroy();
|
||||
/** Implementations should cancel and release all resources */
|
||||
abstract void dispose();
|
||||
|
||||
/** Implementations should cancel their IO work and return */
|
||||
abstract void cancel();
|
||||
|
||||
}
|
||||
|
||||
@@ -98,7 +98,12 @@ public class UrlTileDataSource implements ITileDataSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void dispose() {
|
||||
mConn.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
mConn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,13 +213,13 @@ public class MapDatabase implements ITileDataSource {
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
// make sure that the file is closed
|
||||
destroy();
|
||||
dispose();
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void dispose() {
|
||||
mReadBuffer = null;
|
||||
if (mInputFile != null) {
|
||||
|
||||
@@ -232,6 +232,10 @@ public class MapDatabase implements ITileDataSource {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the debug signatures of the current way and block.
|
||||
*/
|
||||
|
||||
@@ -184,7 +184,11 @@ public class TestTileSource extends TileSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user