Class TMSCachedTileLoaderJob
java.lang.Object
org.openstreetmap.josm.data.cache.JCSCachedTileLoaderJob<String,BufferedImageCacheEntry>
org.openstreetmap.josm.data.imagery.TMSCachedTileLoaderJob
- All Implemented Interfaces:
Runnable,org.openstreetmap.gui.jmapviewer.interfaces.TileJob,ICachedLoaderJob<String>,ICachedLoaderListener
- Direct Known Subclasses:
MapboxVectorCachedTileLoaderJob,WMSCachedTileLoaderJob
public class TMSCachedTileLoaderJob
extends JCSCachedTileLoaderJob<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
FieldsModifier and TypeFieldDescription(package private) static final Patternprivate static final ConcurrentMap<String,Set<org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener>> (package private) static final Patternstatic final LongPropertyGeneral maximum expires for tiles.static final LongPropertyGeneral minimum expires for tiles.private final TileJobOptions(package private) static final Patternprotected final org.openstreetmap.gui.jmapviewer.Tileprivate URLFields 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
ConstructorsConstructorDescriptionTMSCachedTileLoaderJob(org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener, org.openstreetmap.gui.jmapviewer.Tile tile, org.apache.commons.jcs3.access.behavior.ICacheAccess<String, BufferedImageCacheEntry> cache, TileJobOptions options, ThreadPoolExecutor downloadExecutor) Constructor for creating a job, to get a specific tile from cache -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancacheAsEmpty(Map<String, List<String>> headerFields, int responseCode) Simple implementation.protected BufferedImageCacheEntrycreateCacheEntry(byte[] content) detectErrorMessage(String data) Tries do detect an error message from given string.returns cache entry keyprotected StringFor TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers)getUrl()method to get download URL for Jobprivate voidhandleError(CacheEntryAttributes attributes) private booleanprivate booleanprivate booleanisNotImage(Map<String, List<String>> headers, int statusCode) booleanChecks if object from cache has sufficient data to be returned.protected booleanisResponseLoadable(Map<String, List<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 StringremoveCdata(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 Details
-
MAXIMUM_EXPIRES
General maximum expires for tiles. Might be overridden by imagery settings -
MINIMUM_EXPIRES
General minimum expires for tiles. Might be overridden by imagery settings -
SERVICE_EXCEPTION_PATTERN
-
CDATA_PATTERN
-
JSON_PATTERN
-
tile
-
url
-
options
-
inProgress
private static final ConcurrentMap<String,Set<org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener>> inProgress
-
-
Constructor Details
-
TMSCachedTileLoaderJob
public TMSCachedTileLoaderJob(org.openstreetmap.gui.jmapviewer.interfaces.TileLoaderListener listener, org.openstreetmap.gui.jmapviewer.Tile tile, org.apache.commons.jcs3.access.behavior.ICacheAccess<String, BufferedImageCacheEntry> cache, TileJobOptions options, 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 Details
-
getCacheKey
Description copied from interface:ICachedLoaderJobreturns cache entry key- Specified by:
getCacheKeyin interfaceICachedLoaderJob<String>- Returns:
- cache key for tile
-
getUrl
Description copied from interface:ICachedLoaderJobmethod to get download URL for Job- Specified by:
getUrlin interfaceICachedLoaderJob<String>- Returns:
- URL that should be fetched
- Throws:
IOException- when could not determine the URL of the tile
-
isObjectLoadable
Description copied from class:JCSCachedTileLoaderJobChecks if object from cache has sufficient data to be returned.- Overrides:
isObjectLoadablein classJCSCachedTileLoaderJob<String,BufferedImageCacheEntry> - Returns:
trueif object from cache has sufficient data to be returned
-
isResponseLoadable
protected boolean isResponseLoadable(Map<String, List<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<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
-
cacheAsEmpty
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<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
- 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
-
getServerKey
For TMS use BaseURL as settings discovery, so for different paths, we will have different settings (useful for developer servers)- Overrides:
getServerKeyin classJCSCachedTileLoaderJob<String,BufferedImageCacheEntry> - Returns:
- base URL of TMS or server url as defined in super class
-
createCacheEntry
- Specified by:
createCacheEntryin classJCSCachedTileLoaderJob<String,BufferedImageCacheEntry>
-
submit
- Specified by:
submitin interfaceorg.openstreetmap.gui.jmapviewer.interfaces.TileJob
-
parseHeaders
- Overrides:
parseHeadersin classJCSCachedTileLoaderJob<String,BufferedImageCacheEntry>
-
handleNoTileAtZoom
-
isNoTileAtZoom
-
tryLoadTileImage
- Throws:
IOException
-
detectErrorMessage
Description copied from class:JCSCachedTileLoaderJobTries do detect an error message from given string.- Overrides:
detectErrorMessagein classJCSCachedTileLoaderJob<String,BufferedImageCacheEntry> - Parameters:
data- string to analyze- Returns:
- error message if detected, or null
-
removeCdata
-