@ThreadSafe public class FileCacheARC extends java.lang.Object implements FileCacheIF
NetcdfDataset.initNetcdfFileCache(...); // on application startup ... NetcdfFile ncfile = null; try { ncfile = NetcdfDataset.acquireFile(location, cancelTask); ... } finally { if (ncfile != null) ncfile.close(); } ... NetcdfDataset.shutdown(); // when terminating the applicationAll methods are thread safe. Cleanup is done automatically in a background thread, using LRU algorithm.
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.ConcurrentHashMap<java.lang.Object,ucar.nc2.util.cache.FileCacheARC.CacheElement> |
cache |
protected static org.slf4j.Logger |
cacheLog |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,ucar.nc2.util.cache.FileCacheARC.CacheElement.CacheFile> |
files |
protected int |
hardLimit |
protected java.util.concurrent.atomic.AtomicInteger |
hits |
protected static org.slf4j.Logger |
log |
protected int |
minElements |
protected java.util.concurrent.atomic.AtomicInteger |
miss |
protected java.lang.String |
name |
protected int |
period |
protected java.util.concurrent.ConcurrentSkipListMap<ucar.nc2.util.cache.FileCacheARC.CacheElement,ucar.nc2.util.cache.FileCacheARC.CacheElement> |
shadowCache |
protected int |
softLimit |
protected java.util.concurrent.ConcurrentHashMap<java.lang.Object,ucar.nc2.util.cache.FileCacheARC.Tracker> |
track |
Constructor and Description |
---|
FileCacheARC(java.lang.String name,
int minElementsInMemory,
int softLimit,
int hardLimit,
int period)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
FileCacheable |
acquire(FileFactory factory,
java.lang.Object hashKey,
java.lang.String location,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject)
Acquire a FileCacheable from the cache, and lock it so no one else can use it.
|
FileCacheable |
acquire(FileFactory factory,
java.lang.String location)
Acquire a FileCacheable, and lock it so no one else can use it.
|
void |
clearCache(boolean force)
Remove all cache entries.
|
void |
disable()
Disable the cache, and force release all files.
|
void |
eject(java.lang.Object hashKey)
LOOK copied from FileCache, probably wrong
Remove all instances of object from the cache
|
void |
enable()
Enable the cache, with the current set of parameters.
|
java.lang.String |
getInfo(FileCacheable ncfile) |
boolean |
release(FileCacheable ncfile)
Release the file.
|
void |
resetTracking() |
java.util.List<java.lang.String> |
showCache() |
void |
showCache(java.util.Formatter format)
Show individual cache entries, add to formatter.
|
void |
showStats(java.util.Formatter format)
Add stat report (hits, misses, etc) to formatter.
|
void |
showTracking(java.util.Formatter format) |
protected static final org.slf4j.Logger log
protected static final org.slf4j.Logger cacheLog
protected java.lang.String name
protected final int softLimit
protected final int minElements
protected final int hardLimit
protected final int period
protected final java.util.concurrent.ConcurrentSkipListMap<ucar.nc2.util.cache.FileCacheARC.CacheElement,ucar.nc2.util.cache.FileCacheARC.CacheElement> shadowCache
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Object,ucar.nc2.util.cache.FileCacheARC.CacheElement> cache
protected final java.util.concurrent.ConcurrentHashMap<java.lang.Integer,ucar.nc2.util.cache.FileCacheARC.CacheElement.CacheFile> files
protected final java.util.concurrent.atomic.AtomicInteger hits
protected final java.util.concurrent.atomic.AtomicInteger miss
protected java.util.concurrent.ConcurrentHashMap<java.lang.Object,ucar.nc2.util.cache.FileCacheARC.Tracker> track
public FileCacheARC(java.lang.String name, int minElementsInMemory, int softLimit, int hardLimit, int period)
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.public void disable()
disable
in interface FileCacheIF
public void enable()
enable
in interface FileCacheIF
public FileCacheable acquire(FileFactory factory, java.lang.String location) throws java.io.IOException
acquire
in interface FileCacheIF
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 NetcdfFileFactoryjava.io.IOException
- on errorpublic FileCacheable acquire(FileFactory factory, java.lang.Object hashKey, java.lang.String location, int buffer_size, CancelTask cancelTask, java.lang.Object spiObject) throws java.io.IOException
acquire
in interface FileCacheIF
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 nulljava.io.IOException
- on errorpublic void eject(java.lang.Object hashKey)
eject
in interface FileCacheIF
hashKey
- the objectpublic boolean release(FileCacheable ncfile) throws java.io.IOException
release
in interface FileCacheIF
ncfile
- release the lock on this FileCacheable object.java.io.IOException
- if file not in cache.public java.lang.String getInfo(FileCacheable ncfile) throws java.io.IOException
java.io.IOException
public void clearCache(boolean force)
clearCache
in interface FileCacheIF
force
- if true, remove them even if they are currently locked.public void showCache(java.util.Formatter format)
showCache
in interface FileCacheIF
format
- add to thispublic java.util.List<java.lang.String> showCache()
showCache
in interface FileCacheIF
public void showStats(java.util.Formatter format)
showStats
in interface FileCacheIF
format
- add to thispublic void showTracking(java.util.Formatter format)
showTracking
in interface FileCacheIF
public void resetTracking()
resetTracking
in interface FileCacheIF