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.PatternCDATA_PATTERNprivate static java.util.concurrent.ConcurrentMap<java.lang.String,java.util.Set<org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener>>inProgress(package private) static java.util.regex.PatternJSON_PATTERNstatic LongPropertyMAXIMUM_EXPIRESGeneral maximum expires for tiles.static LongPropertyMINIMUM_EXPIRESGeneral minimum expires for tiles.private TileJobOptionsoptions(package private) static java.util.regex.PatternSERVICE_EXCEPTION_PATTERNprotected org.openstreetmap.gui.jmapviewer.Tiletileprivate java.net.URLurl-
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 booleancacheAsEmpty(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerFields, int responseCode)Simple implementation.protected BufferedImageCacheEntrycreateCacheEntry(byte[] content)java.lang.StringdetectErrorMessage(java.lang.String data)Tries do detect an error message from given string.java.lang.StringgetCacheKey()returns cache entry keyprotected java.lang.StringgetServerKey()For TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers)java.net.URLgetUrl()method to get download URL for Jobprivate voidhandleError(CacheEntryAttributes attributes)private booleanhandleNoTileAtZoom()private booleanisNoTileAtZoom()private booleanisNotImage(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, int statusCode)booleanisObjectLoadable()Checks if object from cache has sufficient data to be returned.protected booleanisResponseLoadable(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers, int statusCode, byte[] content)Check if the object is loadable.voidloadingFinished(CacheEntry object, CacheEntryAttributes attributes, ICachedLoaderListener.LoadResult result)Will be called when K object processed.protected CacheEntryAttributesparseHeaders(HttpClient.Response urlConn)private static java.lang.StringremoveCdata(java.lang.String msg)voidsubmit()voidsubmit(boolean force)private booleantryLoadTileImage(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:ICachedLoaderJobreturns cache entry key- Specified by:
getCacheKeyin interfaceICachedLoaderJob<java.lang.String>- Returns:
- cache key for tile
-
getUrl
public java.net.URL getUrl() throws java.io.IOException
Description copied from interface:ICachedLoaderJobmethod to get download URL for Job- Specified by:
getUrlin 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:JCSCachedTileLoaderJobChecks if object from cache has sufficient data to be returned.- Overrides:
isObjectLoadablein classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>- Returns:
trueif 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:JCSCachedTileLoaderJobCheck 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:
isResponseLoadablein 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:JCSCachedTileLoaderJobSimple 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:
cacheAsEmptyin 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:
submitin interfaceorg.openstreetmap.gui.jmapviewer.interfaces.TileJob
-
loadingFinished
public void loadingFinished(CacheEntry object, CacheEntryAttributes attributes, ICachedLoaderListener.LoadResult result)
Description copied from interface:ICachedLoaderListenerWill 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:
loadingFinishedin 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:
getServerKeyin 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:
createCacheEntryin classJCSCachedTileLoaderJob<java.lang.String,BufferedImageCacheEntry>
-
submit
public void submit()
- Specified by:
submitin interfaceorg.openstreetmap.gui.jmapviewer.interfaces.TileJob
-
parseHeaders
protected CacheEntryAttributes parseHeaders(HttpClient.Response urlConn)
- Overrides:
parseHeadersin 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:JCSCachedTileLoaderJobTries do detect an error message from given string.- Overrides:
detectErrorMessagein 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)
-
-