Changeset 30738 in osm for applications/editors/josm/plugins/imagerycache/src
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/OsmDBTilesLoader.java
r29769 r30738 11 11 import java.util.Map; 12 12 import java.util.Random; 13 13 14 import org.openstreetmap.gui.jmapviewer.JobDispatcher; 14 15 import org.openstreetmap.gui.jmapviewer.OsmTileLoader; … … 20 21 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 21 22 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource.TileUpdate; 23 import org.openstreetmap.josm.Main; 22 24 import org.openstreetmap.josm.data.preferences.BooleanProperty; 23 25 24 26 /** 25 * 27 * 26 28 * @author Alexei Kasatkin, based on OsmFileCacheTileLoader by @author Jan Peter Stotz, @author Stefan Zeller 27 29 */ 28 30 class OsmDBTilesLoader extends OsmTileLoader implements CachedTileLoader { 29 30 31 32 31 33 public static final long FILE_AGE_ONE_DAY = 1000 * 60 * 60 * 24; 32 34 public static final long FILE_AGE_ONE_WEEK = FILE_AGE_ONE_DAY * 7; 33 35 34 36 public static final boolean debug = new BooleanProperty("imagerycache.debug", false).get(); 35 37 36 38 TileDAOMapDB dao; 37 39 38 40 protected long maxCacheFileAge = FILE_AGE_ONE_WEEK; 39 41 protected long recheckAfter = FILE_AGE_ONE_DAY; 40 42 41 43 42 44 public OsmDBTilesLoader(TileLoaderListener smap, File cacheFolder) { 43 45 super(smap); … … 45 47 dao.setCacheFolder(cacheFolder); 46 48 } 47 49 48 50 @Override 49 51 public TileJob createTileLoaderJob(final Tile tile) { … … 60 62 dao.cleanStorage(source.getName()); 61 63 } 62 64 63 65 protected class DatabaseLoadJob implements TileJob { 64 66 65 67 private final Tile tile; 66 68 File tileCacheDir; 67 69 68 70 /** 69 * Stores the tile loaded from database, null if nothing found. 71 * Stores the tile loaded from database, null if nothing found. 70 72 */ 71 73 DBTile dbTile = null; 72 74 long fileAge = 0; 73 75 74 76 long id; 75 77 String sourceName; 76 78 77 79 public DatabaseLoadJob(Tile tile) { 78 80 this.tile = tile; … … 112 114 113 115 /** 114 * Loads tile from database. 116 * Loads tile from database. 115 117 * There can be dbTile != null but the tile is outdated and reload is still needed 116 118 * @return true if no loading from server is needed. … … 120 122 try { 121 123 dbTile = dao.getById(sourceName, id); 122 124 123 125 if (dbTile == null) return false; 124 125 loadMetadata(); 126 127 loadMetadata(); 126 128 if (debug) System.out.println(id+": found in cache, metadata ="+dbTile.metaData); 127 129 … … 149 151 } 150 152 } catch (Exception e) { 151 System.out.println("Error: Can not load tile from database: "+sourceName+":"+id);152 e.printStackTrace(System.out);153 Main.error("Error: Can not load tile from database: "+sourceName+":"+id); 154 Main.error(e); 153 155 try { 154 156 if (bin != null) { … … 161 163 return false; // tile is not because of some error (corrupted database, etc.) 162 164 } catch (Error e) { // this is bad, bat MapDB throws it 163 System.out.println("Serious database error: Can not load tile from database: "+sourceName+":"+id);164 e.printStackTrace(System.out);165 dbTile = null; fileAge = 0; return false; 165 Main.error("Serious database error: Can not load tile from database: "+sourceName+":"+id); 166 Main.error(e); 167 dbTile = null; fileAge = 0; return false; 166 168 } 167 169 } … … 170 172 return System.currentTimeMillis() - maxCacheFileAge + recheckAfter; 171 173 } 172 174 173 175 private void loadOrUpdateTileFromServer() { 174 176 175 177 try { 176 178 URLConnection urlConn = loadTileFromOsm(tile); … … 195 197 dbTile = new DBTile(); 196 198 } 197 199 198 200 if (tileUpdate == TileSource.TileUpdate.ETag || tileUpdate == TileSource.TileUpdate.IfNoneMatch) { 199 201 String fileETag = tile.getValue("etag"); … … 224 226 loadTileMetadata(tile, urlConn); 225 227 dbTile.metaData = tile.getMetadata(); 226 228 227 229 if ("no-tile".equals(tile.getValue("tile-info"))) 228 230 { … … 248 250 } 249 251 } 250 252 251 253 } catch (Exception e) { 252 254 tile.setError(e.getMessage()); … … 261 263 } 262 264 } 263 264 265 266 265 267 protected byte[] loadTileInBuffer(URLConnection urlConn) throws IOException { 266 268 InputStream input = urlConn.getInputStream(); … … 292 294 * </ul> 293 295 * 294 * @param fileAge time of the 296 * @param fileAge time of the 295 297 * @return <code>true</code> if the tile on the server is newer than the 296 298 * file
Note:
See TracChangeset
for help on using the changeset viewer.