visad.data
Class DataCacheManager
- java.lang.Object
-
- visad.data.DataCacheManager
-
- All Implemented Interfaces:
- java.lang.Runnable
public class DataCacheManager extends java.lang.Object implements java.lang.RunnableThis provides a global cache for primitive array data You access it via the singelton:DataCacheManager.getCacheManager()Client objects can store their data with:Object cacheId = DataCacheManager.getCacheManager().addToCache(theData);
Where data can be 1D or 2D byte/float/int/double arrays If the data changes then update the cache with:DataCacheManager.getCacheManager().updateData(cacheId, newData);When the client object is finalized or is finished with the data call:DataCacheManager.getCacheManager().removeFromCache(cacheId);When you want to access the data use one of:DataCacheManager.getCacheManager().getByteArray1D(cacheId); DataCacheManager.getCacheManager().getByteArray2D(cacheId); DataCacheManager.getCacheManager().getFloatArray1D(cacheId); DataCacheManager.getCacheManager().getFloatArray2D(cacheId); DataCacheManager.getCacheManager().getShortArray1D(cacheId); DataCacheManager.getCacheManager().getShortArray2D(cacheId); DataCacheManager.getCacheManager().getIntArray1D(cacheId); DataCacheManager.getCacheManager().getIntArray2D(cacheId); DataCacheManager.getCacheManager().getDoubleArray1D(cacheId); DataCacheManager.getCacheManager().getDoubleArray2D(cacheId);The cachemanager will keep the data arrays in memory until the total size is greater than getMaxSize(). Then it will serialize the data arrays in a least recently used manner until the totalSize less than the max size.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.lang.ObjectaddToCache(byte[] values)add the data to the cachejava.lang.ObjectaddToCache(byte[][] values)add the data to the cachejava.lang.ObjectaddToCache(byte[][][] values)add the data to the cachejava.lang.ObjectaddToCache(double[] values)add the data to the cachejava.lang.ObjectaddToCache(double[][] values)add the data to the cachejava.lang.ObjectaddToCache(double[][][] values)add the data to the cachejava.lang.ObjectaddToCache(float[] values)add the data to the cachejava.lang.ObjectaddToCache(float[][] values)add the data to the cachejava.lang.ObjectaddToCache(float[][][] values)add the data to the cachejava.lang.ObjectaddToCache(int[] values)add the data to the cachejava.lang.ObjectaddToCache(int[][] values)add the data to the cachejava.lang.ObjectaddToCache(int[][][] values)add the data to the cachejava.lang.ObjectaddToCache(short[] values)add the data to the cachejava.lang.ObjectaddToCache(short[][] values)add the data to the cachejava.lang.ObjectaddToCache(short[][][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, byte[] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, byte[][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, byte[][][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, byte[][][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, byte[][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, byte[] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, double[] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, double[][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, double[][][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, double[][][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, double[][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, double[] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, float[] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, float[][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, float[][][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, float[][][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, float[][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, float[] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, int[] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, int[][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, int[][][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, int[][][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, int[][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, int[] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, short[] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, short[][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, short[][][] values)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, short[][][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, short[][] values, boolean removeIfNeeded)add the data to the cachejava.lang.ObjectaddToCache(java.lang.String what, short[] values, boolean removeIfNeeded)add the data to the cachevoidcheckCache()Check if we are above the max size.voidflushAllCachedData()byte[]getByteArray1D(java.lang.Object cacheId)get the value from the cachebyte[][]getByteArray2D(java.lang.Object cacheId)get the value from the cachebyte[][][]getByteArray3D(java.lang.Object cacheId)get the value from the cachejava.io.FilegetCacheDir()get the cache dir.java.io.FilegetCacheFile()static DataCacheManagergetCacheManager()The singleton accessdouble[]getDoubleArray1D(java.lang.Object cacheId)get the value from the cachedouble[][]getDoubleArray2D(java.lang.Object cacheId)get the value from the cachedouble[][][]getDoubleArray3D(java.lang.Object cacheId)get the value from the cachefloat[]getFloatArray1D(java.lang.Object cacheId)get the value from the cachefloat[][]getFloatArray2D(java.lang.Object cacheId)get the value from the cachefloat[][][]getFloatArray3D(java.lang.Object cacheId)get the value from the cachejava.lang.ObjectgetId()Get a unique idint[]getIntArray1D(java.lang.Object cacheId)get the value from the cacheint[][]getIntArray2D(java.lang.Object cacheId)get the value from the cacheint[][][]getIntArray3D(java.lang.Object cacheId)get the value from the cacheintgetMaxSize()short[]getShortArray1D(java.lang.Object cacheId)get the value from the cacheshort[][]getShortArray2D(java.lang.Object cacheId)get the value from the cacheshort[][][]getShortArray3D(java.lang.Object cacheId)get the value from the cachejava.lang.StringgetStats()booleaninMemory(java.lang.Object cacheId)voidprintStats()Print out the cache statisticsvoidremoveFromCache(java.lang.Object cacheId)Remove the item from the cachevoidrun()voidsetCacheDir(java.io.File f)set the directory to write files tovoidsetMemoryPercent(double percentage)voidupdateData(java.lang.Object cacheId, java.lang.Object data)the data has changed for the given cache id
-
-
-
Method Detail
-
getCacheManager
public static DataCacheManager getCacheManager()
The singleton access- Returns:
- the cache manager
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
setCacheDir
public void setCacheDir(java.io.File f)
set the directory to write files to- Parameters:
f- dir
-
getCacheDir
public java.io.File getCacheDir()
get the cache dir. If it was not set then default to current directory- Returns:
- The cache dir
-
getId
public java.lang.Object getId()
Get a unique id- Returns:
- unique id
-
updateData
public void updateData(java.lang.Object cacheId, java.lang.Object data)the data has changed for the given cache id- Parameters:
cacheId- cache iddata- the new data
-
inMemory
public boolean inMemory(java.lang.Object cacheId)
-
getCacheFile
public java.io.File getCacheFile()
-
removeFromCache
public void removeFromCache(java.lang.Object cacheId)
Remove the item from the cache- Parameters:
cacheId- the cache id
-
flushAllCachedData
public void flushAllCachedData()
-
setMemoryPercent
public void setMemoryPercent(double percentage)
-
getMaxSize
public int getMaxSize()
-
checkCache
public void checkCache()
Check if we are above the max size. If so then flush data from memory until we are below the threshold
-
printStats
public void printStats()
Print out the cache statistics
-
getStats
public java.lang.String getStats()
-
getDoubleArray1D
public double[] getDoubleArray1D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(double[] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, double[] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, double[] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getFloatArray1D
public float[] getFloatArray1D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(float[] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, float[] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, float[] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getIntArray1D
public int[] getIntArray1D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(int[] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, int[] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, int[] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getShortArray1D
public short[] getShortArray1D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(short[] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, short[] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, short[] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getByteArray1D
public byte[] getByteArray1D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(byte[] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, byte[] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, byte[] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getDoubleArray2D
public double[][] getDoubleArray2D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(double[][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, double[][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, double[][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getFloatArray2D
public float[][] getFloatArray2D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(float[][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, float[][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, float[][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getIntArray2D
public int[][] getIntArray2D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(int[][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, int[][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, int[][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getShortArray2D
public short[][] getShortArray2D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(short[][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, short[][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, short[][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getByteArray2D
public byte[][] getByteArray2D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(byte[][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, byte[][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, byte[][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getDoubleArray3D
public double[][][] getDoubleArray3D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(double[][][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, double[][][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, double[][][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getFloatArray3D
public float[][][] getFloatArray3D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(float[][][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, float[][][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, float[][][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getIntArray3D
public int[][][] getIntArray3D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(int[][][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, int[][][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, int[][][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getShortArray3D
public short[][][] getShortArray3D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(short[][][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, short[][][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, short[][][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
getByteArray3D
public byte[][][] getByteArray3D(java.lang.Object cacheId)
get the value from the cache- Parameters:
cacheId- the cache id- Returns:
- the value
-
addToCache
public java.lang.Object addToCache(byte[][][] values)
add the data to the cache- Parameters:
values- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, byte[][][] values)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to add- Returns:
- the cache id
-
addToCache
public java.lang.Object addToCache(java.lang.String what, byte[][][] values, boolean removeIfNeeded)add the data to the cache- Parameters:
what- the name of the item. used for tracking cache behaviorvalues- the values to addremoveIfNeeded- If true then this data will not be written to disk and will be removed from the cache when the cache is exceeding memory limits- Returns:
- the cache id
-
-
DMelt 3.0 © DataMelt by jWork.ORG