TileDataSource: catch unexpected errors (#943)
This commit is contained in:
parent
d89a402375
commit
e86bf54d8a
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019 Kostas Tzounopoulos
|
* Copyright 2019 Kostas Tzounopoulos
|
||||||
|
* Copyright 2022 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -27,7 +28,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -134,7 +134,8 @@ public class MBTilesMvtTileDataSource extends MBTilesTileDataSource {
|
|||||||
responseDataSink.completed(success ? QueryResult.SUCCESS : QueryResult.FAILED);
|
responseDataSink.completed(success ? QueryResult.SUCCESS : QueryResult.FAILED);
|
||||||
} else
|
} else
|
||||||
responseDataSink.completed(QueryResult.TILE_NOT_FOUND);
|
responseDataSink.completed(QueryResult.TILE_NOT_FOUND);
|
||||||
} catch (IOException e) {
|
} catch (Throwable t) {
|
||||||
|
log.error(t.getMessage(), t);
|
||||||
responseDataSink.completed(QueryResult.FAILED);
|
responseDataSink.completed(QueryResult.FAILED);
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null)
|
if (cursor != null)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2019 Andrea Antonello
|
* Copyright 2019 Andrea Antonello
|
||||||
* Copyright 2019 devemux86
|
* Copyright 2019-2022 devemux86
|
||||||
* Copyright 2019 Kostas Tzounopoulos
|
* Copyright 2019 Kostas Tzounopoulos
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
@ -124,8 +124,8 @@ public class MBTilesBitmapTileDataSource extends MBTilesTileDataSource {
|
|||||||
Bitmap bitmap = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(bytes));
|
Bitmap bitmap = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(bytes));
|
||||||
sink.setTileImage(bitmap);
|
sink.setTileImage(bitmap);
|
||||||
res = QueryResult.SUCCESS;
|
res = QueryResult.SUCCESS;
|
||||||
} catch (Exception e) {
|
} catch (Throwable t) {
|
||||||
log.debug("{} invalid bitmap", tile);
|
log.error(t.getMessage(), t);
|
||||||
} finally {
|
} finally {
|
||||||
sink.completed(res);
|
sink.completed(res);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2013 Hannes Janetzek
|
* Copyright 2013 Hannes Janetzek
|
||||||
|
* Copyright 2022 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -64,8 +65,8 @@ public abstract class TileLoader extends PausableThread implements ITileDataSink
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
loadTile(mTile);
|
loadTile(mTile);
|
||||||
} catch (Exception e) {
|
} catch (Throwable t) {
|
||||||
e.printStackTrace();
|
t.printStackTrace();
|
||||||
completed(FAILED);
|
completed(FAILED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,9 +121,9 @@ public class VectorTileLoader extends TileLoader implements RenderStyle.Callback
|
|||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
log.debug("NPE {} {}", tile, e.getMessage());
|
log.debug("NPE {} {}", tile, e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (Exception e) {
|
} catch (Throwable t) {
|
||||||
log.debug("{} {}", tile, e.getMessage());
|
log.debug("{} {}", tile, t.getMessage());
|
||||||
e.printStackTrace();
|
t.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 devemux86
|
* Copyright 2018-2022 devemux86
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it under the
|
* This program is free software: you can redistribute it and/or modify it under the
|
||||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||||
@ -15,9 +15,13 @@
|
|||||||
package org.oscim.tiling;
|
package org.oscim.tiling;
|
||||||
|
|
||||||
import org.oscim.layers.tile.MapTile;
|
import org.oscim.layers.tile.MapTile;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class OverzoomTileDataSource implements ITileDataSource {
|
public class OverzoomTileDataSource implements ITileDataSource {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(OverzoomTileDataSource.class);
|
||||||
|
|
||||||
private final ITileDataSource tileDataSource;
|
private final ITileDataSource tileDataSource;
|
||||||
private final int overZoom;
|
private final int overZoom;
|
||||||
|
|
||||||
@ -32,14 +36,18 @@ public class OverzoomTileDataSource implements ITileDataSource {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void query(MapTile tile, ITileDataSink sink) {
|
public void query(MapTile tile, ITileDataSink sink) {
|
||||||
MapTile mapTile = tile;
|
try {
|
||||||
ITileDataSink dataSink = sink;
|
MapTile mapTile = tile;
|
||||||
int diff = tile.zoomLevel - overZoom;
|
ITileDataSink dataSink = sink;
|
||||||
if (diff > 0) {
|
int diff = tile.zoomLevel - overZoom;
|
||||||
mapTile = new MapTile(tile.node, tile.tileX >> diff, tile.tileY >> diff, overZoom);
|
if (diff > 0) {
|
||||||
dataSink = new OverzoomDataSink(sink, mapTile, tile);
|
mapTile = new MapTile(tile.node, tile.tileX >> diff, tile.tileY >> diff, overZoom);
|
||||||
|
dataSink = new OverzoomDataSink(sink, mapTile, tile);
|
||||||
|
}
|
||||||
|
tileDataSource.query(mapTile, dataSink);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.error(t.getMessage(), t);
|
||||||
}
|
}
|
||||||
tileDataSource.query(mapTile, dataSink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012 Hannes Janetzek
|
* Copyright 2012 Hannes Janetzek
|
||||||
* Copyright 2017 devemux86
|
* Copyright 2017-2022 devemux86
|
||||||
*
|
*
|
||||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||||
*
|
*
|
||||||
@ -34,12 +34,9 @@ import java.net.SocketException;
|
|||||||
import java.net.SocketTimeoutException;
|
import java.net.SocketTimeoutException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
import static org.oscim.tiling.QueryResult.DELAYED;
|
|
||||||
import static org.oscim.tiling.QueryResult.FAILED;
|
|
||||||
import static org.oscim.tiling.QueryResult.SUCCESS;
|
|
||||||
|
|
||||||
public class UrlTileDataSource implements ITileDataSource {
|
public class UrlTileDataSource implements ITileDataSource {
|
||||||
static final Logger log = LoggerFactory.getLogger(UrlTileDataSource.class);
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(UrlTileDataSource.class);
|
||||||
|
|
||||||
protected final HttpEngine mConn;
|
protected final HttpEngine mConn;
|
||||||
protected final ITileDecoder mTileDecoder;
|
protected final ITileDecoder mTileDecoder;
|
||||||
@ -57,27 +54,27 @@ public class UrlTileDataSource implements ITileDataSource {
|
|||||||
public void query(MapTile tile, ITileDataSink sink) {
|
public void query(MapTile tile, ITileDataSink sink) {
|
||||||
ITileCache cache = mTileSource.tileCache;
|
ITileCache cache = mTileSource.tileCache;
|
||||||
|
|
||||||
if (mUseCache) {
|
QueryResult res = QueryResult.FAILED;
|
||||||
TileReader c = cache.getTile(tile);
|
|
||||||
if (c != null) {
|
|
||||||
InputStream is = c.getInputStream();
|
|
||||||
try {
|
|
||||||
if (mTileDecoder.decode(tile, sink, is)) {
|
|
||||||
sink.completed(SUCCESS);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.debug("{} Cache read: {}", tile, e);
|
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(is);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QueryResult res = FAILED;
|
|
||||||
|
|
||||||
TileWriter cacheWriter = null;
|
TileWriter cacheWriter = null;
|
||||||
try {
|
try {
|
||||||
|
if (mUseCache) {
|
||||||
|
TileReader c = cache.getTile(tile);
|
||||||
|
if (c != null) {
|
||||||
|
InputStream is = c.getInputStream();
|
||||||
|
try {
|
||||||
|
if (mTileDecoder.decode(tile, sink, is)) {
|
||||||
|
sink.completed(QueryResult.SUCCESS);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.debug("{} Cache read: {}", tile, e);
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeQuietly(is);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mConn.sendRequest(tile);
|
mConn.sendRequest(tile);
|
||||||
InputStream is = mConn.read();
|
InputStream is = mConn.read();
|
||||||
if (mUseCache) {
|
if (mUseCache) {
|
||||||
@ -85,23 +82,25 @@ public class UrlTileDataSource implements ITileDataSource {
|
|||||||
mConn.setCache(cacheWriter.getOutputStream());
|
mConn.setCache(cacheWriter.getOutputStream());
|
||||||
}
|
}
|
||||||
if (mTileDecoder.decode(tile, sink, is))
|
if (mTileDecoder.decode(tile, sink, is))
|
||||||
res = SUCCESS;
|
res = QueryResult.SUCCESS;
|
||||||
} catch (SocketException e) {
|
} catch (SocketException e) {
|
||||||
log.debug("{} Socket Error: {}", tile, e.getMessage());
|
log.debug("{} Socket Error: {}", tile, e.getMessage());
|
||||||
} catch (SocketTimeoutException e) {
|
} catch (SocketTimeoutException e) {
|
||||||
log.debug("{} Socket Timeout", tile);
|
log.debug("{} Socket Timeout", tile);
|
||||||
res = DELAYED;
|
res = QueryResult.DELAYED;
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
log.debug("{} Unknown host: {}", tile, e.getMessage());
|
log.debug("{} Unknown host: {}", tile, e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.debug("{} Network Error: {}", tile, e.getMessage());
|
log.debug("{} Network Error: {}", tile, e.getMessage());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("{} Error: {}", tile, e.getMessage());
|
log.debug("{} Error: {}", tile, e.getMessage());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.error(t.getMessage(), t);
|
||||||
} finally {
|
} finally {
|
||||||
boolean ok = (res == SUCCESS);
|
boolean ok = (res == QueryResult.SUCCESS);
|
||||||
|
|
||||||
if (!mConn.requestCompleted(ok) && ok)
|
if (!mConn.requestCompleted(ok) && ok)
|
||||||
res = FAILED;
|
res = QueryResult.FAILED;
|
||||||
|
|
||||||
if (cacheWriter != null)
|
if (cacheWriter != null)
|
||||||
cacheWriter.complete(ok);
|
cacheWriter.complete(ok);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user