Revision 1000 org.gvsig.raster.cache/trunk/org.gvsig.raster.cache/org.gvsig.raster.cache.lib.impl/src/main/java/org/gvsig/raster/cache/tile/impl/layer/TiledLayerImpl.java
TiledLayerImpl.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.cache.tile.impl.layer; |
23 | 23 |
|
24 |
import java.awt.event.ActionEvent; |
|
25 |
import java.awt.event.ActionListener; |
|
26 | 24 |
import java.io.File; |
27 | 25 |
import java.security.MessageDigest; |
28 | 26 |
import java.security.NoSuchAlgorithmException; |
29 | 27 |
import java.util.ArrayList; |
30 | 28 |
|
31 |
import javax.swing.Timer; |
|
32 |
|
|
33 | 29 |
import org.gvsig.raster.cache.tile.Tile; |
34 | 30 |
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy; |
35 | 31 |
import org.gvsig.raster.cache.tile.exception.TileGettingException; |
... | ... | |
47 | 43 |
* |
48 | 44 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
49 | 45 |
*/ |
50 |
public class TiledLayerImpl implements TiledLayer, ActionListener { |
|
51 |
private static int msTime = 20000; |
|
46 |
public class TiledLayerImpl implements TiledLayer { |
|
52 | 47 |
private TileServer provider = null; |
53 | 48 |
private TileCacheImpl tileCache = null; |
54 | 49 |
private String basePath = null; |
... | ... | |
57 | 52 |
//private LRUTileCache memoryCache = null; |
58 | 53 |
private ThreadPoolImpl pool = null; |
59 | 54 |
private ITileFileSystemStrategy strategy = null; |
60 |
private Timer timer = null; |
|
61 |
private TileListener listener = null; |
|
62 |
//private boolean cancel = false; |
|
55 |
private TimerOneTile timerOneTile = null; |
|
56 |
private TimerTilePool timerTilePool = null; |
|
63 | 57 |
|
64 | 58 |
public TiledLayerImpl(TileCacheImpl tileCache, |
65 | 59 |
TileServer provider, |
... | ... | |
72 | 66 |
this.strategy = strategy; |
73 | 67 |
} |
74 | 68 |
|
69 |
/** |
|
70 |
* Gets the timer of one tile |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
private TimerOneTile getTimerOneTile() { |
|
74 |
if(timerOneTile == null) |
|
75 |
timerOneTile = new TimerOneTile(); |
|
76 |
return timerOneTile; |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* Gets the timer of a list of tiles |
|
81 |
* @return |
|
82 |
*/ |
|
83 |
private TimerTilePool getTimerTilePool() { |
|
84 |
if(timerTilePool == null) |
|
85 |
timerTilePool = new TimerTilePool(getThreadPool()); |
|
86 |
return timerTilePool; |
|
87 |
} |
|
88 |
/** |
|
89 |
* Gets the pool of threads |
|
90 |
* @return |
|
91 |
*/ |
|
75 | 92 |
public ThreadPoolImpl getThreadPool() { |
76 | 93 |
if(pool == null) |
77 | 94 |
pool = new ThreadPoolImpl(false); |
... | ... | |
107 | 124 |
} |
108 | 125 |
|
109 | 126 |
|
110 |
//Lo obtiene y lo carga desde disco |
|
127 |
getTimerOneTile().setTile(tile); |
|
128 |
getTimerOneTile().start(); |
|
129 |
//Lo descarga de la fuente y lo carga desde disco |
|
111 | 130 |
provider.getDownloader().downloadTile(tile); |
131 |
getTimerOneTile().stop(); |
|
132 |
|
|
112 | 133 |
tileCache.updateSize(tile.getFile().length()); |
113 | 134 |
tileCache.saveSize(); |
114 | 135 |
if(!tile.isCorrupt()) |
... | ... | |
122 | 143 |
* @see org.gvsig.raster.cache.tile.layer.TiledLayer#getTiles(java.util.ArrayList, org.gvsig.raster.cache.tile.provider.TileListener) |
123 | 144 |
*/ |
124 | 145 |
public void getTiles(ArrayList<Tile> tiles, TileListener listener) throws TileGettingException { |
125 |
this.listener = listener; |
|
126 | 146 |
//If a tile is in memory or in disk then this will be returned |
127 | 147 |
//else this will be gotten from the provider |
128 | 148 |
|
... | ... | |
159 | 179 |
nTilesToDownload ++; |
160 | 180 |
} |
161 | 181 |
|
162 |
getTimer().start(); |
|
182 |
getTimerTilePool().setListener(listener); |
|
183 |
getTimerTilePool().start(); |
|
163 | 184 |
for (int i = 0; i < nTilesToDownload; i++) { |
164 |
getTimer().restart(); |
|
185 |
getTimerTilePool().restart();
|
|
165 | 186 |
Tile tile = (Tile)getThreadPool().getTilePipe().getAtomicTask(); |
166 | 187 |
|
167 | 188 |
if(tile == null) { |
... | ... | |
173 | 194 |
tileCache.updateSize(tile.getFile().length()); |
174 | 195 |
listener.tileReady(tile); |
175 | 196 |
} |
176 |
getTimer().stop(); |
|
197 |
getTimerTilePool().stop();
|
|
177 | 198 |
tileCache.saveSize(); |
178 | 199 |
} |
179 |
|
|
180 |
public void actionPerformed(ActionEvent e) { |
|
181 |
getThreadPool().cancelPool(listener); |
|
182 |
getThreadPool().getTilePipe().setAtomicTask(null); |
|
183 |
} |
|
184 |
|
|
185 |
private Timer getTimer() { |
|
186 |
if(timer == null) |
|
187 |
timer = new Timer(msTime, this); |
|
188 |
return timer; |
|
189 |
} |
|
190 | 200 |
|
191 | 201 |
/* |
192 | 202 |
* (non-Javadoc) |
Also available in: Unified diff