Class ConcurrentTileCacheMultiMap

Object
Observable
ConcurrentTileCacheMultiMap
All Implemented Interfaces:
CacheDiagnostics, TileCache

public class ConcurrentTileCacheMultiMap extends Observable implements TileCache, CacheDiagnostics
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 Details

    • DEFAULT_MEMORY_THRESHOLD

      public static final float DEFAULT_MEMORY_THRESHOLD
      The default memory threshold of the cache.
      See Also:
    • DEFAULT_MEMORY_CACHE

      public static final long DEFAULT_MEMORY_CACHE
      The default memory capacity of the cache (16 MB).
      See Also:
    • DEFAULT_DIAGNOSTIC

      public static final boolean DEFAULT_DIAGNOSTIC
      The default diagnostic settings
      See Also:
    • DEFAULT_CONCURRENCY_LEVEL

      public static final int DEFAULT_CONCURRENCY_LEVEL
      The 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

      public void add(RenderedImage owner, int tileX, int tileY, Raster data)
      Add a new tile to the cache
      Specified by:
      add in interface TileCache
      Parameters:
      owner - The RenderedImage that 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 - A Raster containing the tile data.
    • add

      public void add(RenderedImage owner, int tileX, int tileY, Raster data, Object tileCacheMetric)
      Add a new tile to the cache
      Specified by:
      add in interface TileCache
      Parameters:
      owner - The RenderedImage that 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 - A Raster containing the tile data.
      tileCacheMetric - An Object as a tile metric.
    • remove

      public void remove(RenderedImage owner, int tileX, int tileY)
      Removes the selected tile from the cache
      Specified by:
      remove in interface TileCache
      Parameters:
      owner - The RenderedImage that 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

      public Raster getTile(RenderedImage owner, int tileX, int tileY)
      Retrieves the selected tile from the cache
      Specified by:
      getTile in interface TileCache
      Parameters:
      owner - The RenderedImage that 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

      public Raster[] getTiles(RenderedImage owner)
      Retrieves an array of all tiles in the cache which are owned by the image. May be null if there were no tiles in the cache. The array contains no null entries.
      Specified by:
      getTiles in interface TileCache
      Parameters:
      owner - The RenderedImage to which the tiles belong.
      Returns:
      An array of all tiles owned by the specified image or null if there are none currently in the cache.
    • removeTiles

      public void removeTiles(RenderedImage owner)
      Removes all tiles in the cache which are owned by the image.
      Specified by:
      removeTiles in interface TileCache
      Parameters:
      owner - The RenderedImage owner 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:
      addTiles in interface TileCache
      Parameters:
      owner - The RenderedImage that the tile belongs to.
      tileIndices - An array of Points containing the tileX and tileY indices for each tile.
      tiles - The array of tile Rasters containing tile data.
      tileCacheMetric - Object which provides an ordering metric associated with the RenderedImage owner.
    • getTiles

      public 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. May be null if there were not in the cache. The array contains null entries.
      Specified by:
      getTiles in interface TileCache
      Parameters:
      owner - The RenderedImage that the tile belongs to.
      tileIndices - An array of Points containing the tileX and tileY indices for each tile.
    • flush

      public void flush()
      Removes all tiles present in the cache without checking for the image owner
      Specified by:
      flush in interface TileCache
    • memoryControl

      public void memoryControl()
      Not Supported
      Specified by:
      memoryControl in interface TileCache
      Throws:
      UnsupportedOperationException
    • setTileCapacity

      public void setTileCapacity(int tileCapacity)
      Not Supported
      Specified by:
      setTileCapacity in interface TileCache
      Parameters:
      tileCapacity - The new capacity, in tiles.
      Throws:
      UnsupportedOperationException
    • getTileCapacity

      public int getTileCapacity()
      Not Supported
      Specified by:
      getTileCapacity in interface TileCache
      Throws:
      UnsupportedOperationException
    • setMemoryCapacity

      public void setMemoryCapacity(long memoryCacheCapacity)
      Sets the cache memory capacity and then flush and rebuild the cache
      Specified by:
      setMemoryCapacity in interface TileCache
      Parameters:
      memoryCacheCapacity - The new capacity, in bytes.
    • getMemoryCapacity

      public long getMemoryCapacity()
      Retrieve the cache memory capacity
      Specified by:
      getMemoryCapacity in interface TileCache
    • setMemoryThreshold

      public void setMemoryThreshold(float mt)
      Sets the cache memory threshold and then flush and rebuild the cache
      Specified by:
      setMemoryThreshold in interface TileCache
      Parameters:
      mt - . Retained fraction of memory
    • getMemoryThreshold

      public float getMemoryThreshold()
      Retrieve the cache memory threshold
      Specified by:
      getMemoryThreshold in interface TileCache
    • 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

      public void setTileComparator(Comparator comparator)
      Not Supported
      Specified by:
      setTileComparator in interface TileCache
      Parameters:
      comparator - A Comparator which orders the CachedTiles stored by the TileCache; if null an implementation-dependent algorithm will be used.
      Throws:
      UnsupportedOperationException
    • getTileComparator

      public Comparator getTileComparator()
      Not Supported
      Specified by:
      getTileComparator in interface TileCache
      Returns:
      The tile Comparator or null if the implementation-dependent ordering algorithm is being used.
      Throws:
      UnsupportedOperationException
    • disableDiagnostics

      public void disableDiagnostics()
      Disables diagnosticEnabled for the observers
      Specified by:
      disableDiagnostics in interface CacheDiagnostics
    • enableDiagnostics

      public void enableDiagnostics()
      Enables diagnosticEnabled for the observers
      Specified by:
      enableDiagnostics in interface CacheDiagnostics
    • getCacheHitCount

      public long getCacheHitCount()
      Retrieves the hit count from the cache statistics
      Specified by:
      getCacheHitCount in interface CacheDiagnostics
    • getCacheMemoryUsed

      public long getCacheMemoryUsed()
      Retrieves the current memory size of the cache
      Specified by:
      getCacheMemoryUsed in interface CacheDiagnostics
    • getCacheMissCount

      public long getCacheMissCount()
      Retrieves the miss count from the cache statistics
      Specified by:
      getCacheMissCount in interface CacheDiagnostics
    • getCacheTileCount

      public long getCacheTileCount()
      Retrieves the number of tiles in the cache
      Specified by:
      getCacheTileCount in interface CacheDiagnostics
    • resetCounts

      public void resetCounts()
      Not Supported
      Specified by:
      resetCounts in interface CacheDiagnostics
      Throws:
      UnsupportedOperationException