Skip to content

Commit

Permalink
MapillaryImageUtils: Handle cancellation or other errors better
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed Dec 29, 2022
1 parent 17144c0 commit 7abb96e
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.utils;

import java.io.IOException;
import java.time.Instant;
import java.util.Locale;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.regex.Matcher;
Expand All @@ -13,6 +15,7 @@

import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
import org.openstreetmap.josm.data.cache.CacheEntry;
import org.openstreetmap.josm.data.cache.ICachedLoaderListener;
import org.openstreetmap.josm.data.osm.INode;
import org.openstreetmap.josm.data.osm.IPrimitive;
import org.openstreetmap.josm.data.osm.IWay;
Expand Down Expand Up @@ -136,8 +139,17 @@ public static CompletableFuture<BufferedImageCacheEntry> getImage(@Nonnull INode
}
if (MapillaryImageUtils.isDownloadable(image)) {
CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();
CacheUtils.submit(image, type,
(entry, attributes, result) -> cacheImageFuture(image, completableFuture, entry));
CacheUtils.submit(image, type, (entry, attributes, result) -> {
if (result == ICachedLoaderListener.LoadResult.SUCCESS) {
cacheImageFuture(image, completableFuture, entry);
} else if (result == ICachedLoaderListener.LoadResult.CANCELED) {
completableFuture.completeExceptionally(new CancellationException(
"Mapillary Image download was cancelled: " + MapillaryImageUtils.getKey(image)));
} else {
completableFuture.completeExceptionally(new IOException(
"Mapillary Image could not be downloaded: " + MapillaryImageUtils.getKey(image)));
}
});
return completableFuture;
} else if (getKey(image) > 0) {
CompletableFuture<BufferedImageCacheEntry> completableFuture = new CompletableFuture<>();
Expand Down

0 comments on commit 7abb96e

Please sign in to comment.