public final class SwappingTileCache extends Observable implements javax.media.jai.TileCache, com.sun.media.jai.util.CacheDiagnostics
javax.media.jai.TileCache
interface. In opposite to the
Sun implementation, we'll never throw away any tiles but instead swap them to a
SwapSpace
.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_HASHTABLE_CAPACITY
The default hashtable capacity (heuristic)
|
static long |
DEFAULT_MEMORY_CAPACITY
The default memory capacity of the cache (16 MB).
|
static File |
DEFAULT_SWAP_DIR
The default directory where tiles are stored if they don't fit into memory anymore.
|
Constructor and Description |
---|
SwappingTileCache()
No args constructor.
|
SwappingTileCache(long memoryCapacity,
SwapSpace swapSpace)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(RenderedImage owner,
int tileX,
int tileY,
Raster tile)
Adds a tile to the cache.
|
void |
add(RenderedImage owner,
int tileX,
int tileY,
Raster tile,
Object tileCacheMetric)
Adds a tile to the cache with an associated tile compute cost.
|
void |
addTiles(RenderedImage owner,
Point[] tileIndices,
Raster[] tiles,
Object tileCacheMetric)
Adds an array of tiles to the tile cache.
|
void |
disableDiagnostics()
Turn off diagnostic notification
|
void |
dump() |
void |
enableDiagnostics()
Enable Tile Monitoring and Diagnostics
|
void |
flush()
Removes -ALL- tiles from the cache.
|
Object |
getCachedObject() |
static javax.media.jai.EnumeratedParameter[] |
getCachedTileActions() |
long |
getCacheHitCount() |
long |
getCacheMemoryUsed() |
long |
getCacheMissCount() |
long |
getCacheTileCount() |
long |
getMemoryCapacity()
Returns the cache's memory capacity in bytes.
|
float |
getMemoryThreshold()
Returns the current
memoryThreshold . |
Raster |
getTile(RenderedImage owner,
int tileX,
int tileY)
Retrieves a tile from the cache.
|
int |
getTileCapacity()
Returns the cache's tile capacity.
|
Comparator |
getTileComparator()
Return the current comparator
|
Raster[] |
getTiles(RenderedImage owner)
Retrieves a contiguous array of all tiles in the cache which are
owned by the specified image.
|
Raster[] |
getTiles(RenderedImage owner,
Point[] tileIndices)
Returns an array of tile
Raster s from the cache. |
void |
memoryControl()
Removes tiles from the cache based on their last-access time
(old to new) until the memory usage is memoryThreshold % of that of the
memory capacity.
|
void |
remove(RenderedImage owner,
int tileX,
int tileY)
Removes a tile from the cache.
|
void |
removeTiles(RenderedImage owner)
Removes all the tiles that belong to a
RenderedImage
from the cache. |
void |
resetCounts()
Reset hit and miss counters.
|
void |
setMemoryCapacity(long memoryCapacity)
Sets the cache's memory capacity to the desired number of bytes.
|
void |
setMemoryThreshold(float mt)
Set the memory threshold value.
|
void |
setTileCapacity(int tileCapacity)
Sets the cache's tile capacity to the desired number of tiles.
|
void |
setTileComparator(Comparator c)
The
Comparator is used to produce an
ordered list of tiles based on a user defined
compute cost or priority metric. |
String |
toString()
Returns a string representation of the class object.
|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
public static final long DEFAULT_MEMORY_CAPACITY
public static final int DEFAULT_HASHTABLE_CAPACITY
public static final File DEFAULT_SWAP_DIR
public SwappingTileCache()
public SwappingTileCache(long memoryCapacity, SwapSpace swapSpace)
memoryCapacity
- The maximum cache memory size in bytes.swapSpace
- The space used to swap out tiles.IllegalArgumentException
- If memoryCapacity
is less than 0.public static javax.media.jai.EnumeratedParameter[] getCachedTileActions()
EnumeratedParameter
s corresponding
to the numeric values returned by the getAction()
method of the CachedTile
implementation used by
SunTileCache
. The "name" of each
EnumeratedParameter
provides a brief string
describing the numeric action value.public void add(RenderedImage owner, int tileX, int tileY, Raster tile)
If the specified tile is already in the cache, it will not be cached again. If by adding this tile, the cache exceeds the memory capacity, older tiles in the cache are removed to keep the cache memory usage under the specified limit.
add
in interface javax.media.jai.TileCache
owner
- The image the tile blongs to.tileX
- The tile's X index within the image.tileY
- The tile's Y index within the image.tile
- The tile to be cached.public void add(RenderedImage owner, int tileX, int tileY, Raster tile, Object tileCacheMetric)
If the specified tile is already in the cache, it will not be cached again. If by adding this tile, the cache exceeds the memory capacity, older tiles in the cache are removed to keep the cache memory usage under the specified limit.
add
in interface javax.media.jai.TileCache
owner
- The image the tile blongs to.tileX
- The tile's X index within the image.tileY
- The tile's Y index within the image.tile
- The tile to be cached.tileCacheMetric
- Metric for prioritizing tilespublic void addTiles(RenderedImage owner, Point[] tileIndices, Raster[] tiles, Object tileCacheMetric)
addTiles
in interface javax.media.jai.TileCache
owner
- The RenderedImage
that the tile belongs to.tileIndices
- An array of Point
s containing the
tileX
and tileY
indices for each tile.tiles
- The array of tile Raster
s containing tile data.tileCacheMetric
- Object which provides an ordering metric
associated with the RenderedImage
owner.public void remove(RenderedImage owner, int tileX, int tileY)
If the specified tile is not in the cache, this method does nothing.
remove
in interface javax.media.jai.TileCache
public void removeTiles(RenderedImage owner)
RenderedImage
from the cache.removeTiles
in interface javax.media.jai.TileCache
owner
- The image whose tiles are to be removed from the cache.public Raster getTile(RenderedImage owner, int tileX, int tileY)
If the specified tile is not in the cache, this method
returns null
. If the specified tile is in the
cache, its last-access time is updated.
getTile
in interface javax.media.jai.TileCache
owner
- The image the tile blongs to.tileX
- The tile's X index within the image.tileY
- The tile's Y index within the image.public Raster[] getTiles(RenderedImage owner)
null
if there
were no tiles in the cache. The array contains no null entries.getTiles
in interface javax.media.jai.TileCache
owner
- The RenderedImage
to which the tiles belong.null
if there are none currently in the cache.public Raster[] getTiles(RenderedImage owner, Point[] tileIndices)
Raster
s from the cache.
Any or all of the elements of the returned array may be null
if the corresponding tile is not in the cache.getTiles
in interface javax.media.jai.TileCache
owner
- The RenderedImage
that the tile belongs to.tileIndices
- An array of Point
s containing the
tileX
and tileY
indices for each tile.public void flush()
flush
in interface javax.media.jai.TileCache
public int getTileCapacity()
This implementation of TileCache
does not use
the tile capacity. This method always returns 0.
getTileCapacity
in interface javax.media.jai.TileCache
public void setTileCapacity(int tileCapacity)
This implementation of TileCache
does not use
the tile capacity. The cache size is limited by the memory
capacity only. This method does nothing and has no effect on
the cache.
setTileCapacity
in interface javax.media.jai.TileCache
tileCapacity
- The desired tile capacity for this cache
in number of tiles.public long getMemoryCapacity()
getMemoryCapacity
in interface javax.media.jai.TileCache
public void setMemoryCapacity(long memoryCapacity)
setMemoryCapacity
in interface javax.media.jai.TileCache
memoryCapacity
- The desired memory capacity for this cache
in bytes.IllegalArgumentException
- If memoryCapacity
is less than 0.public void enableDiagnostics()
enableDiagnostics
in interface com.sun.media.jai.util.CacheDiagnostics
public void disableDiagnostics()
disableDiagnostics
in interface com.sun.media.jai.util.CacheDiagnostics
public long getCacheTileCount()
getCacheTileCount
in interface com.sun.media.jai.util.CacheDiagnostics
public long getCacheMemoryUsed()
getCacheMemoryUsed
in interface com.sun.media.jai.util.CacheDiagnostics
public long getCacheHitCount()
getCacheHitCount
in interface com.sun.media.jai.util.CacheDiagnostics
public long getCacheMissCount()
getCacheMissCount
in interface com.sun.media.jai.util.CacheDiagnostics
public void resetCounts()
resetCounts
in interface com.sun.media.jai.util.CacheDiagnostics
public void setMemoryThreshold(float mt)
setMemoryThreshold
in interface javax.media.jai.TileCache
public float getMemoryThreshold()
memoryThreshold
.getMemoryThreshold
in interface javax.media.jai.TileCache
public String toString()
public Object getCachedObject()
Object
that represents the actual cache.public void memoryControl()
memoryControl
in interface javax.media.jai.TileCache
public void setTileComparator(Comparator c)
Comparator
is used to produce an
ordered list of tiles based on a user defined
compute cost or priority metric. This determines
which tiles are subject to "ordered" removal
during a memory control operation.setTileComparator
in interface javax.media.jai.TileCache
public Comparator getTileComparator()
getTileComparator
in interface javax.media.jai.TileCache
public void dump()
Copyright © 2014–2017 European Space Agency (ESA). All rights reserved.