Changeset 12765 in josm
- Timestamp:
- 2017-09-07T00:37:06+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r12620 r12765 27 27 import org.apache.commons.jcs.engine.control.CompositeCacheManager; 28 28 import org.apache.commons.jcs.utils.serialization.StandardSerializer; 29 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;30 29 import org.openstreetmap.josm.Main; 31 30 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 42 41 */ 43 42 public final class JCSCacheManager { 44 private static final Logger LOG = FeatureAdapter.getLogger(JCSCacheManager.class.getCanonicalName());45 46 43 private static volatile CompositeCacheManager cacheManager; 47 44 private static long maxObjectTTL = -1; … … 71 68 File cacheDirLockPath = new File(cacheDir, ".lock"); 72 69 if (!cacheDirLockPath.exists() && !cacheDirLockPath.createNewFile()) { 73 L OG.log(Level.WARNING,"Cannot create cache dir lock file");70 Logging.warn("Cannot create cache dir lock file"); 74 71 } 75 72 cacheDirLock = new FileOutputStream(cacheDirLockPath).getChannel().tryLock(); 76 73 77 74 if (cacheDirLock == null) 78 L OG.log(Level.WARNING,"Cannot lock cache directory. Will not use disk cache");75 Logging.warn("Cannot lock cache directory. Will not use disk cache"); 79 76 80 77 // raising logging level gives ~500x performance gain … … 230 227 File path = new File(cachePath); 231 228 if (!path.exists() && !path.mkdirs()) { 232 L OG.log(Level.WARNING,"Failed to create cache path: {0}", cachePath);229 Logging.warn("Failed to create cache path: {0}", cachePath); 233 230 } else { 234 231 ret.setDiskPath(cachePath); -
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r12620 r12765 16 16 import java.util.concurrent.ThreadPoolExecutor; 17 17 import java.util.concurrent.TimeUnit; 18 import java.util.logging.Level;19 import java.util.logging.Logger;20 18 21 19 import org.apache.commons.jcs.access.behavior.ICacheAccess; 22 20 import org.apache.commons.jcs.engine.behavior.ICacheElement; 23 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;24 21 import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult; 25 22 import org.openstreetmap.josm.data.preferences.IntegerProperty; … … 46 43 */ 47 44 public abstract class JCSCachedTileLoaderJob<K, V extends CacheEntry> implements ICachedLoaderJob<K> { 48 private static final Logger LOG = FeatureAdapter.getLogger(JCSCachedTileLoaderJob.class.getCanonicalName());49 45 protected static final long DEFAULT_EXPIRE_TIME = TimeUnit.DAYS.toMillis(7); 50 46 // Limit for the max-age value send by the server. … … 159 155 } 160 156 if (deduplicationKey == null) { 161 L OG.log(Level.WARNING,"No url returned for: {0}, skipping", getCacheKey());157 Logging.warn("No url returned for: {0}, skipping", getCacheKey()); 162 158 throw new IllegalArgumentException("No url returned"); 163 159 } … … 174 170 if (first || force) { 175 171 // submit all jobs to separate thread, so calling thread is not blocked with IO when loading from disk 176 L OG.log(Level.FINE,"JCS - Submitting job for execution for url: {0}", getUrlNoException());172 Logging.debug("JCS - Submitting job for execution for url: {0}", getUrlNoException()); 177 173 downloadJobExecutor.execute(this); 178 174 } … … 226 222 final String oldName = currentThread.getName(); 227 223 currentThread.setName("JCS Downloading: " + getUrlNoException()); 228 L OG.log(Level.FINE,"JCS - starting fetch of url: {0} ", getUrlNoException());224 Logging.debug("JCS - starting fetch of url: {0} ", getUrlNoException()); 229 225 ensureCacheElement(); 230 226 try { … … 232 228 if (!force && cacheElement != null && isCacheElementValid() && isObjectLoadable()) { 233 229 // we got something in cache, and it's valid, so lets return it 234 L OG.log(Level.FINE,"JCS - Returning object from cache: {0}", getCacheKey());230 Logging.debug("JCS - Returning object from cache: {0}", getCacheKey()); 235 231 finishLoading(LoadResult.SUCCESS); 236 232 return; … … 245 241 // try to get stale entry in cache 246 242 finishLoading(LoadResult.SUCCESS); 247 L OG.log(Level.FINE,"JCS - found stale object in cache: {0}", getUrlNoException());243 Logging.debug("JCS - found stale object in cache: {0}", getUrlNoException()); 248 244 } else { 249 245 // failed completely … … 268 264 } 269 265 if (listeners == null) { 270 L OG.log(Level.WARNING,"Listener not found for URL: {0}. Listener not notified!", getUrlNoException());266 Logging.warn("Listener not found for URL: {0}. Listener not notified!", getUrlNoException()); 271 267 return; 272 268 } … … 285 281 expires = Math.min(expires, attributes.getCreateTime() + EXPIRE_TIME_SERVER_LIMIT); 286 282 if (now > expires) { 287 L OG.log(Level.FINE,"JCS - Object {0} has expired -> valid to {1}, now is: {2}",283 Logging.debug("JCS - Object {0} has expired -> valid to {1}, now is: {2}", 288 284 new Object[]{getUrlNoException(), Long.toString(expires), Long.toString(now)}); 289 285 return false; … … 292 288 now - attributes.getLastModification() > DEFAULT_EXPIRE_TIME) { 293 289 // check by file modification date 294 L OG.log(Level.FINE,"JCS - Object has expired, maximum file age reached {0}", getUrlNoException());290 Logging.debug("JCS - Object has expired, maximum file age reached {0}", getUrlNoException()); 295 291 return false; 296 292 } else if (now - attributes.getCreateTime() > DEFAULT_EXPIRE_TIME) { 297 L OG.log(Level.FINE,"JCS - Object has expired, maximum time since object creation reached {0}", getUrlNoException());293 Logging.debug("JCS - Object has expired, maximum time since object creation reached {0}", getUrlNoException()); 298 294 return false; 299 295 } … … 314 310 Boolean.TRUE.equals(useHead.get(getServerKey())) && 315 311 isCacheValidUsingHead()) { 316 L OG.log(Level.FINE,"JCS - cache entry verified using HEAD request: {0}", getUrl());312 Logging.debug("JCS - cache entry verified using HEAD request: {0}", getUrl()); 317 313 return true; 318 314 } 319 315 320 L OG.log(Level.FINE,"JCS - starting HttpClient GET request for URL: {0}", getUrl());316 Logging.debug("JCS - starting HttpClient GET request for URL: {0}", getUrl()); 321 317 final HttpClient request = getRequest("GET", true); 322 318 … … 334 330 // If isModifiedSince or If-None-Match has been set 335 331 // and the server answers with a HTTP 304 = "Not Modified" 336 L OG.log(Level.FINE,"JCS - If-Modified-Since/ETag test: local version is up to date: {0}", getUrl());332 Logging.debug("JCS - If-Modified-Since/ETag test: local version is up to date: {0}", getUrl()); 337 333 return true; 338 334 } else if (isObjectLoadable() // we have an object in cache, but we haven't received 304 response code … … 344 340 // for further requests - use HEAD 345 341 String serverKey = getServerKey(); 346 L OG.log(Level.INFO,"JCS - Host: {0} found not to return 304 codes for If-Modified-Since or If-None-Match headers",342 Logging.info("JCS - Host: {0} found not to return 304 codes for If-Modified-Since or If-None-Match headers", 347 343 serverKey); 348 344 useHead.put(serverKey, Boolean.TRUE); … … 370 366 cacheData = createCacheEntry(raw); 371 367 cache.put(getCacheKey(), cacheData, attributes); 372 L OG.log(Level.FINE,"JCS - downloaded key: {0}, length: {1}, url: {2}",368 Logging.debug("JCS - downloaded key: {0}, length: {1}, url: {2}", 373 369 new Object[] {getCacheKey(), raw.length, getUrl()}); 374 370 return true; … … 376 372 cacheData = createCacheEntry(new byte[]{}); 377 373 cache.put(getCacheKey(), cacheData, attributes); 378 L OG.log(Level.FINE,"JCS - Caching empty object {0}", getUrl());374 Logging.debug("JCS - Caching empty object {0}", getUrl()); 379 375 return true; 380 376 } else { 381 L OG.log(Level.FINE,"JCS - failure during load - reponse is not loadable nor cached as empty");377 Logging.debug("JCS - failure during load - reponse is not loadable nor cached as empty"); 382 378 return false; 383 379 } 384 380 } 385 381 } catch (FileNotFoundException e) { 386 L OG.log(Level.FINE,"JCS - Caching empty object as server returned 404 for: {0}", getUrlNoException());382 Logging.debug("JCS - Caching empty object as server returned 404 for: {0}", getUrlNoException()); 387 383 attributes.setResponseCode(404); 388 384 attributes.setError(e); … … 394 390 return doCache; 395 391 } catch (IOException e) { 396 L OG.log(Level.FINE,"JCS - IOExecption during communication with server for: {0}", getUrlNoException());392 Logging.debug("JCS - IOExecption during communication with server for: {0}", getUrlNoException()); 397 393 if (isObjectLoadable()) { 398 394 return true; … … 405 401 } catch (InterruptedException e) { 406 402 attributes.setError(e); 407 LOG.log(Level.WARNING, "JCS - Exception during download {0}", getUrlNoException()); 408 Logging.warn(e); 403 Logging.logWithStackTrace(Logging.LEVEL_WARN, e, "JCS - Exception during download {0}", getUrlNoException()); 409 404 Thread.currentThread().interrupt(); 410 405 } 411 L OG.log(Level.WARNING,"JCS - Silent failure during download: {0}", getUrlNoException());406 Logging.warn("JCS - Silent failure during download: {0}", getUrlNoException()); 412 407 return false; 413 408 } -
trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java
r12620 r12765 17 17 import java.util.concurrent.ThreadPoolExecutor; 18 18 import java.util.concurrent.TimeUnit; 19 import java.util.logging.Level;20 import java.util.logging.Logger;21 19 22 20 import org.apache.commons.jcs.access.behavior.ICacheAccess; 23 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;24 21 import org.openstreetmap.gui.jmapviewer.Tile; 25 22 import org.openstreetmap.gui.jmapviewer.interfaces.TileJob; … … 43 40 */ 44 41 public class TMSCachedTileLoaderJob extends JCSCachedTileLoaderJob<String, BufferedImageCacheEntry> implements TileJob, ICachedLoaderListener { 45 private static final Logger LOG = FeatureAdapter.getLogger(TMSCachedTileLoaderJob.class.getCanonicalName());46 42 private static final LongProperty MAXIMUM_EXPIRES = new LongProperty("imagery.generic.maximum_expires", TimeUnit.DAYS.toMillis(30)); 47 43 private static final LongProperty MINIMUM_EXPIRES = new LongProperty("imagery.generic.minimum_expires", TimeUnit.HOURS.toMillis(1)); … … 123 119 return content.length > 0 || cacheData.getImage() != null || isNoTileAtZoom(); 124 120 } catch (IOException e) { 125 LOG.log(Level.WARNING, "JCS TMS - error loading from cache for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()}); 126 Logging.warn(e); 121 Logging.logWithStackTrace(Logging.LEVEL_WARN, e, "JCS TMS - error loading from cache for tile {0}: {1}", 122 new Object[] {tile.getKey(), e.getMessage()} 123 ); 127 124 } 128 125 } … … 208 205 } 209 206 } catch (IOException e) { 210 L OG.log(Level.WARNING,"JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()});207 Logging.warn("JCS TMS - error loading object for tile {0}: {1}", new Object[] {tile.getKey(), e.getMessage()}); 211 208 tile.setError(e); 212 209 tile.setLoaded(false); … … 259 256 private boolean handleNoTileAtZoom() { 260 257 if (isNoTileAtZoom()) { 261 L OG.log(Level.FINE,"JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile);258 Logging.debug("JCS TMS - Tile valid, but no file, as no tiles at this level {0}", tile); 262 259 tile.setError("No tile at this zoom level"); 263 260 tile.putValue("tile-info", "no-tile"); … … 269 266 private boolean isNoTileAtZoom() { 270 267 if (attributes == null) { 271 L OG.warning("Cache attributes are null");268 Logging.warn("Cache attributes are null"); 272 269 } 273 270 return attributes != null && attributes.isNoTileAtZoom(); -
trunk/src/org/openstreetmap/josm/tools/Logging.java
r12621 r12765 271 271 } 272 272 273 /** 274 * Logs a throwable that happened. Adds the stack trace to the log. 275 * @param level The level. 276 * @param t The throwable that should be logged. 277 * @param pattern The formatted message to print. 278 * @param args The objects to insert into format string 279 * @see #logWithStackTrace(Level, Throwable) 280 */ 281 public static void logWithStackTrace(Level level, Throwable t, String pattern, Object... args) { 282 logPrivate(level, () -> getErrorLogWithStack(MessageFormat.format(pattern, args), t)); 283 } 284 285 273 286 private static void logPrivate(Level level, String pattern, Object... args) { 274 287 logPrivate(level, () -> MessageFormat.format(pattern, args));
Note:
See TracChangeset
for help on using the changeset viewer.