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 *
009 * @author Wiktor Niesiobędzki
010 *
011 * @param <K> cache key type
012 */
013public interface ICachedLoaderJob<K> extends Runnable {
014    /**
015     * returns cache entry key
016     *
017     * @return cache key for tile
018     */
019    K getCacheKey();
020
021    /**
022     * method to get download URL for Job
023     * @return URL that should be fetched
024     * @throws IOException when could not determine the URL of the tile
025     *
026     */
027    URL getUrl() throws IOException;
028
029    /**
030     * fetches object from cache, or returns null when object is not found
031     *
032     * @return filled tile with data or null when no cache entry found
033     */
034    CacheEntry get();
035
036    /**
037     * Submit job for background fetch, and listener will be fed with value object
038     *
039     * @param listener cache loader listener
040     * @param force true if the load should skip all the caches (local &amp; remote)
041     * @throws IOException on failure from getUrl() call
042     */
043    void submit(ICachedLoaderListener listener, boolean force) throws IOException;
044}