Ignore:
Timestamp:
2013-03-16T17:22:07+01:00 (11 years ago)
Author:
akks
Message:

JOSM/ImageryCache: corrected cache file name, added imagerycache.debug option

Location:
applications/editors/josm/plugins/imagerycache
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagerycache/build.xml

    r29363 r29368  
    1515
    1616    <!-- enter the SVN commit message -->
    17     <property name="commit.message" value="JOSM/ImageryCache: Initial commit"/>
     17    <property name="commit.message" value="JOSM/ImageryCache: corrected cache file name, added imagerycache.debug option"/>
    1818    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    1919    <property name="plugin.main.version" value="5779"/>
  • applications/editors/josm/plugins/imagerycache/src/org/openstreetmap/josm/plugins/imagerycache/OsmDBTilesLoader.java

    r29363 r29368  
    1313import java.util.Map;
    1414import java.util.Random;
    15 import java.util.logging.Level;
    16 import java.util.logging.Logger;
    1715import org.mapdb.DB;
    1816import org.mapdb.DBMaker;
    19 import org.mapdb.Serializer;
    2017import org.openstreetmap.gui.jmapviewer.JobDispatcher;
    2118import org.openstreetmap.gui.jmapviewer.OsmTileLoader;
     
    2522import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    2623import org.openstreetmap.gui.jmapviewer.interfaces.TileSource.TileUpdate;
     24import org.openstreetmap.josm.data.preferences.BooleanProperty;
    2725
    2826/**
     
    3331   
    3432   
    35     private static final Logger log = Logger.getLogger(OsmDBTilesLoader.class.getName());
    3633    public static final long FILE_AGE_ONE_DAY = 1000 * 60 * 60 * 24;
    3734    public static final long FILE_AGE_ONE_WEEK = FILE_AGE_ONE_DAY * 7;
    38 
    39    
    40    
     35   
     36    public static final boolean debug = new BooleanProperty("imagerycache.debug", false).get();
     37
    4138    static class TileDAOMapDB {
    4239        protected HashMap<String, DB> dbs = new HashMap<String, DB>();
     
    5350                try {
    5451                db = DBMaker
    55                     .newFileDB(new File(cacheFolder, source.replaceAll("[\\\\/:*?\"<>| ]", "_")))
     52                    .newFileDB(new File(cacheFolder, "tiles_"+source.replaceAll("[\\\\/:*?\"<>| ]", "_")))
    5653                    .randomAccessFileEnableIfNeeded()
    5754                    .journalDisable()
     
    6057                dbs.put(source, db);
    6158                } catch (Exception e) {
    62                     log.warning("Error: Can not create MapDB file");
    63                     e.printStackTrace();
     59                    System.out.println("Error: Can not create MapDB file");
     60                    e.printStackTrace(System.out);
    6461                }
    6562            }
     
    7471                    m = d.getHashMap("tiles");
    7572                    storages.put(source, m);
    76                     log.log(Level.FINEST, "Created storage {0}", source);
     73                    if (debug) System.out.println("Created storage "+source);
    7774                } catch (Exception e) {
    78                     log.severe("Error: Can not create HashMap in MapDB storage");
    79                     e.printStackTrace();
     75                    System.out.println("Error: Can not create HashMap in MapDB storage");
     76                    e.printStackTrace(System.out);
    8077                }
    8178            }
     
    9390
    9491        protected void updateModTime(String source, long id, DBTile dbTile) {
    95             log.finest("Updating modification time");
     92            if (debug) System.out.println("Tile "+id+": Updating modification time");
    9693            getStorage(source).put(id, dbTile);
    9794        }
    9895
    9996        protected void updateTile(String source, long id, DBTile dbTile) {
    100             log.finest("Updating tile in base");
     97            if (debug) System.out.println("Tile "+id+": Updating tile in base");
    10198            getStorage(source).put(id, dbTile);
    10299        }
     
    240237                    case LastModified:      // (2)
    241238                        if (!isOsmTileNewer(fileAge)) {
    242                             log.finest("LastModified test: local version is up to date: " + tile);
     239                            System.out.println("Tile "+id+": LastModified test: local version is up to date");
    243240                            dbTile.lastModified = getLastModTime();
    244241                            dao.updateModTime(sourceName, id, dbTile);
     
    271268                    // If we are isModifiedSince or If-None-Match has been set
    272269                    // and the server answers with a HTTP 304 = "Not Modified"
    273                     log.finest("Answer from HTTP: 304 / ETag test: local version is up to date: " + tile);
     270                    if (debug) System.out.println("Tile "+id+": Answer from HTTP=304 / ETag test: local version is up to date");
    274271                    dbTile.lastModified = getLastModTime();
    275272                    dao.updateModTime(sourceName, id, dbTile);
     
    290287                            continue;
    291288                        }
    292                         log.log(Level.FINE, "Loading from OSM{0}", tile);
     289                        if (debug) System.out.println("Tile "+id+": Loading from OSM, "+ tile);
    293290                        byte[] buffer = loadTileInBuffer(urlConn);
    294291                        if (buffer != null) {
     
    308305                listener.tileLoadingFinished(tile, false);
    309306                try {
    310                     log.log(Level.SEVERE, "Failed loading {0}: {1}", new Object[]{tile.getUrl(), e.getMessage()});
    311                     e.printStackTrace();
     307                    System.out.println("Tile "+id+": Error: Failed loading from "+tile.getUrl());
     308                    e.printStackTrace(System.out);
    312309                } catch(IOException i) {
    313310                }
Note: See TracChangeset for help on using the changeset viewer.