Class TMSCachedTileLoaderJob
- java.lang.Object
-
- org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
-
- org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob
-
- All Implemented Interfaces:
java.lang.Runnable
,org.openstreetmap.gui.jmapviewer.interfaces.TileJob
,ICachedLoaderJob<java.lang.String>
,ICachedLoaderListener
- Direct Known Subclasses:
MapboxVectorCachedTileLoaderJob
,WMSCachedTileLoaderJob
public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry> implements org.openstreetmap.gui.jmapviewer.interfaces.TileJob, ICachedLoaderListener
Class bridging TMS requests to JCS cache requests- Since:
- 8168
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.data.cache.ICachedLoaderListener
ICachedLoaderListener.LoadResult
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static java.util.regex.Pattern
CDATA_PATTERN
private static java.util.concurrent.ConcurrentMap<java.lang.String,java.util.Set<org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener>>
inProgress
(package private) static java.util.regex.Pattern
JSON_PATTERN
static LongProperty
MAXIMUM_EXPIRES
General maximum expires for tiles.static LongProperty
MINIMUM_EXPIRES
General minimum expires for tiles.private TileJobOptions
options
(package private) static java.util.regex.Pattern
SERVICE_EXCEPTION_PATTERN
protected org.openstreetmap.gui.jmapviewer.Tile
tile
private java.net.URL
url
-
Fields inherited from class org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob
ABSOLUTE_EXPIRE_TIME_LIMIT, attributes, cache, cacheData, DEFAULT_EXPIRE_TIME, EXPIRE_TIME_SERVER_LIMIT, now, THREAD_LIMIT
-
-
Constructor Summary
Constructors Constructor Description TMSCachedTileLoaderJob(org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener, org.openstreetmap.gui.jmapviewer.Tile tile, org.apache.commons.jcs3.access.behavior.ICacheAccess<java.lang.String,BufferedImageCacheEntry> cache, TileJobOptions options, java.util.concurrent.ThreadPoolExecutor downloadExecutor)
Constructor for creating a job, to get a specific tile from cache
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
cacheAsEmpty(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerFields, int responseCode)
Simple implementation.protected BufferedImageCacheEntry
createCacheEntry(byte[] content)
java.lang.String
detectErrorMessage(java.lang.String data)
Tries do detect an error message from given string.java.lang.String
getCacheKey()
returns cache entry keyprotected java.lang.String
getServerKey()
For TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers)java.net.URL
getUrl()
method to get download URL for Jobprivate void
handleError(CacheEntryAttributes attributes)
private boolean
handleNoTileAtZoom()
private boolean
isNoTileAtZoom()
private boolean
isNotImage(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, int statusCode)
boolean
isObjectLoadable()
Checks if object from cache has sufficient data to be returned.protected boolean
isResponseLoadable(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, int statusCode, byte[] content)
Check if the object is loadable.void
loadingFinished(CacheEntry object, CacheEntryAttributes attributes, ICachedLoaderListener.LoadResult result)
Will be called when K object processed.protected CacheEntryAttributes
parseHeaders(HttpClient.Response urlConn)
private static java.lang.String
removeCdata(java.lang.String msg)
void
submit()
void
submit(boolean force)
private boolean
tryLoadTileImage(CacheEntry object)
-
Methods inherited from class org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob
cancelOutstandingTasks, executionFinished, get, handleJobCancellation, isCacheElementValid, loadObject, run, setFinishedTask, submit
-
-
-
-
Field Detail
-
MAXIMUM_EXPIRES
public static final LongProperty MAXIMUM_EXPIRES
General maximum expires for tiles. Might be overridden by imagery settings
-
MINIMUM_EXPIRES
public static final LongProperty MINIMUM_EXPIRES
General minimum expires for tiles. Might be overridden by imagery settings
-
SERVICE_EXCEPTION_PATTERN
static final java.util.regex.Pattern SERVICE_EXCEPTION_PATTERN
-
CDATA_PATTERN
static final java.util.regex.Pattern CDATA_PATTERN
-
JSON_PATTERN
static final java.util.regex.Pattern JSON_PATTERN
-
tile
protected final org.openstreetmap.gui.jmapviewer.Tile tile
-
url
private volatile java.net.URL url
-
options
private final TileJobOptions options
-
inProgress
private static final java.util.concurrent.ConcurrentMap<java.lang.String,java.util.Set<org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener>> inProgress
-
-
Constructor Detail
-
TMSCachedTileLoaderJob
public TMSCachedTileLoaderJob(org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener, org.openstreetmap.gui.jmapviewer.Tile tile, org.apache.commons.jcs3.access.behavior.ICacheAccess<java.lang.String,BufferedImageCacheEntry> cache, TileJobOptions options, java.util.concurrent.ThreadPoolExecutor downloadExecutor)
Constructor for creating a job, to get a specific tile from cache- Parameters:
listener
- Tile loader listenertile
- to be fetched from cachecache
- objectoptions
- for job (such as http headers, timeouts etc.)downloadExecutor
- that will be executing the jobs
-
-
Method Detail
-
getCacheKey
public java.lang.String getCacheKey()
Description copied from interface:ICachedLoaderJob
returns cache entry key- Specified by:
getCacheKey
in interfaceICachedLoaderJob<java.lang.String>
- Returns:
- cache key for tile
-
getUrl
public java.net.URL getUrl() throws java.io.IOException
Description copied from interface:ICachedLoaderJob
method to get download URL for Job- Specified by:
getUrl
in interfaceICachedLoaderJob<java.lang.String>
- Returns:
- URL that should be fetched
- Throws:
java.io.IOException
- when could not determine the URL of the tile
-
isObjectLoadable
public boolean isObjectLoadable()
Description copied from class:JCSCachedTileLoaderJob
Checks if object from cache has sufficient data to be returned.- Overrides:
isObjectLoadable
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
- Returns:
true
if object from cache has sufficient data to be returned
-
isResponseLoadable
protected boolean isResponseLoadable(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, int statusCode, byte[] content)
Description copied from class:JCSCachedTileLoaderJob
Check if the object is loadable. This means, if the data will be parsed, and if this response will finish as successful retrieve.This simple implementation doesn't load empty response, nor client (4xx) and server (5xx) errors
- Overrides:
isResponseLoadable
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
- Parameters:
headers
- headers sent by serverstatusCode
- http status codecontent
- data read from server- Returns:
- true if object should be cached and returned to listener
-
isNotImage
private boolean isNotImage(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, int statusCode)
-
cacheAsEmpty
protected boolean cacheAsEmpty(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerFields, int responseCode)
Description copied from class:JCSCachedTileLoaderJob
Simple implementation. All errors should be cached as empty. Though some JDK (JDK8 on Windows for example) doesn't return 4xx error codes, instead they do throw an FileNotFoundException or IOException- Overrides:
cacheAsEmpty
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
- Parameters:
headerFields
- headers sent by serverresponseCode
- http status code- Returns:
- true if we should put empty object into cache, regardless of what remote resource has returned
-
submit
public void submit(boolean force)
- Specified by:
submit
in interfaceorg.openstreetmap.gui.jmapviewer.interfaces.TileJob
-
loadingFinished
public void loadingFinished(CacheEntry object, CacheEntryAttributes attributes, ICachedLoaderListener.LoadResult result)
Description copied from interface:ICachedLoaderListener
Will be called when K object processed. The result might be: LoadResult.SUCCESS when object was fetched LoadResult.FAILURE when there was a failure during download LoadResult.REJECTED when job was rejected because of full queue- Specified by:
loadingFinished
in interfaceICachedLoaderListener
- Parameters:
object
- cache entry contentsattributes
- cache entry attributesresult
- load result (success, failure, canceled)
-
handleError
private void handleError(CacheEntryAttributes attributes)
-
getServerKey
protected java.lang.String getServerKey()
For TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers)- Overrides:
getServerKey
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
- Returns:
- base URL of TMS or server url as defined in super class
-
createCacheEntry
protected BufferedImageCacheEntry createCacheEntry(byte[] content)
- Specified by:
createCacheEntry
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
-
submit
public void submit()
- Specified by:
submit
in interfaceorg.openstreetmap.gui.jmapviewer.interfaces.TileJob
-
parseHeaders
protected CacheEntryAttributes parseHeaders(HttpClient.Response urlConn)
- Overrides:
parseHeaders
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
-
handleNoTileAtZoom
private boolean handleNoTileAtZoom()
-
isNoTileAtZoom
private boolean isNoTileAtZoom()
-
tryLoadTileImage
private boolean tryLoadTileImage(CacheEntry object) throws java.io.IOException
- Throws:
java.io.IOException
-
detectErrorMessage
public java.lang.String detectErrorMessage(java.lang.String data)
Description copied from class:JCSCachedTileLoaderJob
Tries do detect an error message from given string.- Overrides:
detectErrorMessage
in classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
- Parameters:
data
- string to analyze- Returns:
- error message if detected, or null
-
removeCdata
private static java.lang.String removeCdata(java.lang.String msg)
-
-