/**
* Load the tiles in the tilerange and then reset the vars
*/
private void doRequestAndResetVars( final TileSet tileset ) {
TileRangeOnDisk tileRangeOnDisk = new TileRangeOnDisk(tileset.getServer(), tileset,
tileRangeBounds, tileRangeTiles, requestTileWorkQueue, writeTileWorkQueue);
// set the listener on the tile range so we can wait until all tiles are
// done for the range before moving on.
tileRangeOnDisk.addListener(listener);
// remove any tiles that are already loaded from disk to avoid
// deadlock waiting for all tiles
Map<String, Tile> loadedTiles = new HashMap<String, Tile>();
Iterator<Entry<String, Tile>> iterator = tileRangeTiles.entrySet().iterator();
while( iterator.hasNext() ) {
Tile tile = iterator.next().getValue();
if (tile.getBufferedImage() != null) {
loadedTiles.put(tile.getId(), tile);
}
}
Iterator<Entry<String, Tile>> iterator2 = loadedTiles.entrySet().iterator();
while( iterator2.hasNext() ) {
Tile tile = iterator2.next().getValue();
tileRangeTiles.remove(tile.getId());
}
// now load any missing tiles and send off thread requests to fetch them
tileRangeOnDisk.loadTiles(new NullProgressMonitor());
// block and wait until all unloaded tiles are loaded before moving forward
while( !tileRangeTiles.isEmpty() ) {
Tile tile = null;
try {
tile = (Tile) tilesCompleted_queue.take(); // blocks until a tile is done
} catch (InterruptedException ex) {
// log error?
// ex.printStackTrace();
} finally {
// remove the tile
if (tile != null) {
tileRangeTiles.remove(tile.getId());
}
}
}
// all tiles in chunk are now complete, so update monitor
this.monitor.worked((int) percentPerTile * tileRangeOnDisk.getTileCount());
// reset vars
requestCount = 0;
tileRangeBounds = new Envelope();
tileRangeTiles.clear();