org.gvsig.fmap.dal.resource
Interface Resource


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
 void addConsumer(org.gvsig.fmap.dal.resource.spi.ResourceConsumer consumer)
          Adds a consumer to this resource.
 void closeRequest()
          If the resource is not in use, calling this method will send a close request to all consumers referencing this resource.
 Object execute(ResourceAction action)
          Executes an action which uses the current Resource.
 Object get()
          Returns an object that represents the resource.
 int getConsumersCount()
          Returns this resource's current number of consumers.
 Object getData()
          Returns a custom object containing extended data relative to this resource.
 long getLastTimeOpen()
          Returns the date and time in which this resource was opened for the last time.
 long getLastTimeUsed()
          Returns the date and time in which this resource was accessed for the last time.
 String getName()
          Returns the resource's name.
 ResourceParameters getParameters()
          Returns the resource parameters.
 boolean inUse()
          Returns whether this resource is already in use by someone.
 boolean isOpen()
          Returns whether this resource is opened.
 int openCount()
          Returns the number of times this resource has been opened since it was created.
 void removeConsumer(org.gvsig.fmap.dal.resource.spi.ResourceConsumer consumer)
          Removes a consumer from this resource's consumer list.
 void setData(Object data)
          Sets a custom object as this resource's extended data.
 

Method Detail

getName

String getName()
               throws AccessResourceException
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

Object execute(ResourceAction action)
               throws ResourceExecuteException
Executes an action which uses the current Resource.

Parameters:
runnable - to execute
Returns:
the action return value
Throws:
ResourceException - if there is an error executing the action
ResourceExecuteException

closeRequest

void closeRequest()
                  throws ResourceException
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

void addConsumer(org.gvsig.fmap.dal.resource.spi.ResourceConsumer consumer)
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

void removeConsumer(org.gvsig.fmap.dal.resource.spi.ResourceConsumer consumer)
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

Object get()
           throws AccessResourceException
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

void setData(Object data)
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.


Copyright © 2004-2012 gvSIG. All Rights Reserved.