it.geosolutions.concurrent
Class ConcurrentTileCacheMultiMap

java.lang.Object
  extended by java.util.Observable
      extended by it.geosolutions.concurrent.ConcurrentTileCacheMultiMap
All Implemented Interfaces:
com.sun.media.jai.util.CacheDiagnostics, javax.media.jai.TileCache

public class ConcurrentTileCacheMultiMap
extends Observable
implements javax.media.jai.TileCache, com.sun.media.jai.util.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 Summary
static int DEFAULT_CONCURRENCY_LEVEL
          The default concurrency settings
static boolean DEFAULT_DIAGNOSTIC
          The default diagnostic settings
static long DEFAULT_MEMORY_CACHE
          The default memory capacity of the cache (16 MB).
static float DEFAULT_MEMORY_THRESHOLD
          The default memory threshold of the cache.
 
Constructor Summary
ConcurrentTileCacheMultiMap()
           
ConcurrentTileCacheMultiMap(long memoryCacheCapacity, boolean diagnostic, float mem_threshold, int concurrencyLevel)
           
 
Method Summary
 void add(RenderedImage owner, int tileX, int tileY, Raster data)
          Add a new tile to the cache
 void add(RenderedImage owner, int tileX, int tileY, Raster data, Object tileCacheMetric)
          Add a new tile to the cache
 void addTiles(RenderedImage owner, Point[] tileIndices, Raster[] tiles, Object tileCacheMetric)
          Adds all tiles in the Point array which are owned by the image.
 void disableDiagnostics()
          Disables diagnosticEnabled for the observers
 void enableDiagnostics()
          Enables diagnosticEnabled for the observers
 void flush()
          Removes all tiles present in the cache without checking for the image owner
 long getCacheHitCount()
          Retrieves the hit count from the cache statistics
 long getCacheMemoryUsed()
          Retrieves the current memory size of the cache
 long getCacheMissCount()
          Retrieves the miss count from the cache statistics
 long getCacheTileCount()
          Retrieves the number of tiles in the cache
 int getConcurrencyLevel()
          Retrieve the cache concurrency level
 long getMemoryCapacity()
          Retrieve the cache memory capacity
 float getMemoryThreshold()
          Retrieve the cache memory threshold
 Raster getTile(RenderedImage owner, int tileX, int tileY)
          Retrieves the selected tile from the cache
 int getTileCapacity()
          Not Supported
 Comparator getTileComparator()
          Not Supported
 Raster[] 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.
 void memoryControl()
          Not Supported
 void remove(RenderedImage owner, int tileX, int tileY)
          Removes the selected tile from the cache
 void removeTiles(RenderedImage owner)
          Removes all tiles in the cache which are owned by the image.
 void resetCounts()
          Not Supported
 void setConcurrencyLevel(int concurrency)
          Sets the cache ConcurrencyLevel and then flush and rebuild the cache
 void setMemoryCapacity(long memoryCacheCapacity)
          Sets the cache memory capacity and then flush and rebuild the cache
 void setMemoryThreshold(float mt)
          Sets the cache memory threshold and then flush and rebuild the cache
 void setTileCapacity(int tileCapacity)
          Not Supported
 void setTileComparator(Comparator comparator)
          Not Supported
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MEMORY_THRESHOLD

public static final float DEFAULT_MEMORY_THRESHOLD
The default memory threshold of the cache.

See Also:
Constant Field Values

DEFAULT_MEMORY_CACHE

public static final long DEFAULT_MEMORY_CACHE
The default memory capacity of the cache (16 MB).

See Also:
Constant Field Values

DEFAULT_DIAGNOSTIC

public static final boolean DEFAULT_DIAGNOSTIC
The default diagnostic settings

See Also:
Constant Field Values

DEFAULT_CONCURRENCY_LEVEL

public static final int DEFAULT_CONCURRENCY_LEVEL
The default concurrency settings

See Also:
Constant Field Values
Constructor Detail

ConcurrentTileCacheMultiMap

public ConcurrentTileCacheMultiMap()

