- Timestamp:
- 2015-04-07T22:17:42+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/ICachedLoaderListener.java
r8168 r8176 3 3 4 4 public interface ICachedLoaderListener { 5 5 6 /** 6 * Will be called when K object was successfully downloaded 7 * 7 * Result of download 8 * 9 */ 10 enum LoadResult { 11 SUCCESS, 12 FAILURE, 13 REJECTED 14 } 15 /** 16 * Will be called when K object processed. The result might be: 17 * LoadResult.SUCCESS when object was fetched 18 * LoadResult.FAILURE when there was a failure during download 19 * LoadResult.REJECTED when job was rejected because of full queue 20 * 8 21 * @param data 9 * @param success22 * @param result 10 23 */ 11 public void loadingFinished(CacheEntry data, boolean success);24 public void loadingFinished(CacheEntry data, LoadResult result); 12 25 13 26 } -
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r8174 r8176 27 27 import org.apache.commons.jcs.engine.behavior.ICacheElement; 28 28 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 29 import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult; 29 30 import org.openstreetmap.josm.data.preferences.IntegerProperty; 30 31 … … 152 153 // we got something in cache, and it's valid, so lets return it 153 154 log.log(Level.FINE, "JCS - Returning object from cache: {0}", getCacheKey()); 154 finishLoading( true);155 finishLoading(LoadResult.SUCCESS); 155 156 return; 156 157 } … … 162 163 // queue was full, try again later 163 164 log.log(Level.FINE, "JCS - rejected job for: {0}", getCacheKey()); 164 finishLoading( false);165 finishLoading(LoadResult.REJECTED); 165 166 } 166 167 } … … 206 207 // try to load object from remote resource 207 208 if (loadObject()) { 208 finishLoading( true);209 finishLoading(LoadResult.SUCCESS); 209 210 } else { 210 211 // if loading failed - check if we can return stale entry 211 212 if (isObjectLoadable()) { 212 213 // try to get stale entry in cache 213 finishLoading( true);214 finishLoading(LoadResult.SUCCESS); 214 215 log.log(Level.FINE, "JCS - found stale object in cache: {0}", getUrl()); 215 216 } else { 216 217 // failed completely 217 finishLoading( false);218 finishLoading(LoadResult.FAILURE); 218 219 } 219 220 } … … 224 225 225 226 226 private void finishLoading( boolean success) {227 private void finishLoading(LoadResult result) { 227 228 Set<ICachedLoaderListener> listeners = null; 228 229 synchronized (inProgress) { … … 235 236 try { 236 237 for (ICachedLoaderListener l: listeners) { 237 l.loadingFinished(cacheData, success);238 l.loadingFinished(cacheData, result); 238 239 } 239 240 } catch (Exception e) { … … 241 242 log.log(Level.FINE, "Stacktrace", e); 242 243 for (ICachedLoaderListener l: listeners) { 243 l.loadingFinished(cacheData, false);244 l.loadingFinished(cacheData, LoadResult.FAILURE); 244 245 } 245 246 -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r8174 r8176 133 133 } 134 134 135 private boolean isNoTileAtZoom() { 136 return attributes != null && attributes.isNoTileAtZoom(); 137 } 138 135 139 @Override 136 140 protected boolean cacheAsEmpty() { 137 if (attributes != null && attributes.isNoTileAtZoom()) { 138 // do not remove file - keep the information, that there is no tile, for further requests 139 // the code above will check, if this information is still valid 141 return isNoTileAtZoom(); 142 } 143 144 private boolean handleNoTileAtZoom() { 145 if (isNoTileAtZoom()) { 140 146 log.log(Level.FINE, "JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile); 141 147 tile.setError("No tile at this zoom level"); … … 143 149 return true; 144 150 } 145 return false; // as there is no other cache to cache the Tile, also cache other empty requests151 return false; 146 152 } 147 153 … … 157 163 158 164 @Override 159 public void loadingFinished(CacheEntry object, boolean success) {165 public void loadingFinished(CacheEntry object, LoadResult result) { 160 166 try { 161 loadTile(object, success); 167 tile.finishLoading(); // whatever happened set that loading has finished 168 switch(result){ 169 case FAILURE: 170 tile.setError("Problem loading tile"); 171 case SUCCESS: 172 handleNoTileAtZoom(); 173 if (object != null) { 174 byte[] content = object.getContent(); 175 if (content != null && content.length > 0) { 176 tile.loadImage(new ByteArrayInputStream(content)); 177 } 178 } 179 case REJECTED: 180 // do not set anything here, leave waiting sign 181 } 162 182 if (listener != null) { 163 listener.tileLoadingFinished(tile, success);183 listener.tileLoadingFinished(tile, result.equals(LoadResult.SUCCESS)); 164 184 } 165 185 } catch (IOException e) { … … 181 201 if (isObjectLoadable()) { 182 202 try { 183 loadTile(data); 203 if (data != null && data.getImage() != null) { 204 tile.setImage(data.getImage()); 205 tile.finishLoading(); 206 } 207 if (isNoTileAtZoom()) { 208 handleNoTileAtZoom(); 209 tile.finishLoading(); 210 } 184 211 return tile; 185 212 } catch (IOException e) { … … 189 216 190 217 } else { 191 return null; 192 } 193 } 194 195 // loads tile when calling back from cache 196 private void loadTile(CacheEntry object, boolean success) throws IOException { 197 tile.finishLoading(); 198 if (object != null) { 199 byte[] content = object.getContent(); 200 if (content != null && content.length > 0) { 201 tile.loadImage(new ByteArrayInputStream(content)); 202 } 203 } 204 if (!success) { 205 tile.setError("Problem loading tile"); 206 } 207 } 208 209 // loads tile when geting stright from cache 210 private void loadTile(BufferedImageCacheEntry object) throws IOException { 211 tile.finishLoading(); 212 if (cacheAsEmpty() || object != null) { // if cache as empty object, do not try to load image 213 if (object.getImage() != null) { 214 tile.setImage(object.getImage()); 215 } 218 return tile; 216 219 } 217 220 }
Note:
See TracChangeset
for help on using the changeset viewer.