Documentation of 'visad.data.DataCacheManager' Java class
DataCacheManager
visad.data

Class DataCacheManager

  • All Implemented Interfaces:
    java.lang.Runnable


    public class DataCacheManager
    extends java.lang.Object
    implements java.lang.Runnable
    This 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.Object addToCache(byte[] values)
      add the data to the cache
      java.lang.Object addToCache(byte[][] values)
      add the data to the cache
      java.lang.Object addToCache(byte[][][] values)
      add the data to the cache
      java.lang.Object addToCache(double[] values)
      add the data to the cache
      java.lang.Object addToCache(double[][] values)
      add the data to the cache
      java.lang.Object addToCache(double[][][] values)
      add the data to the cache
      java.lang.Object addToCache(float[] values)
      add the data to the cache
      java.lang.Object addToCache(float[][] values)
      add the data to the cache
      java.lang.Object addToCache(float[][][] values)
      add the data to the cache
      java.lang.Object addToCache(int[] values)
      add the data to the cache
      java.lang.Object addToCache(int[][] values)
      add the data to the cache
      java.lang.Object addToCache(int[][][] values)
      add the data to the cache
      java.lang.Object addToCache(short[] values)
      add the data to the cache
      java.lang.Object addToCache(short[][] values)
      add the data to the cache
      java.lang.Object addToCache(short[][][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, byte[] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, byte[][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, byte[][][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, byte[][][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, byte[][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, byte[] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, double[] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, double[][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, double[][][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, double[][][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, double[][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, double[] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, float[] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, float[][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, float[][][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, float[][][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, float[][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, float[] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, int[] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, int[][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, int[][][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, int[][][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, int[][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, int[] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, short[] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, short[][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, short[][][] values)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, short[][][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, short[][] values, boolean removeIfNeeded)
      add the data to the cache
      java.lang.Object addToCache(java.lang.String what, short[] values, boolean removeIfNeeded)
      add the data to the cache
      void checkCache()
      Check if we are above the max size.
      void flushAllCachedData() 
      byte[] getByteArray1D(java.lang.Object cacheId)
      get the value from the cache
      byte[][] getByteArray2D(java.lang.Object cacheId)
      get the value from the cache
      byte[][][] getByteArray3D(java.lang.Object cacheId)
      get the value from the cache
      java.io.File getCacheDir()
      get the cache dir.
      java.io.File getCacheFile() 
      static DataCacheManager getCacheManager()
      The singleton access
      double[] getDoubleArray1D(java.lang.Object cacheId)
      get the value from the cache
      double[][] getDoubleArray2D(java.lang.Object cacheId)
      get the value from the cache
      double[][][] getDoubleArray3D(java.lang.Object cacheId)
      get the value from the cache
      float[] getFloatArray1D(java.lang.Object cacheId)
      get the value from the cache
      float[][] getFloatArray2D(java.lang.Object cacheId)
      get the value from the cache
      float[][][] getFloatArray3D(java.lang.Object cacheId)
      get the value from the cache
      java.lang.Object getId()
      Get a unique id
      int[] getIntArray1D(java.lang.Object cacheId)
      get the value from the cache
      int[][] getIntArray2D(java.lang.Object cacheId)
      get the value from the cache
      int[][][] getIntArray3D(java.lang.Object cacheId)
      get the value from the cache
      int getMaxSize() 
      short[] getShortArray1D(java.lang.Object cacheId)
      get the value from the cache
      short[][] getShortArray2D(java.lang.Object cacheId)
      get the value from the cache
      short[][][] getShortArray3D(java.lang.Object cacheId)
      get the value from the cache
      java.lang.String getStats() 
      boolean inMemory(java.lang.Object cacheId) 
      void printStats()
      Print out the cache statistics
      void removeFromCache(java.lang.Object cacheId)
      Remove the item from the cache
      void run() 
      void setCacheDir(java.io.File f)
      set the directory to write files to
      void setMemoryPercent(double percentage) 
      void updateData(java.lang.Object cacheId, java.lang.Object data)
      the data has changed for the given cache id
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getCacheManager

        public static DataCacheManager getCacheManager()
        The singleton access
        Returns:
        the cache manager
      • run

        public void run()
        Specified by:
        run in interface java.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 id
        data - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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 behavior
        values - 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 behavior
        values - the values to add
        removeIfNeeded - 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

You see the box below because you did not login.