Ignore:
Timestamp:
2015-07-12T23:55:18+02:00 (9 years ago)
Author:
wiktorn
Message:

TileSource:

  • added method - getTileId that returns unique identifier for the tile, that should not collide with other tile sources
  • added JavaDocs

JCSCacheManager:

  • moved from object count limit to object size limit
  • fixed bug with unnecessary re-creation of auxilary cache, that could result in cache corruption/loss of current cache data

CachedTileLoaderFactory, WMSCachedTileLoader, TMSCachedTileLoader

  • un-abstract CachedTileLoaderFactory, use reflection to create TileLoaders
  • adjust constructors

TMSCachedTileLoader, AbstractCachedTileSourceLayer:

  • move cache related settings to AbstractCachedTileSourceLayer
  • move cache instation to AbstractCachedTileSourceLayer
  • make "flush tile cache" command clear only one tile source

TMSCachedTileLoaderJob:

  • make "flush tile cache" command clear only one tile source
  • reorder methods

TemplatedWMSTileSource:

  • java docs
  • inline of private methods: getTileXMax, getTileYMax
  • fix sonar issues
  • make WMS layer zoom levels closer to TMS (addresses: #11459)

WMTSTileSource:

  • fix Sonar issues
  • use topLeftCorner in X/Y tile max calculations instead of world bounds (fixes issues with WMTS-es, for which topLeftCorner lies outside projection world bounds)

AbstractTileSourceLayer:

  • draw warning, when min-zoom-level is set, and tiles are not loaded due to too many tiles on screen

TMSLayer, WMSLayer, WMTSLayer:

  • expose access to cache object for ImageryPreferences

CacheContentsPanel:

  • add panel for managing cache regions and tile sources within the regions

CommonSettingsPanel, TMSSettingsPanel:

  • move settings common to all imagery layers from TMSSettingsPanel to CommonSettingsPanel
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/CachedTileLoaderFactory.java

    r8530 r8598  
    33
    44import java.io.File;
    5 import java.io.IOException;
    6 import java.util.HashMap;
     5import java.lang.reflect.Constructor;
     6import java.lang.reflect.InvocationTargetException;
    77import java.util.Map;
     8import java.util.concurrent.ConcurrentHashMap;
    89
     10import org.apache.commons.jcs.access.behavior.ICacheAccess;
    911import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader;
    1012import org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener;
    1113import org.openstreetmap.josm.Main;
    1214import org.openstreetmap.josm.data.Version;
     15import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    1316import org.openstreetmap.josm.data.preferences.StringProperty;
    1417
     
    1922 * @since 8526
    2023 */
    21 public abstract class CachedTileLoaderFactory implements TileLoaderFactory {
     24public class CachedTileLoaderFactory implements TileLoaderFactory {
    2225    /**
    2326     * Keeps the cache directory where
    2427     */
    2528    public static final StringProperty PROP_TILECACHE_DIR = getTileCacheDir();
    26     private String cacheName;
     29    private ICacheAccess<String, BufferedImageCacheEntry> cache;
     30    private Constructor<? extends TileLoader> tileLoaderConstructor;
    2731
    2832    /**
    29      * @param cacheName name of the cache region, that the created loader will use
     33     * @param cache cache instance which will be used by tile loaders created by this tile loader
     34     * @param tileLoaderClass tile loader class that will be created
     35     *
    3036     */
    31     public CachedTileLoaderFactory(String cacheName) {
    32         this.cacheName = cacheName;
     37    public CachedTileLoaderFactory(ICacheAccess<String, BufferedImageCacheEntry> cache, Class<? extends TileLoader> tileLoaderClass) {
     38        this.cache = cache;
     39        try {
     40            tileLoaderConstructor = tileLoaderClass.getConstructor(
     41                    TileLoaderListener.class,
     42                    ICacheAccess.class,
     43                    int.class,
     44                    int.class,
     45                    Map.class);
     46        } catch (NoSuchMethodException | SecurityException e) {
     47            Main.warn(e);
     48            throw new RuntimeException(e);
     49        }
    3350    }
    3451
     
    5067    @Override
    5168    public TileLoader makeTileLoader(TileLoaderListener listener, Map<String, String> inputHeaders) {
    52         Map<String, String> headers = new HashMap<>();
     69        Map<String, String> headers = new ConcurrentHashMap<>();
    5370        headers.put("User-Agent", Version.getInstance().getFullAgentString());
    5471        headers.put("Accept", "text/html, image/png, image/jpeg, image/gif, */*");
     
    5673            headers.putAll(inputHeaders);
    5774
    58         try {
    59             return getLoader(listener, cacheName,
    60                     Main.pref.getInteger("socket.timeout.connect", 15) * 1000,
    61                     Main.pref.getInteger("socket.timeout.read", 30) * 1000,
    62                     headers,
    63                     PROP_TILECACHE_DIR.get());
    64         } catch (IOException e) {
    65             Main.warn(e);
    66         }
    67         return null;
     75        return getLoader(listener, cache,
     76                Main.pref.getInteger("socket.timeout.connect", 15) * 1000,
     77                Main.pref.getInteger("socket.timeout.read", 30) * 1000,
     78                headers);
    6879    }
    6980
    70     protected abstract TileLoader getLoader(TileLoaderListener listener, String cacheName, int connectTimeout, int readTimeout,
    71             Map<String, String> headers, String cacheDir) throws IOException;
     81    protected TileLoader getLoader(TileLoaderListener listener, ICacheAccess<String, BufferedImageCacheEntry> cache,
     82            int connectTimeout, int readTimeout, Map<String, String> headers) {
     83        try {
     84            return tileLoaderConstructor.newInstance(
     85                    listener,
     86                    cache,
     87                    connectTimeout,
     88                    readTimeout,
     89                    headers);
     90        } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
     91            Main.warn(e);
     92            throw new RuntimeException(e);
     93        }
     94    }
    7295}
Note: See TracChangeset for help on using the changeset viewer.