public abstract class AbstractResource extends 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 Object |
lock |
protected 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() |
Object |
execute(ResourceAction action)
Executes an action which uses the current
Resource. |
protected void |
executeBegins() |
protected void |
executeEnds() |
abstract Object |
get()
Returns the real resource represented by this object.
|
ResourceConsumer |
getConsumerAt(int i) |
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.
|
abstract 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(String type) |
void |
notifyOpen() |
int |
openCount()
Returns the number of times this resource has been opened
since it was created.
|
protected 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(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, waitisThisprotected AbstractResource(ResourceParameters parameters) throws InitializeException
InitializeExceptionprotected final void updateLastTimeUsed()
protected final void updateLastTimeOpen()
public final long getLastTimeOpen()
ResourcegetLastTimeOpen in interface Resourcepublic final long getLastTimeUsed()
ResourcegetLastTimeUsed in interface Resourcepublic final ResourceParameters getParameters()
ResourcegetParameters in interface Resourcepublic void prepare(ResourceParameters params) throws PrepareResourceException
PrepareResourceExceptionpublic void prepare()
throws PrepareResourceException
prepare in interface ResourceProviderPrepareResourceExceptionpublic void notifyOpen()
throws ResourceNotifyOpenException
notifyOpen in interface ResourceProviderResourceNotifyOpenExceptionpublic void notifyClose()
throws ResourceNotifyCloseException
notifyClose in interface ResourceProviderResourceNotifyCloseExceptionpublic void notifyChanges()
throws ResourceNotifyChangesException
notifyChanges in interface ResourceProviderResourceNotifyChangesExceptionpublic boolean isOpen()
Resourcepublic int openCount()
Resourcepublic void addObserver(Observer o)
addObserver in interface Observablepublic void deleteObserver(Observer o)
deleteObserver in interface Observablepublic void deleteObservers()
deleteObservers in interface Observablepublic final void addObservers(BaseWeakReferencingObservable observers)
public final void addConsumer(ResourceConsumer consumer)
ResourceaddConsumer in interface Resourceconsumer - the consumer that will be added to this resource's consumer list.public final void removeConsumer(ResourceConsumer consumer)
ResourceremoveConsumer in interface Resourceconsumer - the consumer that will be removed.public int getConsumersCount()
ResourcegetConsumersCount in interface Resourcepublic ResourceConsumer getConsumerAt(int i)
public void closeRequest()
throws ResourceException
ResourcecloseRequest in interface ResourceResourceExceptionpublic void setData(Object data)
Resourcepublic Object getData()
Resourceprotected void notifyObserver(String type)
public void notifyDispose()
throws ResourceNotifyDisposeException
notifyDispose in interface ResourceProviderResourceNotifyDisposeExceptionpublic final boolean inUse()
Resourcepublic Object execute(ResourceAction action) throws ResourceExecuteException
ResourceResource.execute in interface ResourceResourceExecuteExceptionprotected Object performExecution(ResourceAction action) throws Exception
Exceptionprotected final void executeBegins()
protected final void executeEnds()
public abstract String getName() throws AccessResourceException
Resource.getName in interface ResourceAccessResourceException - if there is an error while accessing the resourcepublic abstract Object get() throws AccessResourceException
get in interface ResourceAccessResourceException - if there is an error while accessing the resource