Package gov.nasa.worldwind.cache
Class BasicRasterServerCache
- java.lang.Object
-
- gov.nasa.worldwind.cache.BasicMemoryCache
-
- gov.nasa.worldwind.cache.BasicRasterServerCache
-
- All Implemented Interfaces:
MemoryCache
public class BasicRasterServerCache extends BasicMemoryCache
TheBasicRasterServerCache
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 thesetLeastRecentUseTimeout()
method. In addition, theBasicRasterServerCache
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 internalMemoryMonitorThread
. 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
Fields Modifier and Type Field Description 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 java.util.concurrent.atomic.AtomicInteger
inaccessibleMemorySize
protected java.lang.ref.Reference<java.lang.Object>
lowMemorySemaphore
protected java.lang.ref.ReferenceQueue<java.lang.Object>
queue
protected long
timeoutLeastRecentUseInNanoSeconds
-
Fields inherited from class gov.nasa.worldwind.cache.BasicMemoryCache
capacity, currentUsedCapacity, entries, listeners, lock, lowWater, name
-
-
Constructor Summary
Constructors Constructor Description 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(java.lang.Object key, java.lang.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, getCapacity, getFreeCapacity, getLowWater, getName, getNumObjects, getObject, getUsedCapacity, remove, removeCacheListener, removeEntry, setCapacity, setLowWater, setName, toString
-
-
-
-
Field Detail
-
DEFAULT_INACCESSIBLE_MEMORY_SIZE
protected static final int DEFAULT_INACCESSIBLE_MEMORY_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
protected static final long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC
- 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
-
inaccessibleMemorySize
protected java.util.concurrent.atomic.AtomicInteger inaccessibleMemorySize
-
queue
protected final java.lang.ref.ReferenceQueue<java.lang.Object> queue
-
lowMemorySemaphore
protected java.lang.ref.Reference<java.lang.Object> lowMemorySemaphore
-
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(java.lang.Object key, java.lang.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 interfaceMemoryCache
- Overrides:
add
in classBasicMemoryCache
- 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.
-
updateMemorySemaphore
protected void updateMemorySemaphore()
-
getLeastRecentUseTimeout
public long getLeastRecentUseTimeout()
-
setLeastRecentUseTimeout
public void setLeastRecentUseTimeout(long nanoSeconds)
-
removeExpiredEntries
protected void removeExpiredEntries()
-
-