Revision 28071
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/resource/exception/DisposeResorceManagerException.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.resource.exception; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.exception.DataListException; |
|
4 |
|
|
5 |
public class DisposeResorceManagerException extends DataListException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = -1818272776768733342L; |
|
11 |
|
|
12 |
private final static String MESSAGE_FORMAT = "Exception disposing."; |
|
13 |
private final static String MESSAGE_KEY = "_DisposeResorceManagerException"; |
|
14 |
|
|
15 |
public DisposeResorceManagerException() { |
|
16 |
super(MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID); |
|
17 |
} |
|
18 |
} |
|
0 | 19 |
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/resource/exception/ResourceNotClosedOnDisposeManagerException.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.resource.exception; |
|
2 |
|
|
3 |
import org.gvsig.fmap.dal.resource.Resource; |
|
4 |
|
|
5 |
public class ResourceNotClosedOnDisposeManagerException extends ResourceException { |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
*/ |
|
10 |
private static final long serialVersionUID = -4030443484190503144L; |
|
11 |
private final static String MESSAGE_FORMAT = "The '%(resource)s' still open when the manager begin to dispose."; |
|
12 |
private final static String MESSAGE_KEY = "_ResourceNotClosedOnDisposeManagerException"; |
|
13 |
|
|
14 |
public ResourceNotClosedOnDisposeManagerException(Resource resource) { |
|
15 |
super(resource, MESSAGE_FORMAT, MESSAGE_KEY, serialVersionUID); |
|
16 |
} |
|
17 |
} |
|
0 | 18 |
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/resource/impl/DefaultResourceManager.java | ||
---|---|---|
16 | 16 |
import org.gvsig.fmap.dal.resource.Resource; |
17 | 17 |
import org.gvsig.fmap.dal.resource.ResourceParameters; |
18 | 18 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
19 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
|
19 | 20 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
21 |
import org.gvsig.fmap.dal.resource.exception.ResourceNotClosedOnDisposeManagerException; |
|
20 | 22 |
import org.gvsig.fmap.dal.resource.spi.AbstractResource; |
21 | 23 |
import org.gvsig.fmap.dal.resource.spi.ResourceManagerProviderServices; |
22 | 24 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
... | ... | |
270 | 272 |
DATA_MANAGER_RESOURCE).getNames(); |
271 | 273 |
} |
272 | 274 |
|
275 |
public void closeResources() throws DataException { |
|
276 |
this.collectResources(); |
|
277 |
Resource res; |
|
278 |
Iterator iter = this.resources.values().iterator(); |
|
279 |
while (iter.hasNext()) { |
|
280 |
res = (Resource) iter.next(); |
|
281 |
res.closeRequest(); |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
public void dispose() throws DisposeResorceManagerException { |
|
286 |
DisposeResorceManagerException exception = new DisposeResorceManagerException(); |
|
287 |
|
|
288 |
try { |
|
289 |
this.collectResources(); |
|
290 |
} catch (DataException e) { |
|
291 |
exception.add(e); |
|
292 |
} |
|
293 |
Resource res; |
|
294 |
Iterator iter = this.resources.values().iterator(); |
|
295 |
while (iter.hasNext()) { |
|
296 |
res = (Resource) iter.next(); |
|
297 |
try { |
|
298 |
res.closeRequest(); |
|
299 |
if (res.openCount() > 0) { |
|
300 |
exception |
|
301 |
.add(new ResourceNotClosedOnDisposeManagerException( |
|
302 |
res)); |
|
303 |
} |
|
304 |
iter.remove(); |
|
305 |
} catch (ResourceException e) { |
|
306 |
exception.add(e); |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
this.resources = null; |
|
311 |
this.delegateObservable.deleteObservers(); |
|
312 |
this.delegateObservable = null; |
|
313 |
|
|
314 |
if (!exception.isEmpty()) { |
|
315 |
throw exception; |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
273 | 319 |
} |
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/resource/ResourceManager.java | ||
---|---|---|
3 | 3 |
import java.util.Iterator; |
4 | 4 |
|
5 | 5 |
import org.gvsig.fmap.dal.exception.DataException; |
6 |
import org.gvsig.fmap.dal.resource.exception.DisposeResorceManagerException; |
|
7 |
import org.gvsig.tools.observer.Observer; |
|
6 | 8 |
import org.gvsig.tools.observer.WeakReferencingObservable; |
7 |
import org.gvsig.tools.observer.Observer; |
|
8 | 9 |
|
9 | 10 |
/** |
10 | 11 |
* This interface is the responsible of shared resources management. |
11 |
*
|
|
12 |
* |
|
12 | 13 |
* Allows getting a resource, iterating over the available resources, and |
13 | 14 |
* collecting resources to free them as they become unused |
14 | 15 |
* |
... | ... | |
18 | 19 |
|
19 | 20 |
/** |
20 | 21 |
* Returns an iterator over the available resources. |
21 |
*
|
|
22 |
* |
|
22 | 23 |
* @return |
23 | 24 |
* iterator over the resources. |
24 | 25 |
*/ |
25 | 26 |
public Iterator iterator(); |
26 | 27 |
|
27 | 28 |
/** |
28 |
* Iterates over the resources and frees them if they are ready to
|
|
29 |
* Iterates over the resources and frees them if they are ready to |
|
29 | 30 |
* be freed. |
30 |
*
|
|
31 |
* |
|
31 | 32 |
* @throws DataException |
32 | 33 |
*/ |
33 | 34 |
public void collectResources() throws DataException; |
34 | 35 |
|
35 | 36 |
/** |
36 |
* Initializes the resource collection background process. Allows setting
|
|
37 |
* of the delay between each execution of the collector and also an
|
|
37 |
* Initializes the resource collection background process. Allows setting |
|
38 |
* of the delay between each execution of the collector and also an |
|
38 | 39 |
* observer to be notified on each execution. |
39 |
*
|
|
40 |
* |
|
40 | 41 |
* @param milis |
41 | 42 |
* delay between each execution of the resource collection process, in milliseconds. |
42 |
*
|
|
43 |
* |
|
43 | 44 |
* @param observer |
44 | 45 |
* an observer that will be notified on each execution of the resource collection process. |
45 | 46 |
*/ |
46 | 47 |
public void startResourceCollector(long milis, Observer observer); |
47 | 48 |
|
48 | 49 |
/** |
49 |
* Stops successive executions of the resource collector process. It does not interrupt
|
|
50 |
* the process if it is currently running, but it will not be executed anymore times.
|
|
50 |
* Stops successive executions of the resource collector process. It does not interrupt |
|
51 |
* the process if it is currently running, but it will not be executed anymore times. |
|
51 | 52 |
*/ |
52 | 53 |
public void stopResourceCollector(); |
53 | 54 |
|
55 |
/** |
|
56 |
* Close all register resources. |
|
57 |
* |
|
58 |
* @throws DataException |
|
59 |
*/ |
|
60 |
public void closeResources() throws DataException; |
|
61 |
|
|
62 |
public void dispose() throws DisposeResorceManagerException; |
|
63 |
|
|
54 | 64 |
} |
Also available in: Unified diff