Interface TileCache
- All Known Implementing Classes:
ConcurrentTileCache,ConcurrentTileCacheMultiMap,SunTileCache
TileCache provides a mechanism by which an OpImage may cache its computed tiles. There
may be multiple TileCaches used in an application up to the point of having a different TileCache
for each OpImage.
The TileCache used for a particular OpImage is derived from the RenderingHints
assigned to the associated imaging chain node. If the node is constructed using ImageN.create()
and no TileCache is specified in the RenderingHints parameter, then one is derived from the
RenderingHints associated with the instance of the ImageN class being used.
In the Sun reference implementation, the cache size is limited by the memory capacity, which is set to a default
value at construction or subsequently using the setMemoryCapacity() method. The initial value may be
obtained using getMemoryCapacity(). The tile capacity is not used as different images may have very
different tile sizes so that this metric is not a particularly meaningful control of memory resource consumption in
general.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidadd(RenderedImage owner, int tileX, int tileY, Raster data) Adds a tile to the cache.voidadd(RenderedImage owner, int tileX, int tileY, Raster data, Object tileCacheMetric) Adds a tile to the cache with an associated compute costvoidaddTiles(RenderedImage owner, Point[] tileIndices, Raster[] tiles, Object tileCacheMetric) Adds an array of tiles to the tile cache.voidflush()Advises the cache that all of its tiles may be discarded.longReturns the memory capacity in bytes.floatReturns the memory threshold, which is the fractional amount of cache memory to retain during tile removal.getTile(RenderedImage owner, int tileX, int tileY) Retrieves a tile.intDeprecated.as of ImageN 0.4.0.Returns theComparatorcurrently set for use in ordering theCachedTiles stored by theTileCache.Raster[]getTiles(RenderedImage owner) Retrieves an array of all tiles in the cache which are owned by the specified image.Raster[]getTiles(RenderedImage owner, Point[] tileIndices) Returns an array of tileRasters from the cache.voidAdvises the cache that some of its tiles may be discarded.voidremove(RenderedImage owner, int tileX, int tileY) Advises the cache that a tile is no longer needed.voidremoveTiles(RenderedImage owner) Advises the cache that all tiles associated with a given image are no longer needed.voidsetMemoryCapacity(long memoryCapacity) Sets the memory capacity to a desired number of bytes.voidsetMemoryThreshold(float memoryThreshold) Sets thememoryThresholdvalue to a floating point number that ranges from 0.0 to 1.0.voidsetTileCapacity(int tileCapacity) Deprecated.as of ImageN 0.4.0.voidsetTileComparator(Comparator comparator) Sets aComparatorwhich imposes an order on theCachedTiles stored in theTileCache.
-
Method Details
-
add
Adds a tile to the cache.- Parameters:
owner- TheRenderedImagethat the tile belongs to.tileX- The X index of the tile in the owner's tile grid.tileY- The Y index of the tile in the owner's tile grid.data- ARastercontaining the tile data.
-
add
Adds a tile to the cache with an associated compute cost- Parameters:
owner- TheRenderedImagethat the tile belongs to.tileX- The X index of the tile in the owner's tile grid.tileY- The Y index of the tile in the owner's tile grid.data- ARastercontaining the tile data.tileCacheMetric- AnObjectas a tile metric.
-
remove
Advises the cache that a tile is no longer needed. It is legal to implement this method as a no-op.- Parameters:
owner- TheRenderedImagethat the tile belongs to.tileX- The X index of the tile in the owner's tile grid.tileY- The Y index of the tile in the owner's tile grid.
-
getTile
Retrieves a tile. Returnsnullif the tile is not present in the cache.- Parameters:
owner- TheRenderedImagethat the tile belongs to.tileX- The X index of the tile in the owner's tile grid.tileY- The Y index of the tile in the owner's tile grid.
-
getTiles
Retrieves an array of all tiles in the cache which are owned by the specified image.- Parameters:
owner- TheRenderedImageto which the tiles belong.- Returns:
- An array of all tiles owned by the specified image or
nullif there are none currently in the cache.
-
removeTiles
Advises the cache that all tiles associated with a given image are no longer needed. It is legal to implement this method as a no-op.- Parameters:
owner- TheRenderedImageowner of the tiles to be removed.
-
addTiles
Adds an array of tiles to the tile cache.- Parameters:
owner- TheRenderedImagethat the tile belongs to.tileIndices- An array ofPoints containing thetileXandtileYindices for each tile.tiles- The array of tileRasters containing tile data.tileCacheMetric- Object which provides an ordering metric associated with theRenderedImageowner.
-
getTiles
Returns an array of tileRasters from the cache. Any or all of the elements of the returned array may benullif the corresponding tile is not in the cache. The length of the returned array must be the same as that of the parameter array and the ithRasterin the returned array must correspond to the ith tile index in the parameter array.- Parameters:
owner- TheRenderedImagethat the tile belongs to.tileIndices- An array ofPoints containing thetileXandtileYindices for each tile.
-
flush
void flush()Advises the cache that all of its tiles may be discarded. It is legal to implement this method as a no-op. -
memoryControl
void memoryControl()Advises the cache that some of its tiles may be discarded. It is legal to implement this method as a no-op. -
setTileCapacity
void setTileCapacity(int tileCapacity) Deprecated.as of ImageN 0.4.0.Sets the tile capacity to a desired number of tiles. If the capacity is smaller than the current capacity, tiles are flushed from the cache. It is legal to implement this method as a no-op.- Parameters:
tileCapacity- The new capacity, in tiles.
-
getTileCapacity
int getTileCapacity()Deprecated.as of ImageN 0.4.0.Returns the tile capacity in tiles. It is legal to implement this method as a no-op which should be signaled by returning zero. -
setMemoryCapacity
void setMemoryCapacity(long memoryCapacity) Sets the memory capacity to a desired number of bytes. If the memory capacity is smaller than the amount of memory currently used by the cache, tiles are flushed until theTileCache's memory usage is less thanmemoryCapacity.- Parameters:
memoryCapacity- The new capacity, in bytes.
-
getMemoryCapacity
long getMemoryCapacity()Returns the memory capacity in bytes. -
setMemoryThreshold
void setMemoryThreshold(float memoryThreshold) Sets thememoryThresholdvalue to a floating point number that ranges from 0.0 to 1.0. When the cache memory is full, the memory usage will be reduced to this fraction of the total cache memory capacity. For example, a value of .75 will cause 25% of the memory to be cleared, while retaining 75%.- Parameters:
memoryThreshold- . Retained fraction of memory- Throws:
IllegalArgumentException- if the memoryThreshold is less than 0.0 or greater than 1.0
-
getMemoryThreshold
float getMemoryThreshold()Returns the memory threshold, which is the fractional amount of cache memory to retain during tile removal. -
setTileComparator
Sets aComparatorwhich imposes an order on theCachedTiles stored in theTileCache. This ordering is used inmemoryControl()to determine the sequence in which tiles will be removed from theTileCacheso as to reduce the memory to the level given by the memory threshold. TheObjects passed to thecompare()method of theComparatorwill be instances ofCachedTile.CachedTiles will be removed from theTileCachein the ascending order imposed by thisComparator. If noComparatoris currently set, theTileCacheshould use an implementation-dependent default ordering. In the Sun Microsystems, Inc., implementation ofTileCache, this ordering is the least recently used ordering, i.e., the tiles least recently used will be removed first bymemoryControl().- Parameters:
comparator- AComparatorwhich orders theCachedTiles stored by theTileCache; ifnullan implementation-dependent algorithm will be used.
-
getTileComparator
Comparator getTileComparator()Returns theComparatorcurrently set for use in ordering theCachedTiles stored by theTileCache.- Returns:
- The tile
Comparatorornullif the implementation-dependent ordering algorithm is being used.
-