/** * Request a tile. * * @param index * The index of the tile being requested. * * @param callback * A callback to call when the request is fulfilled. */ public void requestTile (TileIndex index, CacheRequestCallback<T> callback) { _cache.get(index).requestTile(callback); }
/** * Take a list of tiles to request, and return the subset that are new * requests - i.e., ones not already in the cache. * * Each new request will be placed in the cache. * * @param requests * The list of tiles needed * @return A sublist of just those tiles not already requested */ public List<TileIndex> getNewRequests (Iterable<TileIndex> requests) { List<TileIndex> needed = new ArrayList<>(); synchronized (_cache) { for (TileIndex index : requests) { if (!_cache.containsKey(index)) { // Create the tile request, and listen for its fulfilment TileCacheEntry<T> entry = new TileCacheEntry<T>(index); entry.requestTile(_entryListener); // Add to cache _cache.put(index, entry); // Add to list of keys in request order _orderedKeys.add(index); needed.add(index); } } } return needed; }
public TileCache (long maxAge, int maxSize) { _maxTileAge = maxAge; _cache = new SynchronizedLRUCache<>(maxSize, new TileCacheRemovalPolicy()); _haveData= new TreeSet<>(new EntryAgeComparator()); _orderedKeys = new LinkedList<>(); _entryListener = new CacheEntryListener(); _globalCallbacks = new ArrayList<>(); }
public void provideEmptyTile (TileIndex index) { TileCacheEntry<T> entry = _cache.get(index); if (null != entry) entry.setTile(null); }
public void provideTile (TileData<T> tile) { if (null == tile) return; TileIndex index = tile.getDefinition(); TileCacheEntry<T> entry = _cache.get(index); if (null != entry) entry.setTile(tile); }