deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

org.deegree.coverage.raster.cache
Class RasterCache

java.lang.Object
  extended by org.deegree.coverage.raster.cache.RasterCache

public class RasterCache
extends Object

The RasterCache holds references CacheRasterReader which wrap other RasterReaders. This Cache can have multiple directories for storing cache files. If a new Raster should be created it is recommended to call the freeMemory(long) method first, so all data which was less recently used will be written to file.

Version:
$Revision: 22265 $, $Date: 2010-01-27 18:01:36 +0100 (Mi, 27 Jan 2010) $
Author:
Rutger Bezema, last edited by: $Author: rbezema $

Nested Class Summary
(package private) static class RasterCache.CacheComparator
          The CacheComparator class compares two raster readers for their last read access time.
 
Field Summary
static String DEF_RASTER_CACHE
          A key which can be given to the JVM to define the amount of memory used for caching.
static File DEFAULT_CACHE_DIR
          Default cache dir if no directory was given.
static String FILE_EXTENSION
          Standard name for a deegree cache file.
 
Method Summary
 RasterReader addReader(RasterReader reader)
          Adds a raster reader to this cache, all cache files will be written to this cache directory.
static void clear()
          Writes all data the files and removes all readers from the cache.
 File createCacheFile(String id)
          Creates a unique cachefile for the given id, if the id already exists in the cache directory an index will be appended. if the given id is null a uuid will be used, this file will be marked to be deleted on exit.
 SimpleRaster createFromCache(RasterReader reader, String rasterId)
          Tries to find the file with given id from the current cache directory and instantiates a cachedraster for it.
static void dispose()
          Iterates over all current cache directories and calls dispose on their cache files.
static void flush()
          Writes all current caches to their cache files, but leaves the in memory cached rasters alone.
static long freeMemory(long requiredMemory)
          Signals the cache to write as much data to cache files so that the memory occupied by rasters can be returned to running process.
 File getCacheDirectory()
           
static RasterCache getInstance()
          Gets an instance of a data cache which uses the default directory as the cache directory.
static RasterCache getInstance(File directory, boolean create)
          Gets an instance of a data cache which uses the given directory as the cache directory.
static RasterCache getInstance(RasterIOOptions options)
          Gets an instance of a data cache which uses the given options to instantiate a cache.
static long getMaximumCacheMemory()
           
static void updateCurrentlyUsedMemory()
          Iterates over all known readers and (re) calculates their in memory data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CACHE_DIR

public static final File DEFAULT_CACHE_DIR
Default cache dir if no directory was given.


DEF_RASTER_CACHE

public static final String DEF_RASTER_CACHE
A key which can be given to the JVM to define the amount of memory used for caching.

See Also:
Constant Field Values

FILE_EXTENSION

public static final String FILE_EXTENSION
Standard name for a deegree cache file.

See Also:
Constant Field Values
Method Detail

addReader

public RasterReader addReader(RasterReader reader)
Adds a raster reader to this cache, all cache files will be written to this cache directory.

Parameters:
reader - to add to the cache.
Returns:
a new CachedReader which was added to the cache.

clear

public static void clear()
Writes all data the files and removes all readers from the cache.


getInstance

public static RasterCache getInstance(File directory,
                                      boolean create)
Gets an instance of a data cache which uses the given directory as the cache directory.

Parameters:
directory -
create - true if the directory should be created if missing.
Returns:
a raster cache for the given directory.

getInstance

public static RasterCache getInstance(RasterIOOptions options)
Gets an instance of a data cache which uses the given options to instantiate a cache. Currently following RasterIOOptions keys are evaluated. If the options are null the DEFAULT_CACHE_DIR will be used.

Parameters:
options - which can contain cache information.
Returns:
a raster cache for the given directory.

getInstance

public static RasterCache getInstance()
Gets an instance of a data cache which uses the default directory as the cache directory.

Returns:
a raster cache for the default directory.

updateCurrentlyUsedMemory

public static void updateCurrentlyUsedMemory()
Iterates over all known readers and (re) calculates their in memory data.


freeMemory

public static long freeMemory(long requiredMemory)
Signals the cache to write as much data to cache files so that the memory occupied by rasters can be returned to running process. Note this method does not actually write the cache files, it merely signals the CacheRasterReaders to write their data to file if they have a file to write to. It may well be that the required memory can not be freed.

Parameters:
requiredMemory - some process may need.
Returns:
the amount of currently used cache memory, which is only an approximation.

createCacheFile

public final File createCacheFile(String id)
Creates a unique cachefile for the given id, if the id already exists in the cache directory an index will be appended. if the given id is null a uuid will be used, this file will be marked to be deleted on exit.

Parameters:
id - to be used for the identification for the cache file.
Returns:
a unique file name based on the given id.

flush

public static void flush()
Writes all current caches to their cache files, but leaves the in memory cached rasters alone.


createFromCache

public SimpleRaster createFromCache(RasterReader reader,
                                    String rasterId)
Tries to find the file with given id from the current cache directory and instantiates a cachedraster for it.

Parameters:
reader - to be used for reading the original data, if parts of the cachefile are incoherent
rasterId - the id of the raster if null no raster cache file will be created.
Returns:
the raster created from the cache or null if no cache file with given id was found.

getMaximumCacheMemory

public static long getMaximumCacheMemory()
Returns:
the maximum allowed in memory cache size in bytes.

dispose

public static void dispose()
Iterates over all current cache directories and calls dispose on their cache files.


getCacheDirectory

public File getCacheDirectory()
Returns:
the directory used for caching.

deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org

]]>