ConcurrentTileCacheMultiMap

public ConcurrentTileCacheMultiMap(long memoryCacheCapacity,
                                   boolean diagnostic,
                                   float mem_threshold,
                                   int concurrencyLevel)
Method Detail

add

public void add(RenderedImage owner,
                int tileX,
                int tileY,
                Raster data)
Add a new tile to the cache

Specified by:
add in interface javax.media.jai.TileCache

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 javax.media.jai.TileCache

remove

public void remove(RenderedImage owner,
                   int tileX,
                   int tileY)
Removes the selected tile from the cache

Specified by:
remove in interface javax.media.jai.TileCache

getTile

public Raster getTile(RenderedImage owner,
                      int tileX,
                      int tileY)
Retrieves the selected tile from the cache

Specified by:
getTile in interface javax.media.jai.TileCache

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 javax.media.jai.TileCache

removeTiles

public void removeTiles(RenderedImage owner)
Removes all tiles in the cache which are owned by the image.

Specified by:
removeTiles in interface javax.media.jai.TileCache

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 javax.media.jai.TileCache

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 javax.media.jai.TileCache

flush

public void flush()
Removes all tiles present in the cache without checking for the image owner

Specified by:
flush in interface javax.media.jai.TileCache

memoryControl

public void memoryControl()
Not Supported

Specified by:
memoryControl in interface javax.media.jai.TileCache
Throws:
UnsupportedOperationException

setTileCapacity

public void setTileCapacity(int tileCapacity)
Not Supported

Specified by:
setTileCapacity in interface javax.media.jai.TileCache
Throws:
UnsupportedOperationException

getTileCapacity

public int getTileCapacity()
Not Supported

Specified by:
getTileCapacity in interface javax.media.jai.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 javax.media.jai.TileCache

getMemoryCapacity

public long getMemoryCapacity()
Retrieve the cache memory capacity

Specified by:
getMemoryCapacity in interface javax.media.jai.TileCache

setMemoryThreshold

public void setMemoryThreshold(float mt)
Sets the cache memory threshold and then flush and rebuild the cache

Specified by:
setMemoryThreshold in interface javax.media.jai.TileCache

getMemoryThreshold

public float getMemoryThreshold()
Retrieve the cache memory threshold

Specified by:
getMemoryThreshold in interface javax.media.jai.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 javax.media.jai.TileCache
Throws:
UnsupportedOperationException

getTileComparator

public Comparator getTileComparator()
Not Supported

Specified by:
getTileComparator in interface javax.media.jai.TileCache
Throws:
UnsupportedOperationException

disableDiagnostics

public void disableDiagnostics()
Disables diagnosticEnabled for the observers

Specified by:
disableDiagnostics in interface com.sun.media.jai.util.CacheDiagnostics

enableDiagnostics

public void enableDiagnostics()
Enables diagnosticEnabled for the observers

Specified by:
enableDiagnostics in interface com.sun.media.jai.util.CacheDiagnostics

getCacheHitCount

public long getCacheHitCount()
Retrieves the hit count from the cache statistics

Specified by:
getCacheHitCount in interface com.sun.media.jai.util.CacheDiagnostics

getCacheMemoryUsed

public long getCacheMemoryUsed()
Retrieves the current memory size of the cache

Specified by:
getCacheMemoryUsed in interface com.sun.media.jai.util.CacheDiagnostics

getCacheMissCount

public long getCacheMissCount()
Retrieves the miss count from the cache statistics

Specified by:
getCacheMissCount in interface com.sun.media.jai.util.CacheDiagnostics

getCacheTileCount

public long getCacheTileCount()
Retrieves the number of tiles in the cache

Specified by:
getCacheTileCount in interface com.sun.media.jai.util.CacheDiagnostics

resetCounts

public void resetCounts()
Not Supported

Specified by:
resetCounts in interface com.sun.media.jai.util.CacheDiagnostics
Throws:
UnsupportedOperationException


Copyright © 2006–2014 GeoSolutions. All rights reserved.