Package org.gvsig.fmap.dal.resource
Interface Resource
- All Known Subinterfaces:
DBResource,ResourceProvider
public interface Resource
Encapsulates a system resource (file, database connection, etc).
It is used to manage usage and availability of shared system
resources. This interface allows monitoring a resource and helps
preventing dead locks on it as well as being freed as soon as
it is not being used.
Data providers can provide implementations for their own resources. This
is specially interesting when resources require a specific treatment
beyond the standard shared file or connection, for instance to manage
connections to a server through its own connection pool.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddConsumer(ResourceConsumer consumer) Adds a consumer to this resource.voidIf the resource is not in use, calling this method will send a close request to all consumers referencing this resource.execute(ResourceAction action) Executes an action which uses the currentResource.get()Returns an object that represents the resource.intReturns this resource's current number of consumers.getData()Returns a custom object containing extended data relative to this resource.longReturns the date and time in which this resource was opened for the last time.longReturns the date and time in which this resource was accessed for the last time.getName()Returns the resource's name.Returns the resource parameters.booleaninUse()Returns whether this resource is already in use by someone.booleanisOpen()Returns whether this resource is opened.intReturns the number of times this resource has been opened since it was created.voidremoveConsumer(ResourceConsumer consumer) Removes a consumer from this resource's consumer list.voidSets a custom object as this resource's extended data.
-
Method Details
-
getName
Returns the resource's name.- Returns:
- resource's name
- Throws:
AccessResourceException
-
getParameters
ResourceParameters getParameters()Returns the resource parameters. These parameters contain all the necessary information to access the resource.- Returns:
- resource parameters.
-
getLastTimeOpen
long getLastTimeOpen()Returns the date and time in which this resource was opened for the last time.- Returns:
- date and time in which this resource was opened for the last time, in milliseconds.
-
getLastTimeUsed
long getLastTimeUsed()Returns the date and time in which this resource was accessed for the last time.- Returns:
- date and time in which this resource was accessed for the last time, in milliseconds.
-
inUse
boolean inUse()Returns whether this resource is already in use by someone.- Returns:
- true if this resource is in use, false if not.
-
isOpen
boolean isOpen()Returns whether this resource is opened.- Returns:
- true if this resource is opened, false if not.
-
openCount
int openCount()Returns the number of times this resource has been opened since it was created.- Returns:
- number of times this resource has been opened since it was created.
-
execute
Executes an action which uses the currentResource.- Parameters:
runnable- to execute- Returns:
- the action return value
- Throws:
ResourceException- if there is an error executing the actionResourceExecuteException
-
closeRequest
If the resource is not in use, calling this method will send a close request to all consumers referencing this resource. If the resource is in use, calling this method will do nothing.- Throws:
ResourceException
-
addConsumer
Adds a consumer to this resource. This will create a weak reference to the consumer in this resource's consumer list.- Parameters:
consumer- the consumer that will be added to this resource's consumer list.
-
removeConsumer
Removes a consumer from this resource's consumer list.- Parameters:
consumer- the consumer that will be removed.
-
getConsumersCount
int getConsumersCount()Returns this resource's current number of consumers.- Returns:
- current number of consumers of this resource.
-
get
Returns an object that represents the resource. The actual type depends on the resource provider. It could be a string with a descriptive name or something more elaborated.- Returns:
- an object that represents the resource.
- Throws:
AccessResourceException
-
getData
Object getData()Returns a custom object containing extended data relative to this resource. This is part of a simple mechanism to allow passing further data to the resource that may be necessary for optimal treatment.- Returns:
- data related to this resource
-
setData
Sets a custom object as this resource's extended data. This is part of a simple mechanism to allow passing further data to the resource that may be necessary for optimal treatment.- Parameters:
data- a custom object containing data related to this resource.
-