svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / resource / Resource.java @ 40559
History | View | Annotate | Download (5.46 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.resource; |
25 |
|
26 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
27 |
import org.gvsig.fmap.dal.resource.exception.ResourceException; |
28 |
import org.gvsig.fmap.dal.resource.exception.ResourceExecuteException; |
29 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
30 |
|
31 |
/**
|
32 |
* Encapsulates a system resource (file, database connection, etc).
|
33 |
* It is used to manage usage and availability of shared system
|
34 |
* resources. This interface allows monitoring a resource and helps
|
35 |
* preventing dead locks on it as well as being freed as soon as
|
36 |
* it is not being used.
|
37 |
*
|
38 |
* Data providers can provide implementations for their own resources. This
|
39 |
* is specially interesting when resources require a specific treatment
|
40 |
* beyond the standard shared file or connection, for instance to manage
|
41 |
* connections to a server through its own connection pool.
|
42 |
*/
|
43 |
public interface Resource { |
44 |
|
45 |
/**
|
46 |
* Returns the resource's name.
|
47 |
*
|
48 |
* @return resource's name
|
49 |
*
|
50 |
* @throws AccessResourceException
|
51 |
*/
|
52 |
public String getName() throws AccessResourceException; |
53 |
|
54 |
/**
|
55 |
* Returns the resource parameters. These parameters contain
|
56 |
* all the necessary information to access the resource.
|
57 |
*
|
58 |
* @return resource parameters.
|
59 |
*/
|
60 |
public ResourceParameters getParameters();
|
61 |
|
62 |
/**
|
63 |
* Returns the date and time in which this resource was opened for the last
|
64 |
* time.
|
65 |
*
|
66 |
* @return date and time in which this resource was opened for the last
|
67 |
* time, in milliseconds.
|
68 |
*/
|
69 |
public long getLastTimeOpen(); |
70 |
|
71 |
/**
|
72 |
* Returns the date and time in which this resource was accessed for the
|
73 |
* last time.
|
74 |
*
|
75 |
* @return date and time in which this resource was accessed for the last
|
76 |
* time, in milliseconds.
|
77 |
*/
|
78 |
public long getLastTimeUsed(); |
79 |
|
80 |
/**
|
81 |
* Returns whether this resource is already in use by someone.
|
82 |
*
|
83 |
* @return
|
84 |
* true if this resource is in use, false if not.
|
85 |
*/
|
86 |
public boolean inUse(); |
87 |
|
88 |
/**
|
89 |
* Returns whether this resource is opened.
|
90 |
*
|
91 |
* @return
|
92 |
* true if this resource is opened, false if not.
|
93 |
*/
|
94 |
public boolean isOpen(); |
95 |
|
96 |
/**
|
97 |
* Returns the number of times this resource has been opened
|
98 |
* since it was created.
|
99 |
*
|
100 |
* @return
|
101 |
* number of times this resource has been opened
|
102 |
* since it was created.
|
103 |
*/
|
104 |
public int openCount(); |
105 |
|
106 |
/**
|
107 |
* Executes an action which uses the current {@link Resource}.
|
108 |
*
|
109 |
* @param runnable
|
110 |
* to execute
|
111 |
* @return the action return value
|
112 |
* @throws ResourceException
|
113 |
* if there is an error executing the action
|
114 |
*/
|
115 |
public Object execute(ResourceAction action) |
116 |
throws ResourceExecuteException;
|
117 |
|
118 |
/**
|
119 |
* If the resource is not in use, calling this method will send a close request
|
120 |
* to all consumers referencing this resource. If the resource is in use,
|
121 |
* calling this method will do nothing.
|
122 |
*
|
123 |
* @throws ResourceException
|
124 |
*/
|
125 |
public void closeRequest() throws ResourceException; |
126 |
|
127 |
/**
|
128 |
* Adds a consumer to this resource. This will create a weak reference
|
129 |
* to the consumer in this resource's consumer list.
|
130 |
*
|
131 |
* @param consumer
|
132 |
* the consumer that will be added to this resource's consumer list.
|
133 |
*/
|
134 |
public void addConsumer(ResourceConsumer consumer); |
135 |
|
136 |
/**
|
137 |
* Removes a consumer from this resource's consumer list.
|
138 |
*
|
139 |
* @param consumer
|
140 |
* the consumer that will be removed.
|
141 |
*/
|
142 |
public void removeConsumer(ResourceConsumer consumer); |
143 |
|
144 |
/**
|
145 |
* Returns this resource's current number of consumers.
|
146 |
*
|
147 |
* @return
|
148 |
* current number of consumers of this resource.
|
149 |
*/
|
150 |
public int getConsumersCount(); |
151 |
|
152 |
/**
|
153 |
* Returns an object that represents the resource. The actual type
|
154 |
* depends on the resource provider. It could be a string with a
|
155 |
* descriptive name or something more elaborated.
|
156 |
*
|
157 |
* @return
|
158 |
* an object that represents the resource.
|
159 |
*
|
160 |
* @throws AccessResourceException
|
161 |
*/
|
162 |
public Object get() throws AccessResourceException; |
163 |
|
164 |
/**
|
165 |
* Returns a custom object containing extended data relative to
|
166 |
* this resource.
|
167 |
*
|
168 |
* This is part of a simple mechanism to allow passing further data to
|
169 |
* the resource that may be necessary for optimal treatment.
|
170 |
*
|
171 |
* @return
|
172 |
* data related to this resource
|
173 |
*/
|
174 |
public Object getData(); |
175 |
|
176 |
/**
|
177 |
* Sets a custom object as this resource's extended data.
|
178 |
*
|
179 |
* This is part of a simple mechanism to allow passing further data to
|
180 |
* the resource that may be necessary for optimal treatment.
|
181 |
*
|
182 |
* @param data
|
183 |
* a custom object containing data related to this resource.
|
184 |
*/
|
185 |
public void setData(Object data); |
186 |
|
187 |
} |