001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.cache; 003 004import java.io.IOException; 005import java.net.URL; 006 007/** 008 * Interface for a job to load a single object (typically an imagery tile). 009 * It is either retrieved from cache or downloaded from the given URL ({@link #getUrl()}). 010 * 011 * @author Wiktor Niesiobędzki 012 * 013 * @param <K> cache key type 014 */ 015public interface ICachedLoaderJob<K> extends Runnable { 016 /** 017 * returns cache entry key 018 * 019 * @return cache key for tile 020 */ 021 K getCacheKey(); 022 023 /** 024 * method to get download URL for Job 025 * @return URL that should be fetched 026 * @throws IOException when could not determine the URL of the tile 027 * 028 */ 029 URL getUrl() throws IOException; 030 031 /** 032 * fetches object from cache, or returns null when object is not found 033 * 034 * @return filled tile with data or null when no cache entry found 035 */ 036 CacheEntry get(); 037 038 /** 039 * Submit job for background fetch, and listener will be fed with value object 040 * 041 * @param listener cache loader listener 042 * @param force true if the load should skip all the caches (local & remote) 043 * @throws IOException on failure from getUrl() call 044 */ 045 void submit(ICachedLoaderListener listener, boolean force) throws IOException; 046}