public abstract class AbstractResource extends java.lang.Object implements ResourceProvider, WeakReferencingObservable
Base implementation for Resource
This implementation not define the Resource#begin()
and
Resource#end()
Modifier and Type | Field and Description |
---|---|
protected java.lang.Object |
lock |
protected java.lang.Object |
multiResourcelock |
Modifier | Constructor and Description |
---|---|
protected |
AbstractResource(ResourceParameters parameters) |
Modifier and Type | Method and Description |
---|---|
void |
addConsumer(ResourceConsumer consumer)
Adds a consumer to this resource.
|
void |
addObserver(Observer o) |
void |
addObservers(BaseWeakReferencingObservable observers) |
void |
closeRequest()
If the resource is not in use, calling this method will send a close request
to all consumers referencing this resource.
|
void |
deleteObserver(Observer o) |
void |
deleteObservers() |
java.lang.Object |
execute(ResourceAction action)
Executes an action which uses the current
Resource . |
protected void |
executeBegins() |
protected void |
executeEnds() |
abstract java.lang.Object |
get()
Returns the real resource represented by this object.
|
ResourceConsumer |
getConsumerAt(int i) |
int |
getConsumersCount()
Returns this resource's current number of consumers.
|
java.lang.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.
|
abstract java.lang.String |
getName()
Returns the name of the
Resource . |
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.
|
void |
notifyChanges() |
void |
notifyClose() |
void |
notifyDispose() |
protected void |
notifyObserver(java.lang.String type) |
void |
notifyOpen() |
int |
openCount()
Returns the number of times this resource has been opened
since it was created.
|
protected java.lang.Object |
performExecution(ResourceAction action) |
void |
prepare() |
void |
prepare(ResourceParameters params) |
void |
removeConsumer(ResourceConsumer consumer)
Removes a consumer from this resource's consumer list.
|
void |
setData(java.lang.Object data)
Sets a custom object as this resource's extended data.
|
protected void |
updateLastTimeOpen() |
protected void |
updateLastTimeUsed() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isThis
protected final java.lang.Object lock
protected java.lang.Object multiResourcelock
protected AbstractResource(ResourceParameters parameters) throws InitializeException
InitializeException
protected final void updateLastTimeUsed()
protected final void updateLastTimeOpen()
public final long getLastTimeOpen()
Resource
getLastTimeOpen
in interface Resource
public final long getLastTimeUsed()
Resource
getLastTimeUsed
in interface Resource
public ResourceParameters getParameters()
Resource
getParameters
in interface Resource
public void prepare(ResourceParameters params) throws PrepareResourceException
PrepareResourceException
public void prepare() throws PrepareResourceException
prepare
in interface ResourceProvider
PrepareResourceException
public void notifyOpen() throws ResourceNotifyOpenException
notifyOpen
in interface ResourceProvider
ResourceNotifyOpenException
public void notifyClose() throws ResourceNotifyCloseException
notifyClose
in interface ResourceProvider
ResourceNotifyCloseException
public void notifyChanges() throws ResourceNotifyChangesException
notifyChanges
in interface ResourceProvider
ResourceNotifyChangesException
public boolean isOpen()
Resource
public int openCount()
Resource
public void addObserver(Observer o)
addObserver
in interface Observable
public void deleteObserver(Observer o)
deleteObserver
in interface Observable
public void deleteObservers()
deleteObservers
in interface Observable
public final void addObservers(BaseWeakReferencingObservable observers)
public final void addConsumer(ResourceConsumer consumer)
Resource
addConsumer
in interface Resource
consumer
- the consumer that will be added to this resource's consumer list.public final void removeConsumer(ResourceConsumer consumer)
Resource
removeConsumer
in interface Resource
consumer
- the consumer that will be removed.public int getConsumersCount()
Resource
getConsumersCount
in interface Resource
public ResourceConsumer getConsumerAt(int i)
public void closeRequest() throws ResourceException
Resource
closeRequest
in interface Resource
ResourceException
public void setData(java.lang.Object data)
Resource
public java.lang.Object getData()
Resource
protected void notifyObserver(java.lang.String type)
public void notifyDispose() throws ResourceNotifyDisposeException
notifyDispose
in interface ResourceProvider
ResourceNotifyDisposeException
public final boolean inUse()
Resource
public java.lang.Object execute(ResourceAction action) throws ResourceExecuteException
Resource
Resource
.execute
in interface Resource
ResourceExecuteException
protected java.lang.Object performExecution(ResourceAction action) throws java.lang.Exception
java.lang.Exception
protected final void executeBegins()
protected final void executeEnds()
public abstract java.lang.String getName() throws AccessResourceException
Resource
.getName
in interface Resource
AccessResourceException
- if there is an error while accessing the resourcepublic abstract java.lang.Object get() throws AccessResourceException
get
in interface Resource
AccessResourceException
- if there is an error while accessing the resource