|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.nc2.NetcdfFileCache
public class NetcdfFileCache
Keep cache of open NetcdfFile objects, for performance. Call NetcdfFileCache.acquire instead of NetcdfFile.open. The NetcdfFile object typically contains a RandomAccessFile object that wraps a system resource like a file handle. These are left open when the NetcdfFile is in the cache. The maximum number of these is bounded, though not strictly. A cleanup routine reduces cache size to a minimum number. This cleanup is called periodically and when the maximum cache size is reached.
NetcdfFile ncfile = null;
try {
ncfile = NetcdfFileCache.acquire(location, cancelTask);
...
} finally {
ncfile.close();
}
Library ships with cache disabled, call init() to use. Make sure you call exit() when exiting program. All methods are thread safe. Cleanup is done automatically in a background thread, using LRU. Uses org.apache.commons.logging for error messages.
NetcdfDataset.acquireFile(java.lang.String, ucar.nc2.util.CancelTask)| Constructor Summary | |
|---|---|
NetcdfFileCache()
|
|
| Method Summary | |
|---|---|
static NetcdfFile |
acquire(java.lang.String location,
CancelTask cancelTask)
Acquire a NetcdfFile, and lock it so no one else can use it. |
static NetcdfFile |
acquire(java.lang.String location,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject,
NetcdfFileFactory factory)
|
static NetcdfFile |
acquireCacheOnly(java.lang.String cacheName)
Try to find a file in the cache. |
static void |
clearCache(boolean force)
Remove all cache entries. |
static void |
disable()
Disable use of the cache. |
static void |
exit()
You must call exit() to shut down the background timer in order to get a clean process shutdown. |
static java.util.List |
getCache()
Get the files in the cache. |
static void |
init()
Default 10 minimum, 20 maximum files, cleanup every 20 minutes |
static void |
init(int minElementsInMemory,
int maxElementsInMemory,
long period)
Initialize the cache. |
static void |
release(NetcdfFile ncfile)
Release the file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public NetcdfFileCache()
| Method Detail |
|---|
public static void init()
public static void init(int minElementsInMemory,
int maxElementsInMemory,
long period)
minElementsInMemory - keep this number in the cachemaxElementsInMemory - trigger a cleanup if it goes over this number.period - (secs) do periodic cleanups every this number of seconds.public static void disable()
public static void exit()
public static NetcdfFile acquireCacheOnly(java.lang.String cacheName)
cacheName - used as the key.
public static NetcdfFile acquire(java.lang.String location,
CancelTask cancelTask)
throws java.io.IOException
You should call NetcdfFile.close() when done, (rather than NetcdfFileCache.release() directly) and the file is then released instead of closed.
If cache size goes over maxElement, then immediately (actually in 10 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.
location - file location, also used as the cache namecancelTask - user can cancel, ok to be null.
java.io.IOException - on errorNetcdfFile.open(java.lang.String)
public static NetcdfFile acquire(java.lang.String location,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject,
NetcdfFileFactory factory)
throws java.io.IOException
java.io.IOException
public static void release(NetcdfFile ncfile)
throws java.io.IOException
ncfile - release this file.
java.io.IOException - if file not in cache.public static java.util.List getCache()
public static void clearCache(boolean force)
force - if true, remove them even if they are currently locked.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||