gov.nasa.worldwind.cache.BasicRasterServerCache Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2012 United States Government as represented by the Administrator of the
* National Aeronautics and Space Administration.
* All Rights Reserved.
*/
package gov.nasa.worldwind.cache;
import gov.nasa.worldwind.util.Logging;
import java.lang.ref.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
/**
* @author Lado Garakanidze
* @version $Id: BasicRasterServerCache.java 1171 2013-02-11 21:45:02Z dcollins $
*/
/**
* 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.
*/
public class BasicRasterServerCache extends BasicMemoryCache
{
protected static final int DEFAULT_INACCESSIBLE_MEMORY_SIZE = 100 * 1024 * 1024;
protected static final long DEFAULT_PRUNER_THREAD_TIMEOUT_MSEC = 5000L; // 20 secs = 20,000 milli-seconds
protected static final long DEFAULT_LEAST_RECENTLY_USED_TIMEOUT_NSEC = 20000000000L;
// 20 sec = 20,000,000,000 nano-sec
protected AtomicInteger inaccessibleMemorySize = new AtomicInteger(DEFAULT_INACCESSIBLE_MEMORY_SIZE);
protected final ReferenceQueue
© 2015 - 2024 Weber Informatics LLC | Privacy Policy