Changeset 14270 in josm for trunk


Ignore:
Timestamp:
2018-09-22T12:38:49+02:00 (6 years ago)
Author:
wiktorn
Message:

Treat SocketTimeoutException as transient error.

Extend CacheEntryAttributes and allow storage of exception class name. Use this
information to treat SocketTimeoutException in TMS downloads as transient.

See: #16743

Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/cache/CacheEntryAttributes.java

    r13439 r14270  
    77import java.util.Map;
    88import java.util.Map.Entry;
     9import java.util.Optional;
    910import java.util.Set;
    1011import java.util.concurrent.ConcurrentHashMap;
     
    2930    private static final String HTTP_RESPONSE_CODE = "httpResponseCode";
    3031    private static final String ERROR_MESSAGE = "errorMessage";
     32    private static final String EXCEPTION = "exception";
    3133    // this contains all of the above
    3234    private static final Set<String> RESERVED_KEYS = new HashSet<>(Arrays.asList(
     
    3638        EXPIRATION_TIME,
    3739        HTTP_RESPONSE_CODE,
    38         ERROR_MESSAGE
     40        ERROR_MESSAGE,
     41        EXCEPTION
    3942    ));
    4043
     
    195198        attrs.put(ERROR_MESSAGE, message);
    196199    }
     200
     201    /**
     202     * @param e exception that caused error
     203     *
     204     */
     205    public void setException(Exception e) {
     206        attrs.put(EXCEPTION, e.getClass().getCanonicalName());
     207    }
     208
     209    /**
     210     * @return Optional exception that was thrown when fetching resource
     211     *
     212     */
     213    public Optional<Class<? extends Exception>> getException() {
     214        String className = attrs.get(EXCEPTION);
     215        if (className == null) {
     216            return Optional.empty();
     217        }
     218        try {
     219            Class<?> klass = Class.forName(className);
     220            if (Exception.class.isAssignableFrom(klass)) {
     221                return Optional.of(klass.asSubclass(Exception.class));
     222            }
     223        } catch (ClassNotFoundException | ClassCastException ex) {
     224            // NOOP
     225        }
     226        return Optional.empty();
     227    }
    197228}
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java

    r13825 r14270  
    392392            attributes.setResponseCode(404);
    393393            attributes.setError(e);
     394            attributes.setException(e);
    394395            boolean doCache = isResponseLoadable(null, 404, null) || cacheAsEmpty();
    395396            if (doCache) {
     
    404405            } else {
    405406                attributes.setError(e);
     407                attributes.setException(e);
    406408                attributes.setResponseCode(599); // set dummy error code, greater than 500 so it will be not cached
    407409                return false;
     
    410412        } catch (InterruptedException e) {
    411413            attributes.setError(e);
     414            attributes.setException(e);
    412415            Logging.logWithStackTrace(Logging.LEVEL_WARN, e, "JCS - Exception during download {0}", getUrlNoException());
    413416            Thread.currentThread().interrupt();
  • trunk/src/org/openstreetmap/josm/data/imagery/TMSCachedTileLoaderJob.java

    r14268 r14270  
    66import java.io.ByteArrayInputStream;
    77import java.io.IOException;
     8import java.net.SocketTimeoutException;
    89import java.net.URL;
    910import java.nio.charset.StandardCharsets;
     
    226227                tile.setLoaded(false); // treat 500 errors as temporary and try to load it again
    227228            }
     229            // treat SocketTimeoutException as transient error
     230            attributes.getException()
     231            .filter(x -> x.isAssignableFrom(SocketTimeoutException.class))
     232            .ifPresent(x -> tile.setLoaded(false));
    228233        } else {
    229234            tile.setError(tr("Problem loading tile"));
Note: See TracChangeset for help on using the changeset viewer.