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> { 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 * implements the main algorithm for fetching 031 */ 032 void run(); 033 034 /** 035 * fetches object from cache, or returns null when object is not found 036 * 037 * @return filled tile with data or null when no cache entry found 038 */ 039 CacheEntry get(); 040 041 /** 042 * Submit job for background fetch, and listener will be fed with value object 043 * 044 * @param listener cache loader listener 045 * @param force true if the load should skip all the caches (local & remote) 046 * @throws IOException on failure from getUrl() call 047 */ 048 void submit(ICachedLoaderListener listener, boolean force) throws IOException; 049}