NASA World Wind

gov.nasa.worldwind.cache
Class BasicRasterServerCache

java.lang.Object
  extended by gov.nasa.worldwind.cache.BasicMemoryCache
      extended by gov.nasa.worldwind.cache.BasicRasterServerCache
All Implemented Interfaces:
MemoryCache

public class BasicRasterServerCache
extends BasicMemoryCache

The BasicRasterServerCache is an implementation of the memory cache that is specific to store maximum possible cacheable items, until the heap size allows. Once the memory limit is hit, it will drop ALL cached items. Also, BasicRasterServerCache creates a pruner thread that removes all cached items which were not used for 20 seconds or more. The least recent use timeout is configurable via the setLeastRecentUseTimeout() method. In addition, the BasicRasterServerCache allocates 100MB memory and keeps only a phantom reference to the allocated 100M memory. Once any part of the application needs more memory the phantom referenced memory will be immediately released and the phantom reference will be added to the internal reference queue, which is monitored by an internal MemoryMonitorThread. Once the phantom reference is added to the reference queue, the entire cached content will be released. This approach allows to use almost entire available heap memory to cache rasters and release memory when more memory is needed to the application itself.


Nested Class Summary
 
Nested classes/interfaces inherited from class gov.nasa.worldwind.cache.BasicMemoryCache
BasicMemoryCache.CacheEntry
 
Nested classes/interfaces inherited from interface gov.nasa.worldwind.cache.MemoryCache
MemoryCache.CacheListener
 
Field Summary
protected static int DEFAULT_INACCESSIBLE_MEMORY_SIZE
           
protected static long DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC
           
protected static long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
           
protected  AtomicInteger inaccessibleMemorySize
           
protected  Reference<Object> lowMemorySemaphore
           
protected  ReferenceQueue<Object> queue
           
protected  long timeoutLeastRecentUseInNanoSeconds
           
 
Fields inherited from class gov.nasa.worldwind.cache.BasicMemoryCache
capacity, currentUsedCapacity, entries, listeners, lock, lowWater, name
 
Constructor Summary
BasicRasterServerCache()
          Constructs a new cache which uses entire memory, but will immediately drop all cached entries ones there is a need for more memory by anyone else.
BasicRasterServerCache(int inaccessibleMemorySize)
           
 
Method Summary
 boolean add(Object key, Object clientObject, long clientObjectSize)
          Adds an object to the cache.
 long getLeastRecentUseTimeout()
           
protected  void removeExpiredEntries()
           
 void setLeastRecentUseTimeout(long nanoSeconds)
           
protected  void updateMemorySemaphore()
           
 
Methods inherited from class gov.nasa.worldwind.cache.BasicMemoryCache
add, addCacheListener, clear, contains, finalize, getCapacity, getFreeCapacity, getLowWater, getName, getNumObjects, getObject, getUsedCapacity, remove, removeCacheListener, removeEntry, setCapacity, setLowWater, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INACCESSIBLE_MEMORY_SIZE

protected static final int DEFAULT_INACCESSIBLE_MEMORY_SIZE
See Also:
Constant Field Values

DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC

protected static final long DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC
See Also:
Constant Field Values

DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC

protected static final long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
See Also:
Constant Field Values

inaccessibleMemorySize

protected AtomicInteger inaccessibleMemorySize

lowMemorySemaphore

protected Reference<Object> lowMemorySemaphore

queue

protected final ReferenceQueue<Object> queue

timeoutLeastRecentUseInNanoSeconds

protected long timeoutLeastRecentUseInNanoSeconds
Constructor Detail

BasicRasterServerCache

public BasicRasterServerCache()
Constructs a new cache which uses entire memory, but will immediately drop all cached entries ones there is a need for more memory by anyone else.


BasicRasterServerCache

public BasicRasterServerCache(int inaccessibleMemorySize)
Method Detail

add

public boolean add(Object key,
                   Object clientObject,
                   long clientObjectSize)
Description copied from class: BasicMemoryCache
Adds an object to the cache. The add fails if the object or key is null, or if the size is zero, negative or greater than the maximmum capacity.

Specified by:
add in interface MemoryCache
Overrides:
add in class BasicMemoryCache
Parameters:
key - The unique reference key that identifies this object.
clientObject - The actual object to be cached.
clientObjectSize - The size of the object in cache units.
Returns:
returns true if clientObject was added, false otherwise.

getLeastRecentUseTimeout

public long getLeastRecentUseTimeout()

removeExpiredEntries

protected void removeExpiredEntries()

setLeastRecentUseTimeout

public void setLeastRecentUseTimeout(long nanoSeconds)

updateMemorySemaphore

protected void updateMemorySemaphore()

NASA World Wind