ini.trakem2.persistence
Class Cache

java.lang.Object
  extended by ini.trakem2.persistence.Cache

public class Cache
extends java.lang.Object

Access is not synchronized, that is your duty. The current setup depends on calls to removeAndFlushSome to clean up empty slots; otherwise these slots are never cleaned up to avoid O(n) overhead (worst case) when removing a Pyramid for a given id, or O(1) cost of checking whether the first interval is empty and removing it. Granted, the latter could be done in all calls to , but in the current setup this overhead is just not necessary. This Cache self-regulates the size to stay always at or below max_bytes. If the smallest image added is larger than max_bytes, then that image will be the only one in the cache, and will be thrown out when adding a new image. That is, the max_bytes is an indication for a desired maximum. The usual is that the cache will stay below max_bytes, unless when a single image is larger than max_bytes. Also, momentarily when adding an image, max_bytes may be overflown by maximum the size of the newly added image. Take that into account when choosing a value for max_bytes. When an image is removed, either directly or out of house-keeping to stay under max_bytes, that image is flushed. ImagePlus instances are not flushed, but if they point to an Image, then that image is flushed.


Constructor Summary
Cache(long max_bytes)
           
 
Method Summary
 boolean contains(long id)
           
 boolean contains(long id, int level)
           
 void debug()
           
 long ensureFree(long min_free_bytes)
          Remove and flush the minimal amount of images to ensure there are at least min_free_bytes free.
 ij.ImagePlus get(long id)
           
 java.awt.Image get(long id, int level)
           
 ij.ImagePlus get(java.lang.String path)
           
 java.util.Map<java.lang.Integer,java.awt.Image> getAll(long id)
           
 long getBytes()
          Current estimated space occupied by the images in this cache.
 java.awt.Image getClosestAbove(long id, int level)
           
 java.awt.Image getClosestBelow(long id, int level)
           
 long getMaxBytes()
          Maximum desired space for this cache.
static java.lang.String getPath(ij.ImagePlus imp)
          Returns null if the ImagePlus was preprocessed.
 void put(long id, java.awt.Image image, int level)
           
 void put(long id, ij.ImagePlus imp, int maxdim)
           
 void remove(long id)
           
 java.awt.Image remove(long id, int level)
          Remove one mipmap level, if there.
 void removeAndFlushAll()
          Flush all mipmaps, and forget all mipmaps and imps.
 void removeAndFlushPyramid(long id)
          Does not alter the ImagePlus.
 long removeAndFlushSome(int n)
           
 long removeAndFlushSome(long min_bytes)
          Returns the number of released bytes.
 ij.ImagePlus removeImagePlus(long id)
          Remove only the ImagePlus, if there.
 long seqFindId(ij.ImagePlus imp)
           
 void setMaxBytes(long max_bytes)
           
 int size()
           
 void updateImagePlusPath(java.lang.String oldPath, java.lang.String newPath)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Cache

public Cache(long max_bytes)
Method Detail

setMaxBytes

public void setMaxBytes(long max_bytes)

ensureFree

public final long ensureFree(long min_free_bytes)
Remove and flush the minimal amount of images to ensure there are at least min_free_bytes free.


getMaxBytes

public long getMaxBytes()
Maximum desired space for this cache.


getBytes

public long getBytes()
Current estimated space occupied by the images in this cache.


contains

public final boolean contains(long id)

contains

public final boolean contains(long id,
                              int level)

get

public final java.awt.Image get(long id,
                                int level)

get

public final ij.ImagePlus get(java.lang.String path)

get

public final ij.ImagePlus get(long id)

getAll

public final java.util.Map<java.lang.Integer,java.awt.Image> getAll(long id)

getClosestAbove

public final java.awt.Image getClosestAbove(long id,
                                            int level)

getClosestBelow

public final java.awt.Image getClosestBelow(long id,
                                            int level)

put

public final void put(long id,
                      java.awt.Image image,
                      int level)

updateImagePlusPath

public final void updateImagePlusPath(java.lang.String oldPath,
                                      java.lang.String newPath)

getPath

public static final java.lang.String getPath(ij.ImagePlus imp)
Returns null if the ImagePlus was preprocessed.


put

public final void put(long id,
                      ij.ImagePlus imp,
                      int maxdim)
Parameters:
maxdim - is max(width, height) of the Patch wrapping @param imp; that is, the dimensions of the mipmap image.

remove

public final java.awt.Image remove(long id,
                                   int level)
Remove one mipmap level, if there.


removeImagePlus

public final ij.ImagePlus removeImagePlus(long id)
Remove only the ImagePlus, if there.


remove

public final void remove(long id)

removeAndFlushAll

public final void removeAndFlushAll()
Flush all mipmaps, and forget all mipmaps and imps.


removeAndFlushPyramid

public final void removeAndFlushPyramid(long id)
Does not alter the ImagePlus.


removeAndFlushSome

public final long removeAndFlushSome(long min_bytes)
Returns the number of released bytes.


removeAndFlushSome

public final long removeAndFlushSome(int n)

size

public final int size()

debug

public void debug()

seqFindId

public final long seqFindId(ij.ImagePlus imp)