org.jhotdraw.contrib.html
Interface DisposableResourceHolder

All Known Implementing Classes:
StandardDisposableResourceHolder

public interface DisposableResourceHolder

DisposableResourceHolder defines the interface for objects holding disposable resources.
A disposable resource is any kind of object that can be disposed of according to a given disposal strategy.
DisposableResourceHolder keeps track of the last time the resource is accessed to support ellapsed time ResourceDisposabilityStrategies.
For example, if you are handling large images that you can regenerate at will, the DisposableResourceHolder will hold the image, and if not accessed for let's say 60 secs then it discards the image (sets its reference to null) so that it can be GCed.
Within the context of JHotDraw, HTMLTextAreaFigure uses DisposableResourceHolders to handle the HTML generated image, but if the figure is not displayed (out of the display area or in a background view) then the image is disposed of after a while and the HTMLTextAreaFigure will regenerate it the next time it is displayed.
A resource may be locked so that its user can be sure it will not be disposed of while in use. After finished using it it should be unlocked so as to reintegrate it to the disposal strategy.

Version:
<$CURRENT_VERSION$>
Author:
Eduardo Francos - InContext
See Also:
DisposableResourceManager, StandardDisposableResourceManager, ResourceDisposabilityStrategy, DisposableResourceManagerFactory, StandardDisposableResourceHolder

Method Summary
 java.lang.Object clone()
          Makes a clone the this
 void dispose()
          Disposes of the resource immediately.
 long getDisposableDelay()
          Gets the disposableDelay
 long getLastTimeAccessed()
          Gets the lastTimeAccessed attribute of the DisposableResourceHolder object
 java.lang.Object getResource()
          Gets the resource
 boolean isAvailable()
          Returns true if the resource is still available
 boolean isLocked()
          True if the resource is locked
 void lock()
          Locks the resource so it cannot be automatically disposed of until unlock is called.
 void resetDelay()
          Resets the disposing delay so as to restart the time counter
 void setDisposableDelay(long millis)
          Sets the disposableDelay
 void setResource(java.lang.Object resource)
          Sets the resource
 void unlock()
          Unlocks the resource so it can be automatically disposed of again.
 

Method Detail

getResource

java.lang.Object getResource()
                             throws java.lang.NullPointerException
Gets the resource

Returns:
The resource value
Throws:
java.lang.NullPointerException - If the resource was disposed of

clone

java.lang.Object clone()
Makes a clone the this

Returns:
the clone

setResource

void setResource(java.lang.Object resource)
Sets the resource

Parameters:
resource - The new resource value

setDisposableDelay

void setDisposableDelay(long millis)
Sets the disposableDelay

Parameters:
millis - The new disposableDelay value

getDisposableDelay

long getDisposableDelay()
Gets the disposableDelay

Returns:
The disposableDelay value

resetDelay

void resetDelay()
Resets the disposing delay so as to restart the time counter


getLastTimeAccessed

long getLastTimeAccessed()
Gets the lastTimeAccessed attribute of the DisposableResourceHolder object

Returns:
The lastTimeAccessed value

dispose

void dispose()
Disposes of the resource immediately.


isAvailable

boolean isAvailable()
Returns true if the resource is still available

Returns:
The resourceDirty value

lock

void lock()
Locks the resource so it cannot be automatically disposed of until unlock is called.
Explicit disposing by calling dispose() is still possible though.


unlock

void unlock()
Unlocks the resource so it can be automatically disposed of again.
Explicit disposing by calling dispose() is still possible though.


isLocked

boolean isLocked()
True if the resource is locked

Returns:
The locked status