Package org.eclipse.imagen.media.cache
Class ConcurrentTileCacheMultiMap
Object
Observable
ConcurrentTileCacheMultiMap
- All Implemented Interfaces:
CacheDiagnostics,TileCache
This implementation of the TileCache class uses a Guava Cache and a multimap in order to provide a better concurrency
handling. The first object contains all the cached tiles while the second one contains the mapping of the tile keys
for each image. This class implements
CacheDiagnostics in order to get the statistics associated to the
TileCache. The user can define the cache memory capacity, the concurrency level (which indicates in how many
segments the cache must be divided), the threshold of the total memory to use and a boolean indicating if the
diagnostic must be enabled.- Author:
- Nicola Lagomarsini GeoSolutions S.A.S.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default concurrency settingsstatic final booleanThe default diagnostic settingsstatic final longThe default memory capacity of the cache (16 MB).static final floatThe default memory threshold of the cache. -
Constructor Summary
ConstructorsConstructorDescriptionConcurrentTileCacheMultiMap(long memoryCacheCapacity, boolean diagnostic, float mem_threshold, int concurrencyLevel) -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(RenderedImage owner, int tileX, int tileY, Raster data) Add a new tile to the cachevoidadd(RenderedImage owner, int tileX, int tileY, Raster data, Object tileCacheMetric) Add a new tile to the cachevoidaddTiles(RenderedImage owner, Point[] tileIndices, Raster[] tiles, Object tileCacheMetric) Adds all tiles in the Point array which are owned by the image.voidDisables diagnosticEnabled for the observersvoidEnables diagnosticEnabled for the observersvoidflush()Removes all tiles present in the cache without checking for the image ownerlongRetrieves the hit count from the cache statisticslongRetrieves the current memory size of the cachelongRetrieves the miss count from the cache statisticslongRetrieves the number of tiles in the cacheintRetrieve the cache concurrency levellongRetrieve the cache memory capacityfloatRetrieve the cache memory thresholdgetTile(RenderedImage owner, int tileX, int tileY) Retrieves the selected tile from the cacheintNot SupportedNot SupportedRaster[]getTiles(RenderedImage owner) Retrieves an array of all tiles in the cache which are owned by the image.Raster[]getTiles(RenderedImage owner, Point[] tileIndices) Retrieves an array of tiles in the cache which are specified by the Point array and owned by the image.voidNot Supportedvoidremove(RenderedImage owner, int tileX, int tileY) Removes the selected tile from the cachevoidremoveTiles(RenderedImage owner) Removes all tiles in the cache which are owned by the image.voidNot SupportedvoidsetConcurrencyLevel(int concurrency) Sets the cache ConcurrencyLevel and then flush and rebuild the cachevoidsetMemoryCapacity(long memoryCacheCapacity) Sets the cache memory capacity and then flush and rebuild the cachevoidsetMemoryThreshold(float mt) Sets the cache memory threshold and then flush and rebuild the cachevoidsetTileCapacity(int tileCapacity) Not SupportedvoidsetTileComparator(Comparator comparator) Not SupportedMethods inherited from class Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
-
Field Details
-
DEFAULT_MEMORY_THRESHOLD
public static final float DEFAULT_MEMORY_THRESHOLDThe default memory threshold of the cache.- See Also:
-
DEFAULT_MEMORY_CACHE
public static final long DEFAULT_MEMORY_CACHEThe default memory capacity of the cache (16 MB).- See Also:
-
DEFAULT_DIAGNOSTIC
public static final boolean DEFAULT_DIAGNOSTICThe default diagnostic settings- See Also:
-
DEFAULT_CONCURRENCY_LEVEL
public static final int DEFAULT_CONCURRENCY_LEVELThe default concurrency settings- See Also:
-
-
Constructor Details
-
ConcurrentTileCacheMultiMap
public ConcurrentTileCacheMultiMap() -
ConcurrentTileCacheMultiMap
public ConcurrentTileCacheMultiMap(long memoryCacheCapacity, boolean diagnostic, float mem_threshold, int concurrencyLevel)
-
-
Method Details
-
add
Add a new tile to the cache -
add
Add a new tile to the cache- Specified by:
addin interfaceTileCache- 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
Removes the selected tile from the cache -
getTile
Retrieves the selected tile from the cache -
getTiles
Retrieves an array of all tiles in the cache which are owned by the image. May benullif there were no tiles in the cache. The array contains no null entries. -
removeTiles
Removes all tiles in the cache which are owned by the image.- Specified by:
removeTilesin interfaceTileCache- Parameters:
owner- TheRenderedImageowner of the tiles to be removed.
-
addTiles
public void addTiles(RenderedImage owner, Point[] tileIndices, Raster[] tiles, Object tileCacheMetric) Adds all tiles in the Point array which are owned by the image.- Specified by:
addTilesin interfaceTileCache- 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
Retrieves an array of tiles in the cache which are specified by the Point array and owned by the image. May benullif there were not in the cache. The array contains null entries. -
flush
public void flush()Removes all tiles present in the cache without checking for the image owner -
memoryControl
public void memoryControl()Not Supported- Specified by:
memoryControlin interfaceTileCache- Throws:
UnsupportedOperationException
-
setTileCapacity
public void setTileCapacity(int tileCapacity) Not Supported- Specified by:
setTileCapacityin interfaceTileCache- Parameters:
tileCapacity- The new capacity, in tiles.- Throws:
UnsupportedOperationException
-
getTileCapacity
public int getTileCapacity()Not Supported- Specified by:
getTileCapacityin interfaceTileCache- Throws:
UnsupportedOperationException
-
setMemoryCapacity
public void setMemoryCapacity(long memoryCacheCapacity) Sets the cache memory capacity and then flush and rebuild the cache- Specified by:
setMemoryCapacityin interfaceTileCache- Parameters:
memoryCacheCapacity- The new capacity, in bytes.
-
getMemoryCapacity
public long getMemoryCapacity()Retrieve the cache memory capacity- Specified by:
getMemoryCapacityin interfaceTileCache
-
setMemoryThreshold
public void setMemoryThreshold(float mt) Sets the cache memory threshold and then flush and rebuild the cache- Specified by:
setMemoryThresholdin interfaceTileCache- Parameters:
mt- . Retained fraction of memory
-
getMemoryThreshold
public float getMemoryThreshold()Retrieve the cache memory threshold- Specified by:
getMemoryThresholdin interfaceTileCache
-
setConcurrencyLevel
public void setConcurrencyLevel(int concurrency) Sets the cache ConcurrencyLevel and then flush and rebuild the cache -
getConcurrencyLevel
public int getConcurrencyLevel()Retrieve the cache concurrency level -
setTileComparator
Not Supported- Specified by:
setTileComparatorin interfaceTileCache- Parameters:
comparator- AComparatorwhich orders theCachedTiles stored by theTileCache; ifnullan implementation-dependent algorithm will be used.- Throws:
UnsupportedOperationException
-
getTileComparator
Not Supported- Specified by:
getTileComparatorin interfaceTileCache- Returns:
- The tile
Comparatorornullif the implementation-dependent ordering algorithm is being used. - Throws:
UnsupportedOperationException
-
disableDiagnostics
public void disableDiagnostics()Disables diagnosticEnabled for the observers- Specified by:
disableDiagnosticsin interfaceCacheDiagnostics
-
enableDiagnostics
public void enableDiagnostics()Enables diagnosticEnabled for the observers- Specified by:
enableDiagnosticsin interfaceCacheDiagnostics
-
getCacheHitCount
public long getCacheHitCount()Retrieves the hit count from the cache statistics- Specified by:
getCacheHitCountin interfaceCacheDiagnostics
-
getCacheMemoryUsed
public long getCacheMemoryUsed()Retrieves the current memory size of the cache- Specified by:
getCacheMemoryUsedin interfaceCacheDiagnostics
-
getCacheMissCount
public long getCacheMissCount()Retrieves the miss count from the cache statistics- Specified by:
getCacheMissCountin interfaceCacheDiagnostics
-
getCacheTileCount
public long getCacheTileCount()Retrieves the number of tiles in the cache- Specified by:
getCacheTileCountin interfaceCacheDiagnostics
-
resetCounts
public void resetCounts()Not Supported- Specified by:
resetCountsin interfaceCacheDiagnostics- Throws:
UnsupportedOperationException
-