Revision 23509
branches/v2_0_0_prep/libraries/libFMap_dataFile/src-test/org/gvsig/fmap/data/feature/file/ResourceManagerTest.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
import junit.framework.TestCase; |
37 | 37 |
|
38 |
import org.gvsig.tools.exception.BaseException; |
|
39 | 38 |
import org.gvsig.fmap.data.CloseException; |
40 | 39 |
import org.gvsig.fmap.data.DataCollection; |
41 | 40 |
import org.gvsig.fmap.data.DataException; |
... | ... | |
45 | 44 |
import org.gvsig.fmap.data.ResourceManager; |
46 | 45 |
import org.gvsig.fmap.data.ResourceNotification; |
47 | 46 |
import org.gvsig.fmap.data.feature.file.shp.SHPTest; |
47 |
import org.gvsig.tools.exception.BaseException; |
|
48 | 48 |
import org.gvsig.tools.observer.Observable; |
49 | 49 |
import org.gvsig.tools.observer.Observer; |
50 | 50 |
|
... | ... | |
87 | 87 |
System.out.println("** closed: " + name + "(" + key + ")"); |
88 | 88 |
} |
89 | 89 |
|
90 |
rManager.remove(res); |
|
91 |
System.out.println("** removed: " + name + "(" + key + ")"); |
|
90 |
rManager.forceRemove(res); |
|
91 |
System.out.println("** removed (forced): " + name + "(" + key |
|
92 |
+ ")"); |
|
92 | 93 |
|
93 | 94 |
iter = rManager.iterator(); |
94 | 95 |
} |
... | ... | |
447 | 448 |
assertEquals(2, closer.getOpenedResources()); |
448 | 449 |
|
449 | 450 |
} |
451 |
|
|
452 |
public void test_deadResources() { |
|
453 |
ResourceCloser closer = new ResourceCloser(); |
|
454 |
|
|
455 |
//Nos aseguramos que no hay recursos abiertos |
|
456 |
try { |
|
457 |
closer.closeAndDisposeAll(); |
|
458 |
} catch (Exception e1) { |
|
459 |
e1.printStackTrace(); |
|
460 |
fail(); |
|
461 |
} |
|
462 |
org.gvsig.fmap.data.feature.file.dbf.Register.selfRegister(); |
|
463 |
org.gvsig.fmap.data.feature.file.shp.Register.selfRegister(); |
|
464 |
org.gvsig.fmap.data.feature.file.dxf.Register.selfRegister(); |
|
465 |
org.gvsig.fmap.data.feature.file.dgn.Register.selfRegister(); |
|
466 |
|
|
467 |
DataStore shp = null; |
|
468 |
|
|
469 |
ResourceManager rManager = ResourceManager.getResourceManager(); |
|
470 |
|
|
471 |
try { |
|
472 |
shp = dataManager.createDataStore(SHPTest |
|
473 |
.getParams(SHPTest.fileNormal)); |
|
474 |
shp.getMetadata(); |
|
475 |
} catch (BaseException e) { |
|
476 |
e.printStackTrace(); |
|
477 |
fail(); |
|
478 |
} |
|
479 |
assertEquals(2, closer.getOpenedResources()); |
|
480 |
|
|
481 |
// Eliminamos la referencia al Store para que se quede 'colgado' el recurso |
|
482 |
shp = null; |
|
483 |
assertEquals(2, closer.getOpenedResources()); |
|
484 |
|
|
485 |
// lanzamos el garbageCollector para que se muera la referencia |
|
486 |
System.gc(); |
|
487 |
System.gc(); |
|
488 |
System.gc(); |
|
489 |
|
|
490 |
// Cogemos el primer recuros y pedimos su cantidad de referencias |
|
491 |
// esto deber?a de dejar la referencias a 0. |
|
492 |
Iterator iter = rManager.iterator(); |
|
493 |
|
|
494 |
assertEquals(0, ((Resource) iter.next()).getRefencesCount()); |
|
495 |
|
|
496 |
//lanzamos la 'recoleccion' y deber?a de dejar todas las referencia limpias |
|
497 |
// y el manager vacio |
|
498 |
try { |
|
499 |
rManager.collectDeadResources(); |
|
500 |
} catch (DataException e) { |
|
501 |
e.printStackTrace(); |
|
502 |
fail(); |
|
503 |
return; |
|
504 |
} |
|
505 |
|
|
506 |
assertEquals(0, closer.getOpenedResources()); |
|
507 |
|
|
508 |
assertEquals(0, closer.getResourcesOrdered().size()); |
|
509 |
|
|
510 |
|
|
511 |
} |
|
512 |
|
|
513 |
public void test_deadResourcesThread() { |
|
514 |
ResourceCloser closer = new ResourceCloser(); |
|
515 |
|
|
516 |
//Nos aseguramos que no hay recursos abiertos |
|
517 |
try { |
|
518 |
closer.closeAndDisposeAll(); |
|
519 |
} catch (Exception e1) { |
|
520 |
e1.printStackTrace(); |
|
521 |
fail(); |
|
522 |
} |
|
523 |
org.gvsig.fmap.data.feature.file.dbf.Register.selfRegister(); |
|
524 |
org.gvsig.fmap.data.feature.file.shp.Register.selfRegister(); |
|
525 |
org.gvsig.fmap.data.feature.file.dxf.Register.selfRegister(); |
|
526 |
org.gvsig.fmap.data.feature.file.dgn.Register.selfRegister(); |
|
527 |
|
|
528 |
DataStore shp = null; |
|
529 |
|
|
530 |
ResourceManager rManager = ResourceManager.getResourceManager(); |
|
531 |
|
|
532 |
//Lanzamos el thread |
|
533 |
|
|
534 |
rManager.startDeadResourceCollectorThread(10); // 1/100 seg |
|
535 |
|
|
536 |
try { |
|
537 |
shp = dataManager.createDataStore(SHPTest |
|
538 |
.getParams(SHPTest.fileNormal)); |
|
539 |
shp.getMetadata(); |
|
540 |
} catch (BaseException e) { |
|
541 |
e.printStackTrace(); |
|
542 |
fail(); |
|
543 |
} |
|
544 |
assertEquals(2, closer.getOpenedResources()); |
|
545 |
|
|
546 |
// Eliminamos la referencia al Store para que se quede 'colgado' el recurso |
|
547 |
shp = null; |
|
548 |
assertEquals(2, closer.getOpenedResources()); |
|
549 |
|
|
550 |
long t = System.currentTimeMillis(); |
|
551 |
while (System.currentTimeMillis() - t < 50) { |
|
552 |
// lanzamos el garbageCollector para que se muera la referencia |
|
553 |
System.gc(); |
|
554 |
} |
|
555 |
|
|
556 |
|
|
557 |
// Comprobamos que los recursos ya no existen |
|
558 |
assertEquals(0, closer.getOpenedResources()); |
|
559 |
|
|
560 |
assertEquals(0, closer.getResourcesOrdered().size()); |
|
561 |
|
|
562 |
rManager.stopDeadResourceCollectorThread(); |
|
563 |
|
|
564 |
} |
|
565 |
|
|
450 | 566 |
} |
branches/v2_0_0_prep/libraries/libFMap_dataFile/src-test/org/gvsig/fmap/data/feature/file/DataStoreTest.java | ||
---|---|---|
1114 | 1114 |
fail(); |
1115 | 1115 |
} |
1116 | 1116 |
|
1117 |
int i = 0; |
|
1118 |
Resource res = null; |
|
1119 |
Resource tmpRes = null; |
|
1120 |
Object obj = null; |
|
1117 |
Resource res = getResource(params); |
|
1121 | 1118 |
|
1122 |
Iterator iter = resMan.iterator(); |
|
1123 |
while (iter.hasNext()) { |
|
1124 |
obj = iter.next(); |
|
1125 |
if (obj instanceof FileResource) { |
|
1126 |
tmpRes = (Resource) obj; |
|
1127 |
if (((FileResource) tmpRes).getFile().getAbsoluteFile().equals( |
|
1128 |
params.getFile().getAbsoluteFile())) { |
|
1129 |
i++; |
|
1130 |
res = tmpRes; |
|
1131 |
} |
|
1132 |
} |
|
1133 |
} |
|
1119 |
assertNotNull(res); |
|
1134 | 1120 |
|
1135 |
assertEquals(1, i); |
|
1136 |
|
|
1137 | 1121 |
assertEquals(3, res.getRefencesCount()); |
1138 | 1122 |
|
1139 | 1123 |
try { |
... | ... | |
1263 | 1247 |
} |
1264 | 1248 |
|
1265 | 1249 |
assertEquals(0, res.getRefencesCount()); |
1266 |
res = null;
|
|
1250 |
res = getResource(params);
|
|
1267 | 1251 |
|
1268 |
i = 0; |
|
1269 |
iter = resMan.iterator(); |
|
1270 |
while (iter.hasNext()) { |
|
1271 |
obj = iter.next(); |
|
1272 |
if (obj instanceof FileResource) { |
|
1273 |
tmpRes = (Resource) obj; |
|
1274 |
if (((FileResource) tmpRes).getFile().getAbsoluteFile().equals( |
|
1275 |
params.getFile().getAbsoluteFile())) { |
|
1276 |
i++; |
|
1277 |
res = tmpRes; |
|
1278 |
} |
|
1279 |
} |
|
1280 |
} |
|
1252 |
assertNull(res); |
|
1281 | 1253 |
|
1282 |
assertEquals(0, i); |
|
1283 |
|
|
1284 | 1254 |
doPrepareFileResourceTest(params); |
1285 | 1255 |
|
1286 | 1256 |
} |
... | ... | |
1576 | 1546 |
} |
1577 | 1547 |
|
1578 | 1548 |
} |
1549 |
|
|
1550 |
protected static Resource getResource(FileStoreParameters params) { |
|
1551 |
Resource tmpRes = null; |
|
1552 |
Object obj = null; |
|
1553 |
|
|
1554 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
|
1555 |
|
|
1556 |
Iterator iter = resMan.iterator(); |
|
1557 |
while (iter.hasNext()) { |
|
1558 |
obj = iter.next(); |
|
1559 |
if (obj instanceof FileResource) { |
|
1560 |
tmpRes = (Resource) obj; |
|
1561 |
if (((FileResource) tmpRes).getFile().getAbsoluteFile().equals( |
|
1562 |
params.getFile().getAbsoluteFile())) { |
|
1563 |
return tmpRes; |
|
1564 |
} |
|
1565 |
} |
|
1566 |
} |
|
1567 |
return null; |
|
1568 |
} |
|
1579 | 1569 |
} |
branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/fmap/data/feature/file/dxf/DXFStore.java | ||
---|---|---|
59 | 59 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
60 | 60 |
|
61 | 61 |
try { |
62 |
this.dxf = (DXFResource)resMan.addResource(tmpResource);
|
|
62 |
this.dxf = (DXFResource) resMan.addResource(tmpResource, this);
|
|
63 | 63 |
// this.dxf.load(); |
64 | 64 |
} catch (DataException e1) { |
65 | 65 |
throw new InitializeException(this.getName(),e1); |
... | ... | |
295 | 295 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
296 | 296 |
|
297 | 297 |
try { |
298 |
resMan.remove(this.dxf); |
|
298 |
resMan.remove(this.dxf, this);
|
|
299 | 299 |
} catch (DataException e1) { |
300 | 300 |
throw new CloseException(this.getName(),e1); |
301 | 301 |
} catch (KeyException e) { |
branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/fmap/data/feature/file/dgn/DGNResource.java | ||
---|---|---|
164 | 164 |
DGNElemCore elemento = m_DgnReader.DGNReadElement(); |
165 | 165 |
nClass = 0; |
166 | 166 |
// auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0); |
167 |
auxFeature.set(ID_FIELD_HEIGHTTEXT, 0); |
|
167 |
auxFeature.set(ID_FIELD_HEIGHTTEXT, 0.0f);
|
|
168 | 168 |
// auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0); |
169 |
auxFeature.set(ID_FIELD_ROTATIONTEXT, 0); |
|
169 |
auxFeature.set(ID_FIELD_ROTATIONTEXT, 0.0);
|
|
170 | 170 |
// auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue(); |
171 | 171 |
auxFeature.set(ID_FIELD_TEXT, null); |
172 | 172 |
|
branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/fmap/data/feature/file/dgn/DGNStore.java | ||
---|---|---|
56 | 56 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
57 | 57 |
|
58 | 58 |
try { |
59 |
this.dgn = (DGNResource)resMan.addResource(tmpResource);
|
|
59 |
this.dgn = (DGNResource) resMan.addResource(tmpResource, this);
|
|
60 | 60 |
} catch (DataException e1) { |
61 | 61 |
throw new InitializeException(this.getName(),e1); |
62 | 62 |
} |
... | ... | |
273 | 273 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
274 | 274 |
|
275 | 275 |
try { |
276 |
resMan.remove(this.dgn); |
|
276 |
resMan.remove(this.dgn, this);
|
|
277 | 277 |
} catch (DataException e1) { |
278 | 278 |
throw new CloseException(this.getName(),e1); |
279 | 279 |
} catch (KeyException e) { |
branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/fmap/data/feature/file/shp/SHPStore.java | ||
---|---|---|
4 | 4 |
import java.security.KeyException; |
5 | 5 |
import java.util.Iterator; |
6 | 6 |
|
7 |
import org.gvsig.tools.exception.BaseException; |
|
8 | 7 |
import org.gvsig.fmap.data.CloseException; |
9 | 8 |
import org.gvsig.fmap.data.DataCollection; |
10 | 9 |
import org.gvsig.fmap.data.DataException; |
... | ... | |
31 | 30 |
import org.gvsig.metadata.IMetadata; |
32 | 31 |
import org.gvsig.metadata.IMetadataManager; |
33 | 32 |
import org.gvsig.metadata.MetadataManager; |
33 |
import org.gvsig.tools.exception.BaseException; |
|
34 | 34 |
|
35 | 35 |
public class SHPStore extends DBFStore{ |
36 | 36 |
public static String DATASTORE_NAME = "SHPStore"; |
... | ... | |
61 | 61 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
62 | 62 |
|
63 | 63 |
try { |
64 |
this.shp = (SHPResource)resMan.addResource(tmpResource);
|
|
64 |
this.shp = (SHPResource) resMan.addResource(tmpResource, this);
|
|
65 | 65 |
} catch (DataException e1) { |
66 | 66 |
throw new InitializeException(this.getName(),e1); |
67 | 67 |
} |
... | ... | |
162 | 162 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
163 | 163 |
|
164 | 164 |
try { |
165 |
resMan.remove(this.shp); |
|
165 |
resMan.remove(this.shp, this);
|
|
166 | 166 |
} catch (DataException e1) { |
167 | 167 |
throw new CloseException(this.getName(),e1); |
168 | 168 |
} catch (KeyException e) { |
branches/v2_0_0_prep/libraries/libFMap_dataFile/src/org/gvsig/fmap/data/feature/file/dbf/DBFStore.java | ||
---|---|---|
51 | 51 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
52 | 52 |
|
53 | 53 |
try { |
54 |
this.dbf = (DBFResource)resMan.addResource(tmpResource);
|
|
54 |
this.dbf = (DBFResource) resMan.addResource(tmpResource, this);
|
|
55 | 55 |
} catch (DataException e1) { |
56 | 56 |
throw new InitializeException(this.getName(),e1); |
57 | 57 |
} |
... | ... | |
239 | 239 |
ResourceManager resMan = ResourceManager.getResourceManager(); |
240 | 240 |
|
241 | 241 |
try { |
242 |
resMan.remove(this.dbf); |
|
242 |
resMan.remove(this.dbf, this);
|
|
243 | 243 |
} catch (DataException e1) { |
244 | 244 |
throw new CloseException(this.getName(),e1); |
245 | 245 |
} catch (KeyException e) { |
Also available in: Unified diff