Package ucar.nc2.util.cache
Class FileCacheARC
- java.lang.Object
-
- ucar.nc2.util.cache.FileCacheARC
-
- All Implemented Interfaces:
FileCacheIF
@ThreadSafe public class FileCacheARC extends Object implements FileCacheIF
ARC cach algorithm not complete.
-
-
Field Summary
Fields Modifier and Type Field Description protected ConcurrentHashMap<Object,ucar.nc2.util.cache.FileCacheARC.CacheElement>cacheprotected static org.slf4j.LoggercacheLogprotected ConcurrentHashMap<Integer,ucar.nc2.util.cache.FileCacheARC.CacheElement.CacheFile>filesprotected inthardLimitprotected AtomicIntegerhitsprotected static org.slf4j.Loggerlogprotected intminElementsprotected AtomicIntegermissprotected Stringnameprotected intperiodprotected ConcurrentSkipListMap<ucar.nc2.util.cache.FileCacheARC.CacheElement,ucar.nc2.util.cache.FileCacheARC.CacheElement>shadowCacheprotected intsoftLimitprotected ConcurrentHashMap<Object,ucar.nc2.util.cache.FileCacheARC.Tracker>track
-
Constructor Summary
Constructors Constructor Description FileCacheARC(String name, int minElementsInMemory, int softLimit, int hardLimit, int period)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FileCacheableacquire(FileFactory factory, Object hashKey, DatasetUrl location, int buffer_size, CancelTask cancelTask, Object spiObject)Acquire a FileCacheable from the cache, and lock it so no one else can use it.FileCacheableacquire(FileFactory factory, DatasetUrl location)Acquire a FileCacheable, and lock it so no one else can use it.voidclearCache(boolean force)Remove all cache entries.voiddisable()Disable the cache, and force release all files.voideject(Object hashKey)LOOK copied from FileCache, probably wrong Remove all instances of object from the cachevoidenable()Enable the cache, with the current set of parameters.StringgetInfo(FileCacheable ncfile)booleanrelease(FileCacheable ncfile)Release the file.voidresetTracking()List<String>showCache()voidshowCache(Formatter format)Show individual cache entries, add to formatter.voidshowStats(Formatter format)Add stat report (hits, misses, etc) to formatter.voidshowTracking(Formatter format)
-
-
-
Field Detail
-
log
protected static final org.slf4j.Logger log
-
cacheLog
protected static final org.slf4j.Logger cacheLog
-
name
protected String name
-
softLimit
protected final int softLimit
-
minElements
protected final int minElements
-
hardLimit
protected final int hardLimit
-
period
protected final int period
-
shadowCache
protected final ConcurrentSkipListMap<ucar.nc2.util.cache.FileCacheARC.CacheElement,ucar.nc2.util.cache.FileCacheARC.CacheElement> shadowCache
-
cache
protected final ConcurrentHashMap<Object,ucar.nc2.util.cache.FileCacheARC.CacheElement> cache
-
files
protected final ConcurrentHashMap<Integer,ucar.nc2.util.cache.FileCacheARC.CacheElement.CacheFile> files
-
hits
protected final AtomicInteger hits
-
miss
protected final AtomicInteger miss
-
track
protected ConcurrentHashMap<Object,ucar.nc2.util.cache.FileCacheARC.Tracker> track
-
-
Constructor Detail
-
FileCacheARC
public FileCacheARC(String name, int minElementsInMemory, int softLimit, int hardLimit, int period)
Constructor.- Parameters:
name- of file cacheminElementsInMemory- keep this number in the cachesoftLimit- trigger a cleanup if it goes over this number.hardLimit- if > 0, never allow more than this many elements. This causes a cleanup to be done in the calling thread.period- if > 0, do periodic cleanups every this number of seconds.
-
-
Method Detail
-
disable
public void disable()
Disable the cache, and force release all files. You must still call shutdown() before exiting the application.- Specified by:
disablein interfaceFileCacheIF
-
enable
public void enable()
Enable the cache, with the current set of parameters.- Specified by:
enablein interfaceFileCacheIF
-
acquire
public FileCacheable acquire(FileFactory factory, DatasetUrl location) throws IOException
Acquire a FileCacheable, and lock it so no one else can use it. call FileCacheable.close() when done.- Specified by:
acquirein interfaceFileCacheIF- Parameters:
factory- use this factory to open the file; may not be nulllocation- file location, also used as the cache name, will be passed to the NetcdfFileFactory- Returns:
- NetcdfFile corresponding to location.
- Throws:
IOException- on error
-
acquire
public FileCacheable acquire(FileFactory factory, Object hashKey, DatasetUrl location, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException
Acquire a FileCacheable from the cache, and lock it so no one else can use it. If not already in cache, open it with FileFactory, and put in cache. Call FileCacheable.close() when done, (rather than FileCacheIF.release() directly) and the file is then released instead of closed. If cache size goes over maxElement, then immediately (actually in 100 msec) schedule a cleanup in a background thread. This means that the cache should never get much larger than maxElement, unless you have them all locked.- Specified by:
acquirein interfaceFileCacheIF- Parameters:
factory- use this factory to open the file if not in the cache; may not be nullhashKey- unique key for this file. If null, the location will be usedlocation- file location, may also used as the cache name, will be passed to the NetcdfFileFactorybuffer_size- RandomAccessFile buffer size, if <= 0, use default sizecancelTask- user can cancel, ok to be null.spiObject- sent to iosp.setSpecial() if not null- Returns:
- FileCacheable corresponding to location.
- Throws:
IOException- on error
-
eject
public void eject(Object hashKey)
LOOK copied from FileCache, probably wrong Remove all instances of object from the cache- Specified by:
ejectin interfaceFileCacheIF- Parameters:
hashKey- the object
-
release
public boolean release(FileCacheable ncfile) throws IOException
Release the file. This unlocks it, updates its lastAccessed date. FileCacheable.close() needs to call this instead of actually closing.- Specified by:
releasein interfaceFileCacheIF- Parameters:
ncfile- release the lock on this FileCacheable object.- Throws:
IOException- if file not in cache.
-
getInfo
public String getInfo(FileCacheable ncfile)
-
clearCache
public void clearCache(boolean force)
Remove all cache entries.- Specified by:
clearCachein interfaceFileCacheIF- Parameters:
force- if true, remove them even if they are currently locked.
-
showCache
public void showCache(Formatter format)
Show individual cache entries, add to formatter.- Specified by:
showCachein interfaceFileCacheIF- Parameters:
format- add to this
-
showCache
public List<String> showCache()
- Specified by:
showCachein interfaceFileCacheIF
-
showStats
public void showStats(Formatter format)
Add stat report (hits, misses, etc) to formatter.- Specified by:
showStatsin interfaceFileCacheIF- Parameters:
format- add to this
-
showTracking
public void showTracking(Formatter format)
- Specified by:
showTrackingin interfaceFileCacheIF
-
resetTracking
public void resetTracking()
- Specified by:
resetTrackingin interfaceFileCacheIF
-
-