gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / main / java / org / gvsig / raster / cache / buffer / impl / stripecache / vertical / CacheVertImpl.java @ 992
History | View | Annotate | Download (20.1 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.vertical; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.raster.cache.buffer.Band; |
6 |
import org.gvsig.raster.cache.buffer.exception.WrongParameterException; |
7 |
import org.gvsig.raster.cache.buffer.impl.stripecache.CacheStruct; |
8 |
import org.gvsig.raster.cache.buffer.impl.stripecache.HDDPageList; |
9 |
import org.gvsig.raster.cache.buffer.impl.stripecache.PageBuffer; |
10 |
import org.gvsig.raster.cache.buffer.impl.stripecache.PageCacheList; |
11 |
import org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.CacheHorzImpl; |
12 |
|
13 |
/**
|
14 |
* <P>
|
15 |
* Esta clase representa a la cache raster. Consta de una ser?e de p?ginas (CachePages)
|
16 |
* que son buffers con los bloques de datos cacheados en un instante dado. Esta cache tiene
|
17 |
* una estructura en forma de array donde cada elemento es una p?gina de cach?. Las p?ginas
|
18 |
* se agrupan en bloques de N p?ginas denominados grupos. La variable nelemsGroup contiene
|
19 |
* el n?mero de p?ginas de cada grupo.
|
20 |
* </P>
|
21 |
* <P>
|
22 |
* La politica de reemplazo es que una p?gina siempre va a un conjunto determinado por el calculo
|
23 |
* cto = pag % nelemsGroup. Si hay hueco vac?o en el grupo se a?adir? en el siguiente hueco pero
|
24 |
* si hay que reeplazar se reeplazar? la p?gina que m?s tiempo haga su ?ltimo acceso.
|
25 |
* </P>
|
26 |
* <P>
|
27 |
* Esta cach? lleva el control de que p?ginas est?n cargadas a trav?s de un array de de booleanos
|
28 |
* donde cada elemento representa a una p?gina de datos del raster. Si el elemento en la posici?n
|
29 |
* N de dicho array es true significa que la p?gina est? cacheada. Si es false no lo estar?.
|
30 |
* </P>
|
31 |
* <P>
|
32 |
* La p?gina de datos actualmente accedida debe estar cacheada por lo que est? clase debe llevar
|
33 |
* el control de que p?gina se est? accediendo o a sido accedida por ?ltima vez. La variable que
|
34 |
* nos dice que p?gina est? siendo accedida es loadPage y pageBuffer ser? la variable que apunta
|
35 |
* al buffer de esta p?gina. Cuando se cambia de p?gina en un acceso estas dos variables deben
|
36 |
* cambiar a sus nuevos valores.
|
37 |
* </P>
|
38 |
* <P>
|
39 |
* Otro par?metro que controla esta clase es que p?gina de cada grupo ha sido accedido con mayor
|
40 |
* frecuencia. Esto es ?til porque siempre se reemplaza la p?gina de un grupo que haga m?s tiempo
|
41 |
* que haya sido accedida bajo la premisa de que "las p?ginas con accesos recientes tienen mayor
|
42 |
* probabilidad de volver a ser usadas". Esto es controlado por la variable lastAccess que es
|
43 |
* usada para implementar el algoritmo LRU. Cada vez que una p?gina de un grupo es accedida su
|
44 |
* contador de lastAccess se pone a 0. El resto de contadores de las p?ginas del grupo se incrementa
|
45 |
* en uno. Siempre se sustituye la p?gina del grupo con valor m?s grande en el contador.
|
46 |
* </P>
|
47 |
*
|
48 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
49 |
*
|
50 |
*/
|
51 |
public class CacheVertImpl extends CacheHorzImpl { |
52 |
|
53 |
|
54 |
/**
|
55 |
* Inicializamos la variables. Para ello creamos el objeto Cache que contendr? todos los
|
56 |
* par?metros necesarios para crear el array que controla los accesos m?s recientes y el
|
57 |
* array que dice si una p?gina est? en memoria o no.
|
58 |
* @param nBands N?mero de bandas
|
59 |
* @param dataType Tipo de dato de la p?gina
|
60 |
* @param dataSourceWidth ancho de la fuente de datos
|
61 |
*/
|
62 |
public CacheVertImpl(int nBands, int dataType, int dataSourceWidth, int dataSourceHeight) { |
63 |
super(nBands, dataType, dataSourceWidth, dataSourceHeight);
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* Contructor
|
68 |
* @param cacheStruct
|
69 |
*/
|
70 |
public CacheVertImpl(CacheStruct cacheStruct) {
|
71 |
super(cacheStruct);
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Initialize arrays and data structures
|
76 |
* @param nBands
|
77 |
* @param dataType
|
78 |
* @param dataSourceWidth
|
79 |
* @param dataSourceHeight
|
80 |
*/
|
81 |
protected void init(int nBands, int dataType, int dataSourceWidth, int dataSourceHeight) { |
82 |
//Creamos la estructura de la cach?
|
83 |
//Se cambian el ancho y el alto en la cach? vertical
|
84 |
cacheStruct = new CacheStructVertImpl(nBands, dataType, dataSourceWidth, dataSourceHeight);
|
85 |
|
86 |
//Inicializamos la antig?edad de acceso
|
87 |
lastAccess = new int[cacheStruct.getNGroups()][cacheStruct.getPagsPerGroup()]; |
88 |
|
89 |
//Creamos el buffer de la cach?
|
90 |
pageNumberInCache = new int[cacheStruct.getNPags()]; |
91 |
modified = new boolean[cacheStruct.getNPags()]; |
92 |
cacheada = new boolean[cacheStruct.getNTotalPags()]; |
93 |
|
94 |
initStructs(); |
95 |
initPointers(); |
96 |
|
97 |
createPages(getNBands()); |
98 |
} |
99 |
|
100 |
|
101 |
/**
|
102 |
* Create new and empty pages with the structure information of
|
103 |
* this cache
|
104 |
*/
|
105 |
public void createPages(int bands) { |
106 |
hddPageList = new HDDPageList(cacheStruct.getNTotalPags(), bands);
|
107 |
pageCacheList = new PageCacheList(cacheStruct.getNPags(),
|
108 |
bands, |
109 |
dataSourceHeight, |
110 |
cacheStruct.getDataType(), |
111 |
cacheStruct.getHPag()); |
112 |
pageCacheList.setHddPages(hddPageList); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* Load the cache status selected in the parameter. The array has one position for each
|
117 |
* page of cache. In each position has the page number loaded in that memory place.
|
118 |
*
|
119 |
* @param pageNumberInCache Array of positions
|
120 |
* @throws InterruptedException
|
121 |
*/
|
122 |
public void loadCacheStatus(int[] pageNumberInCache) throws InterruptedException { |
123 |
if(pageNumberInCache.length != pageCacheList.size())
|
124 |
return;
|
125 |
for (int iPage = 0; iPage < pageNumberInCache.length; iPage++) |
126 |
pageCacheList.get(iPage).loadPage(pageNumberInCache[iPage]); |
127 |
} |
128 |
|
129 |
/**
|
130 |
* Limpia los trozos de cach? en disco. Despu?s del llamar a este
|
131 |
* m?todo no puede volver a usarse esta cach?.
|
132 |
* @throws IOException
|
133 |
*/
|
134 |
public void clearCache() throws IOException { |
135 |
pageCacheList.clearPageList(); |
136 |
hddPageList.clearPageList(); |
137 |
} |
138 |
|
139 |
/*
|
140 |
* (non-Javadoc)
|
141 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getBitsPag()
|
142 |
*/
|
143 |
public int getBitsPag() { |
144 |
return cacheStruct.getBitsPag();
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* Obtiene la altura de la p?gina de cache en l?neas.
|
149 |
* @return N?mero de l?neas de altura de p?gina.
|
150 |
*/
|
151 |
public int getHPag() { |
152 |
return cacheStruct.getHPag();
|
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#isInCache(int)
|
158 |
*/
|
159 |
public boolean isInCache(int nPag) { |
160 |
/*if(nPag < 0 || nPag >= cacheada.length)
|
161 |
return false;*/
|
162 |
return cacheada[nPag];
|
163 |
} |
164 |
|
165 |
/*
|
166 |
* (non-Javadoc)
|
167 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setPageAsLoadInCache(int)
|
168 |
*/
|
169 |
public void setPageAsLoadInCache(int nPag) { |
170 |
if(nPag < 0 || nPag >= cacheada.length) |
171 |
return;
|
172 |
cacheada[nPag] = true;
|
173 |
} |
174 |
|
175 |
/*
|
176 |
* (non-Javadoc)
|
177 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setPageAsNotLoadInCache(int)
|
178 |
*/
|
179 |
public void setPageAsNotLoadInCache(int nPag) { |
180 |
if(nPag < 0 || nPag >= cacheada.length) |
181 |
return;
|
182 |
cacheada[nPag] = false;
|
183 |
} |
184 |
|
185 |
/*
|
186 |
* (non-Javadoc)
|
187 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getRasterPageNumberInPosition(int)
|
188 |
*/
|
189 |
public int getRasterPageNumberInPosition(int nCachePage) { |
190 |
return pageNumberInCache[nCachePage];
|
191 |
} |
192 |
|
193 |
/*
|
194 |
* (non-Javadoc)
|
195 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getRasterPageNumberInPosition(int, int)
|
196 |
*/
|
197 |
public int getRasterPageNumberInPosition(int group, int posInGroup) { |
198 |
return pageNumberInCache[group * getPagsPerGroup() + posInGroup];
|
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setRasterPageNumberInPosition(int, int)
|
204 |
*/
|
205 |
public void setRasterPageNumberInPosition(int nCachePage, int nRasterPage) { |
206 |
pageNumberInCache[nCachePage] = nRasterPage; |
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setRasterPageNumberInPosition(int, int, int)
|
212 |
*/
|
213 |
public void setRasterPageNumberInPosition(int group, int posInGroup, int nRasterPage) { |
214 |
pageNumberInCache[group * getPagsPerGroup() + posInGroup] = nRasterPage; |
215 |
} |
216 |
|
217 |
/**
|
218 |
* Obtiene el n?mero de p?gina de cach? donde est? cargada la p?gina del raster
|
219 |
* que se ha pasado por par?metro.
|
220 |
* @param pag P?gina del raster
|
221 |
* @return N?mero de p?gina del raster
|
222 |
*/
|
223 |
public int getNumberCachePageFromNumberRasterPage(int pag) { |
224 |
int group = pag % getNGroups();
|
225 |
for(int i = 0; i < getPagsPerGroup(); i++) |
226 |
if(pageNumberInCache[group + i] == pag)
|
227 |
return (group * getPagsPerGroup() + i);
|
228 |
return -1; |
229 |
} |
230 |
|
231 |
/*
|
232 |
* (non-Javadoc)
|
233 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getNumberGroupFromNumberRasterPage(int)
|
234 |
*/
|
235 |
public int[] getNumberGroupFromNumberRasterPage(int pag) { |
236 |
int group = pag % getNGroups();
|
237 |
for(int i = 0; i < getPagsPerGroup(); i++) |
238 |
if(pageNumberInCache[(group * getPagsPerGroup()) + i] == pag)
|
239 |
return new int[]{group, i}; |
240 |
return null; |
241 |
} |
242 |
|
243 |
/*
|
244 |
* (non-Javadoc)
|
245 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getLastAccess()
|
246 |
*/
|
247 |
public int[][] getLastAccess() { |
248 |
return lastAccess;
|
249 |
} |
250 |
|
251 |
/*
|
252 |
* (non-Javadoc)
|
253 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setZeroInLastAccess(int, int)
|
254 |
*/
|
255 |
public void setZeroInLastAccess(int group, int posInGroup) { |
256 |
lastAccess[group][posInGroup] = 0;
|
257 |
} |
258 |
|
259 |
/*
|
260 |
* (non-Javadoc)
|
261 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getNumberInAccessPage()
|
262 |
*/
|
263 |
public int getNumberInAccessPage() { |
264 |
return numberInAccessPage;
|
265 |
} |
266 |
|
267 |
/*
|
268 |
* (non-Javadoc)
|
269 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getPagsPerGroup()
|
270 |
*/
|
271 |
public int getPagsPerGroup() { |
272 |
return cacheStruct.getPagsPerGroup();
|
273 |
} |
274 |
|
275 |
/**
|
276 |
* Obtiene la p?gina de datos de la posici?n pag
|
277 |
* @param pag N?mero de p?gina de cach? a recuperar
|
278 |
* @return PageBuffer correspondiente a la p?gina recuperada
|
279 |
*/
|
280 |
public PageBuffer getPageBufferFromNumberCachePage(int pag) { |
281 |
return pageCacheList.get(pag);
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* Obtiene la p?gina de datos a partir del n?mero de p?gina de raster
|
286 |
* @param pag N?mero de p?gina raster a recuperar
|
287 |
* @return PageBuffer correspondiente a la p?gina recuperada o null si no est? en cach?
|
288 |
*/
|
289 |
public PageBuffer getPageBufferFromNumberRasterPage(int pag) { |
290 |
int group = pag % getNGroups();
|
291 |
for(int i = 0; i < getPagsPerGroup(); i++) |
292 |
if(pageNumberInCache[group * getPagsPerGroup() + i] == pag)
|
293 |
return pageCacheList.get(group * getPagsPerGroup() + i);
|
294 |
return null; |
295 |
} |
296 |
|
297 |
/*
|
298 |
* (non-Javadoc)
|
299 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getPageBuffer(int, int)
|
300 |
*/
|
301 |
public PageBuffer getPageBuffer(int group, int posInGroup) { |
302 |
return pageCacheList.get(group * getPagsPerGroup() + posInGroup);
|
303 |
} |
304 |
|
305 |
/*
|
306 |
* (non-Javadoc)
|
307 |
* @see org.cachete.buffer.stripecache.ICache#getAccessPage()
|
308 |
*/
|
309 |
public PageBuffer getAccessPage() {
|
310 |
return accessPage;
|
311 |
} |
312 |
|
313 |
/*
|
314 |
* (non-Javadoc)
|
315 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setAccessPage(org.gvsig.raster.cache.buffer.impl.stripecache.horizontal.PageBuffer, int)
|
316 |
*/
|
317 |
public void setAccessPage(PageBuffer pb, int pagNumber) { |
318 |
accessPage = pb; |
319 |
numberInAccessPage = pagNumber; |
320 |
} |
321 |
|
322 |
/*
|
323 |
* (non-Javadoc)
|
324 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#isModified(int)
|
325 |
*/
|
326 |
public boolean isModified(int nCachePag) { |
327 |
return modified[nCachePag];
|
328 |
} |
329 |
|
330 |
/*
|
331 |
* (non-Javadoc)
|
332 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#isModified(int, int)
|
333 |
*/
|
334 |
public boolean isModified(int group, int posInGroup) { |
335 |
return modified[group * getPagsPerGroup() + posInGroup];
|
336 |
} |
337 |
|
338 |
/*
|
339 |
* (non-Javadoc)
|
340 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#setModify(int)
|
341 |
*/
|
342 |
public void setModify(int nCachePag) { |
343 |
modified[nCachePag] = true;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* Pone como modificada una p?gina de cach?
|
348 |
* @param group Grupo en el que se encuentra la p?gina
|
349 |
* @param posInGroup Posici?n dentro del grupo en el que est? la p?gina
|
350 |
*/
|
351 |
public void setModify(int group, int posInGroup) { |
352 |
modified[group * getPagsPerGroup() + posInGroup] = true;
|
353 |
} |
354 |
|
355 |
/*
|
356 |
* (non-Javadoc)
|
357 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#unsetModify(int)
|
358 |
*/
|
359 |
public void unsetModify(int nCachePag) { |
360 |
modified[nCachePag] = false;
|
361 |
} |
362 |
|
363 |
/*
|
364 |
* (non-Javadoc)
|
365 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#unsetModify(int, int)
|
366 |
*/
|
367 |
public void unsetModify(int group, int posInGroup) { |
368 |
modified[group * getPagsPerGroup() + posInGroup] = false;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Obtiene el n?mero de p?ginas de la cach?
|
373 |
* @return N?mero total de p?ginas de la cach?
|
374 |
*/
|
375 |
public int getNPags() { |
376 |
return cacheStruct.getNPags();
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* Obtiene el n?mero de bandas
|
381 |
* @return N?mero de bandas
|
382 |
*/
|
383 |
public int getNBands() { |
384 |
return cacheStruct.getNBands();
|
385 |
} |
386 |
|
387 |
/**
|
388 |
* Obtiene la estructura de ca cach?
|
389 |
* @return CacheStruct
|
390 |
*/
|
391 |
public CacheStruct getCacheStruct() {
|
392 |
return cacheStruct;
|
393 |
} |
394 |
|
395 |
/**
|
396 |
* Asigna la estructura de ca cach?
|
397 |
* @param CacheStruct
|
398 |
*/
|
399 |
public void setCacheStruct(CacheStruct cacheStruct) { |
400 |
this.cacheStruct = cacheStruct;
|
401 |
} |
402 |
|
403 |
/*
|
404 |
* (non-Javadoc)
|
405 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getNGroups()
|
406 |
*/
|
407 |
public int getNGroups() { |
408 |
return cacheStruct.getNGroups();
|
409 |
} |
410 |
|
411 |
/*
|
412 |
* (non-Javadoc)
|
413 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#getNTotalPags()
|
414 |
*/
|
415 |
public int getNTotalPags() { |
416 |
return cacheStruct.getNTotalPags();
|
417 |
} |
418 |
|
419 |
/**
|
420 |
* Obtiene el array con los n?meros de p?gina que hay cargados
|
421 |
* en cada bloque de cache
|
422 |
* @return array con los n?mero de p?gina
|
423 |
*/
|
424 |
public int[] getPageNumberInCache() { |
425 |
return this.pageNumberInCache; |
426 |
} |
427 |
|
428 |
/**
|
429 |
* Para extraer el desplazamiento de una direcci?n (l?nea de raster) hay que hacer una operaci?n And con
|
430 |
* con la altura de la p?gina -1. Por ejemplo, una p?gina de 16 l?neas de altura el desplazamiento ser?
|
431 |
* 16 - 1 = 15 porque 15 en binario es 1111.
|
432 |
*
|
433 |
* Si queremos acceder a la linea del raster n?mero 83 (1010011) realizando la operaci?n And con el valor del
|
434 |
* desplazamiento obtenemos (0001111 & 1010011 = 0000011), es decir el valor 3 en decimal. Esto quiere decir
|
435 |
* que la l?nea 83 del raster es la 3 de su p?gina.
|
436 |
* @return valor del desplazamiento
|
437 |
*/
|
438 |
public int getOffset() { |
439 |
return cacheStruct.getOffset();
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* Convierte una p?gina dentro de un grupo de la cach? en un n?mero de
|
444 |
* p?gina de cach?. Por ejemplo, en una cach? de 10 grupos y 5 p?ginas por grupo
|
445 |
* la p?gina 2 del grupo 4 devolver? el 23 (5 * 4 + 3 = 23) teniendo en cuenta que
|
446 |
* la p?gina y el grupo cero tambi?n cuentan.
|
447 |
* @param group
|
448 |
* @param pageInGroup
|
449 |
* @return
|
450 |
*/
|
451 |
public int convertPageInGroupToPageInCache(int group, int pageInGroup) { |
452 |
return (group * cacheStruct.getPagsPerGroup() + pageInGroup);
|
453 |
} |
454 |
|
455 |
/*
|
456 |
* (non-Javadoc)
|
457 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#updateLastAccess(int)
|
458 |
*/
|
459 |
public int updateLastAccess(int group) { |
460 |
int max = Integer.MIN_VALUE; |
461 |
int posMax = 0; |
462 |
for(int i = 0; i < getPagsPerGroup(); i++) { |
463 |
if(getLastAccess()[group][i] >= 0) |
464 |
getLastAccess()[group][i] ++; |
465 |
|
466 |
if(getLastAccess()[group][i] > max) {
|
467 |
max = getLastAccess()[group][i]; |
468 |
posMax = i; |
469 |
} |
470 |
} |
471 |
return posMax;
|
472 |
} |
473 |
|
474 |
/**
|
475 |
* Obtiene la posici?n del grupo de la p?gina a reemplazar, es decir la de m?ximo valor
|
476 |
* en el vector lastAccess.
|
477 |
* @param group N?mero de grupo a obtener la p?gina de reemplazo
|
478 |
* @return La posici?n del elemento del grupo con valor m?ximo. Este elemento
|
479 |
* es el candidato para el reemplazo.
|
480 |
*/
|
481 |
public int posInGroupPagToReplace(int group) { |
482 |
int max = Integer.MIN_VALUE; |
483 |
int posMax = 0; |
484 |
for(int i = 0; i < getPagsPerGroup(); i++) { |
485 |
if(getLastAccess()[group][i] > max) {
|
486 |
max = getLastAccess()[group][i]; |
487 |
posMax = i; |
488 |
} |
489 |
} |
490 |
return posMax;
|
491 |
} |
492 |
|
493 |
/*
|
494 |
* (non-Javadoc)
|
495 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#loadPage(int, int, int)
|
496 |
*/
|
497 |
public void loadPage(int group, int posInGroupPageToReplace, int nPag) throws InterruptedException { |
498 |
pageCacheList.get(group * getPagsPerGroup() + posInGroupPageToReplace).loadPage(nPag); |
499 |
} |
500 |
|
501 |
/*
|
502 |
* (non-Javadoc)
|
503 |
* @see org.gvsig.raster.cache.buffer.impl.stripecache.ICache#savePage(int, int, int)
|
504 |
*/
|
505 |
public void savePage(int group, int posInGroupPageToReplace, int nPag) throws IOException { |
506 |
pageCacheList.get(group * getPagsPerGroup() + posInGroupPageToReplace).savePage(nPag); |
507 |
} |
508 |
|
509 |
/**
|
510 |
* Salva a disco todas las p?ginas en memoria cach? e inicializa estructuras de datos.
|
511 |
*
|
512 |
* @throws IOException
|
513 |
*/
|
514 |
public void resetCache() throws IOException { |
515 |
for (int iCachePage = 0; iCachePage < pageCacheList.size(); iCachePage++) { |
516 |
if(modified[iCachePage])
|
517 |
pageCacheList.get(iCachePage).savePage(this.getRasterPageNumberInPosition(iCachePage));
|
518 |
} |
519 |
initStructs(); |
520 |
} |
521 |
|
522 |
/**
|
523 |
* Remove the selected cache band from disk and memory
|
524 |
* @param iBand Band number to remove
|
525 |
* @throws IOException
|
526 |
*/
|
527 |
public void removeBand(int pos) throws IOException { |
528 |
pageCacheList.removeBand(pos); |
529 |
hddPageList.removeBand(pos); |
530 |
} |
531 |
|
532 |
/**
|
533 |
* Add an empty band in the cache
|
534 |
* @param iBand Band number to add
|
535 |
* @throws IOException
|
536 |
*/
|
537 |
public void addBand(int pos) throws IOException { |
538 |
resetCache(); |
539 |
pageCacheList.addBand(pos); |
540 |
PageBuffer buf = new PageBuffer(cacheStruct.getDataType(), dataSourceWidth, cacheStruct.getHPag(), 1, true); |
541 |
hddPageList.addBand(pos, buf); |
542 |
} |
543 |
|
544 |
/**
|
545 |
* Add a band in the cache
|
546 |
* @param iBand Band number to add
|
547 |
* @param Band Band to add
|
548 |
* @throws IOException
|
549 |
*/
|
550 |
public void addBand(int pos, Band band) throws IOException { |
551 |
resetCache(); |
552 |
pageCacheList.addBand(pos); |
553 |
PageBuffer buf = new PageBuffer(cacheStruct.getDataType(), dataSourceWidth, band.getBlockSize(), 1, true); |
554 |
hddPageList.addBand(pos, band, buf); |
555 |
} |
556 |
|
557 |
/**
|
558 |
* Swap bands accordint to positions selected in bandPosition parameter.
|
559 |
*
|
560 |
* @param bandPosition
|
561 |
* New order for the bands in the array. Each position in the array represent the old band
|
562 |
* .The number that it contains represent the new position of that band. For instance, an
|
563 |
* array with values {1, 0, 2, 3} means that it has four bands and the band number one is swaped
|
564 |
* with the band number zero. The bands two and three don't change its position in this example.
|
565 |
* @throws WrongParameterException
|
566 |
* @throws IOException
|
567 |
*/
|
568 |
public void swapBands(int[] bandPosition) throws WrongParameterException, IOException { |
569 |
resetCache(); |
570 |
pageCacheList.swapBands(bandPosition); |
571 |
hddPageList.swapBands(bandPosition); |
572 |
} |
573 |
|
574 |
/**
|
575 |
* Consulta si alguna p?gina de memoria tiene modificaciones para volcar a disco
|
576 |
* @return true si hay alguna p?gina con modificaciones y false si no la hay
|
577 |
*/
|
578 |
public boolean anyPageModified() { |
579 |
for (int iPage = 0; iPage < modified.length; iPage++) { |
580 |
if(modified[iPage])
|
581 |
return true; |
582 |
} |
583 |
return false; |
584 |
} |
585 |
|
586 |
/**
|
587 |
* Get the width of the data source
|
588 |
* @return int
|
589 |
*/
|
590 |
public int getDataSourceWidth() { |
591 |
return dataSourceWidth;
|
592 |
} |
593 |
|
594 |
/**
|
595 |
* Get the height of the data source
|
596 |
* @return int
|
597 |
*/
|
598 |
public int getDataSourceHeight() { |
599 |
return dataSourceHeight;
|
600 |
} |
601 |
|
602 |
/*
|
603 |
* (non-Javadoc)
|
604 |
* @see java.lang.Object#clone()
|
605 |
*/
|
606 |
public Object clone() { |
607 |
CacheVertImpl clon = cloneStructure(); |
608 |
clon.hddPageList = (HDDPageList)hddPageList.clone(); |
609 |
clon.pageCacheList = (PageCacheList)pageCacheList.clone(); |
610 |
clon.pageCacheList.setHddPages(clon.hddPageList); |
611 |
return clon;
|
612 |
} |
613 |
|
614 |
/**
|
615 |
* Clone the cache structure without clone data pages neither disk pages
|
616 |
* @return Cache
|
617 |
*/
|
618 |
public CacheVertImpl cloneStructure() {
|
619 |
CacheVertImpl clon = new CacheVertImpl(cacheStruct.getNBands(), cacheStruct.getDataType(), dataSourceWidth, dataSourceHeight);
|
620 |
for (int i = 0; i < cacheada.length; i++) |
621 |
clon.cacheada[i] = cacheada[i]; |
622 |
clon.numberInAccessPage = numberInAccessPage; |
623 |
for (int i = 0; i < pageNumberInCache.length; i++) |
624 |
clon.pageNumberInCache[i] = pageNumberInCache[i]; |
625 |
for (int i = 0; i < lastAccess.length; i++) { |
626 |
for (int j = 0; j < lastAccess[i].length; j++) { |
627 |
clon.lastAccess[i][j] = lastAccess[i][j]; |
628 |
} |
629 |
} |
630 |
for (int i = 0; i < modified.length; i++) |
631 |
clon.modified[i] = modified[i]; |
632 |
clon.cacheStruct = (CacheStruct)cacheStruct.clone(); |
633 |
return clon;
|
634 |
} |
635 |
|
636 |
/**
|
637 |
* Imprime la informaci?n de estructura de cach?
|
638 |
*/
|
639 |
public void show() { |
640 |
((org.gvsig.raster.cache.buffer.impl.stripecache.CacheStruct)cacheStruct).show(); |
641 |
System.out.println("Cacheada:"); |
642 |
for(int i = 0; i < cacheada.length; i++) |
643 |
System.out.print(i + "=" + cacheada[i]+" "); |
644 |
System.out.println();
|
645 |
System.out.println("LastAccess:"); |
646 |
for(int i = 0; i < cacheStruct.getNGroups(); i++) { |
647 |
System.out.println("Grupo " + i +":"); |
648 |
for(int j = 0; j < cacheStruct.getPagsPerGroup(); j++) |
649 |
System.out.println("elem " + j + " : " + "Page " + pageNumberInCache[i * cacheStruct.getPagsPerGroup() + j] + " : " + lastAccess[i][j]); |
650 |
|
651 |
} |
652 |
} |
653 |
|
654 |
} |