|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectucar.nc2.dataset.NetcdfDatasetCache
public class NetcdfDatasetCache
Keep cache of open NetcdfDataset, for performance. Call NetcdfDatasetCache.acquire instead of NetcdfDataset.open.
NetcdfDataset ncd = null;
try {
ncd = NetcdfDatsetCache.acquire(location, enhance, cancelTask);
...
} finally {
ncd.close( ncfile)
}
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.slf4j.Logger for error messages.
| Constructor Summary | |
|---|---|
NetcdfDatasetCache()
|
|
| Method Summary | |
|---|---|
static NetcdfDataset |
acquire(java.lang.String location,
CancelTask cancelTask)
Acquire a NetcdfDataset, and lock it so no one else can use it. |
static NetcdfDataset |
acquire(java.lang.String cacheName,
CancelTask cancelTask,
NetcdfDatasetFactory factory)
Same as acquire(), but use a factory to open the dataset. |
static NetcdfDataset |
acquire(java.lang.String cacheName,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject,
NetcdfDatasetFactory factory)
Same as acquire(), but use a factory to open the dataset. |
static NetcdfDataset |
acquireCacheOnly(java.lang.String cacheName,
CancelTask cancelTask)
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(NetcdfDataset ncd)
Release the file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public NetcdfDatasetCache()
| 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 NetcdfDataset acquireCacheOnly(java.lang.String cacheName,
CancelTask cancelTask)
throws java.io.IOException
cacheName - used as the key.
java.io.IOException
public static NetcdfDataset acquire(java.lang.String location,
CancelTask cancelTask)
throws java.io.IOException
You should call NetcdfDataset.close() when done, (rather than NetcdfDatasetCache.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 the task, ok to be null.
java.io.IOException - on errorNetcdfFile.open(java.lang.String)
public static NetcdfDataset acquire(java.lang.String cacheName,
CancelTask cancelTask,
NetcdfDatasetFactory factory)
throws java.io.IOException
cacheName - : use this as the cache name, may or may not be the same as the location. This is also passed to the
factory object.cancelTask - user can cancel the task, ok to be null.factory - use this to open; if null use NetcdfDataset.openDataset(). factory should not use NetcdfFileCache.
java.io.IOException - on error
public static NetcdfDataset acquire(java.lang.String cacheName,
int buffer_size,
CancelTask cancelTask,
java.lang.Object spiObject,
NetcdfDatasetFactory factory)
throws java.io.IOException
cacheName - : use this as the cache name, may or may not be the same as the location. This is also passed to the
factory object.cancelTask - user can cancel the task, ok to be null.factory - use this to open; if null use NetcdfDataset.openDataset(). factory should not use NetcdfFileCache.
java.io.IOException - on error
public static void release(NetcdfDataset ncd)
throws java.io.IOException
ncd - 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 | |||||||||