Revision 24975 branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/resource/Resource.java
Resource.java | ||
---|---|---|
7 | 7 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
8 | 8 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
9 | 9 |
|
10 |
/** |
|
11 |
* Encapsulates a system resource (file, database connection, etc). |
|
12 |
* It is used to manage usage and availability of shared system |
|
13 |
* resources. This interface allows monitoring a resource and helps |
|
14 |
* preventing dead locks on it as well as being freed as soon as |
|
15 |
* it is not being used. |
|
16 |
* |
|
17 |
* Data providers can provide implementations for their own resources. This |
|
18 |
* is specially interesting when resources require a specific treatment |
|
19 |
* beyond the standard shared file or connection, for instance to manage |
|
20 |
* connections to a server through its own connection pool. |
|
21 |
*/ |
|
10 | 22 |
public interface Resource { |
11 | 23 |
|
24 |
/** |
|
25 |
* Returns the resource's name. |
|
26 |
* |
|
27 |
* @return resource's name |
|
28 |
* |
|
29 |
* @throws AccessResourceException |
|
30 |
*/ |
|
12 | 31 |
public String getName() throws AccessResourceException; |
13 | 32 |
|
33 |
/** |
|
34 |
* Returns the resource parameters. These parameters contain |
|
35 |
* all the necessary information to access the resource. |
|
36 |
* |
|
37 |
* @return resource parameters. |
|
38 |
*/ |
|
14 | 39 |
public ResourceParameters getParameters(); |
15 | 40 |
|
41 |
/** |
|
42 |
* Returns the date and time in which this resource was |
|
43 |
* opened for the last time. |
|
44 |
* |
|
45 |
* @return |
|
46 |
* date and time in which this resource was opened for the last time. |
|
47 |
*/ |
|
16 | 48 |
public Date getLastTimeOpen(); |
17 | 49 |
|
50 |
/** |
|
51 |
* Returns the date and time in which this resource was |
|
52 |
* accessed for the last time. |
|
53 |
* |
|
54 |
* @return |
|
55 |
* date and time in which this resource was accessed for the last time. |
|
56 |
*/ |
|
18 | 57 |
public Date getLastTimeUsed(); |
19 | 58 |
|
59 |
/** |
|
60 |
* Returns whether this resource is already in use by someone. |
|
61 |
* |
|
62 |
* @return |
|
63 |
* true if this resource is in use, false if not. |
|
64 |
*/ |
|
20 | 65 |
public boolean inUse(); |
21 | 66 |
|
67 |
/** |
|
68 |
* Returns whether this resource is opened. |
|
69 |
* |
|
70 |
* @return |
|
71 |
* true if this resource is opened, false if not. |
|
72 |
*/ |
|
22 | 73 |
public boolean isOpen(); |
23 | 74 |
|
75 |
/** |
|
76 |
* Returns the number of times this resource has been opened |
|
77 |
* since it was created. |
|
78 |
* |
|
79 |
* @return |
|
80 |
* number of times this resource has been opened |
|
81 |
* since it was created. |
|
82 |
*/ |
|
24 | 83 |
public int openCount(); |
25 | 84 |
|
85 |
/** |
|
86 |
* Initiates a mutual exclusion block over this resource. It should be used |
|
87 |
* whenever a resource is going to be changed in any way, to avoid concurrent |
|
88 |
* changes and unexpected behavior. |
|
89 |
* |
|
90 |
* @throws ResourceBeginException |
|
91 |
*/ |
|
26 | 92 |
public void begin() throws ResourceBeginException; |
27 | 93 |
|
94 |
/** |
|
95 |
* Ends a mutual exclusion block. It <b>must</b> be used always after a begin() |
|
96 |
* call to prevent a dead lock. |
|
97 |
*/ |
|
28 | 98 |
public void end(); |
29 | 99 |
|
100 |
/** |
|
101 |
* If the resource is not in use, calling this method will send a close request |
|
102 |
* to all consumers referencing this resource. If the resource is in use, |
|
103 |
* calling this method will do nothing. |
|
104 |
* |
|
105 |
* @throws ResourceException |
|
106 |
*/ |
|
30 | 107 |
public void closeRequest() throws ResourceException; |
31 | 108 |
|
109 |
/** |
|
110 |
* Adds a consumer to this resource. This will create a weak reference |
|
111 |
* to the consumer in this resource's consumer list. |
|
112 |
* |
|
113 |
* @param consumer |
|
114 |
* the consumer that will be added to this resource's consumer list. |
|
115 |
*/ |
|
32 | 116 |
public void addConsumer(ResourceConsumer consumer); |
33 | 117 |
|
118 |
/** |
|
119 |
* Removes a consumer from this resource's consumer list. |
|
120 |
* |
|
121 |
* @param consumer |
|
122 |
* the consumer that will be removed. |
|
123 |
*/ |
|
34 | 124 |
public void removeConsumer(ResourceConsumer consumer); |
35 | 125 |
|
126 |
/** |
|
127 |
* Returns this resource's current number of consumers. |
|
128 |
* |
|
129 |
* @return |
|
130 |
* current number of consumers of this resource. |
|
131 |
*/ |
|
36 | 132 |
public int getConsumersCount(); |
37 |
|
|
133 |
|
|
134 |
/** |
|
135 |
* Returns an object that represents the resource. The actual type |
|
136 |
* depends on the resource provider. It could be a string with a |
|
137 |
* descriptive name or something more elaborated. |
|
138 |
* |
|
139 |
* @return |
|
140 |
* an object that represents the resource. |
|
141 |
* |
|
142 |
* @throws AccessResourceException |
|
143 |
*/ |
|
38 | 144 |
public Object get() throws AccessResourceException; |
39 | 145 |
|
146 |
/** |
|
147 |
* Returns a custom object containing extended data relative to |
|
148 |
* this resource. |
|
149 |
* |
|
150 |
* This is part of a simple mechanism to allow passing further data to |
|
151 |
* the resource that may be necessary for optimal treatment. |
|
152 |
* |
|
153 |
* @return |
|
154 |
* data related to this resource |
|
155 |
*/ |
|
40 | 156 |
public Object getData(); |
41 | 157 |
|
158 |
/** |
|
159 |
* Sets a custom object as this resource's extended data. |
|
160 |
* |
|
161 |
* This is part of a simple mechanism to allow passing further data to |
|
162 |
* the resource that may be necessary for optimal treatment. |
|
163 |
* |
|
164 |
* @param data |
|
165 |
* a custom object containing data related to this resource. |
|
166 |
*/ |
|
42 | 167 |
public void setData(Object data); |
43 | 168 |
|
44 | 169 |
} |
Also available in: Unified diff