@Override public FileCacheable acquire(final FileFactory factory, Object hashKey, final DatasetUrl durl, final int buffer_size, final CancelTask cancelTask, final Object spiObject) throws IOException { if (null == hashKey) hashKey = durl.trueurl; if (null == hashKey) throw new IllegalArgumentException(); try { // If the key wasn't in the "easy to compute" group, we need to use the factory. return cache.get((String)hashKey, () -> factory.open(durl, buffer_size, cancelTask, spiObject)); } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); } }
/** * Same as openFile, but file is acquired through the File Cache. * You still close with NetcdfFile.close(), the release is handled automatically. * You must first call initNetcdfFileCache() for caching to actually take place. * * @param factory if not null, use this factory to read the file. If null, use the default factory. * @param hashKey if not null, use as the cache key, else use the location * @param location location of file, passed to FileFactory * @param buffer_size RandomAccessFile buffer size, if <= 0, use default size * @param cancelTask allow task to be cancelled; may be null. * @param spiObject sent to iosp.setSpecial(); may be null * @return NetcdfFile object * @throws java.io.IOException on read error */ static public NetcdfFile acquireFile(ucar.nc2.util.cache.FileFactory factory, Object hashKey, String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { // must use the factory if there is one but no fileCache if ((fileCache == null) && (factory != null)) { return (NetcdfFile) factory.open(location, buffer_size, cancelTask, spiObject); } return openOrAcquireFile(fileCache, factory, hashKey, location, buffer_size, cancelTask, spiObject); }
/** * Same as openFile, but file is acquired through the File Cache. * You still close with NetcdfFile.close(), the release is handled automatically. * You must first call initNetcdfFileCache() for caching to actually take place. * * @param factory if not null, use this factory to read the file. If null, use the default factory. * @param hashKey if not null, use as the cache key, else use the location * @param location location of file, passed to FileFactory * @param buffer_size RandomAccessFile buffer size, if <= 0, use default size * @param cancelTask allow task to be cancelled; may be null. * @param spiObject sent to iosp.setSpecial(); may be null * @return NetcdfFile object * @throws java.io.IOException on read error */ static public NetcdfFile acquireFile(ucar.nc2.util.cache.FileFactory factory, Object hashKey, DatasetUrl location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { // must use the factory if there is one but no fileCache if ((netcdfFileCache == null) && (factory != null)) { return (NetcdfFile) factory.open(location, buffer_size, cancelTask, spiObject); } return openOrAcquireFile(netcdfFileCache, factory, hashKey, location, buffer_size, cancelTask, spiObject); }
/** * Same as openFile, but file is acquired through the File Cache. * You still close with NetcdfFile.close(), the release is handled automatically. * You must first call initNetcdfFileCache() for caching to actually take place. * * @param factory if not null, use this factory to read the file. If null, use the default factory. * @param hashKey if not null, use as the cache key, else use the location * @param location location of file, passed to FileFactory * @param buffer_size RandomAccessFile buffer size, if <= 0, use default size * @param cancelTask allow task to be cancelled; may be null. * @param spiObject sent to iosp.setSpecial(); may be null * @return NetcdfFile object * @throws java.io.IOException on read error */ static public NetcdfFile acquireFile(ucar.nc2.util.cache.FileFactory factory, Object hashKey, String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object spiObject) throws IOException { // must use the factory if there is one but no fileCache if ((fileCache == null) && (factory != null)) { return (NetcdfFile) factory.open(location, buffer_size, cancelTask, spiObject); } return openOrAcquireFile(fileCache, factory, hashKey, location, buffer_size, cancelTask, spiObject); }
public GribCollectionImmutable getGribCollection() throws IOException { String path = getIndexFilenameInCache(); if (path == null) { if (Grib.debugIndexOnly) { // we are running in debug mode where we only have the indices, not the data files // tricky: substitute the current root File orgParentDir = new File(directory); File currentFile = new File(PartitionCollectionMutable.this.indexFilename); File currentParent = currentFile.getParentFile(); File currentParentWithDir = new File(currentParent, orgParentDir.getName()); File nestedIndex = isPartitionOfPartitions ? new File(currentParentWithDir, filename) : new File(currentParent, filename); // JMJ path = nestedIndex.getPath(); } else { throw new FileNotFoundException("No index filename for partition= "+this.toString()); } } // LOOK not cached return (GribCollectionImmutable) PartitionCollectionImmutable.partitionCollectionFactory.open(new DatasetUrl(null, path), -1, null, this); }
static public GribCollectionImmutable acquireGribCollection(FileFactory factory, Object hashKey, String location, int buffer_size, CancelTask cancelTask, Object spiObject) throws IOException { FileCacheable result; DatasetUrl durl = new DatasetUrl(null, location); if (gribCollectionCache != null) { // FileFactory factory, Object hashKey, String location, int buffer_size, CancelTask cancelTask, Object spiObject result = GribCdmIndex.gribCollectionCache.acquire(factory, hashKey, durl, buffer_size, cancelTask, spiObject); } else { // String location, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object iospMessage result = factory.open(durl, buffer_size, cancelTask, spiObject); } return (GribCollectionImmutable) result; }
static public NetcdfDataset acquireDataset(FileFactory fac, DatasetUrl durl, Set<Enhance> enhanceMode, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object iospMessage) throws IOException { // caching not turned on if (netcdfFileCache == null) { if (fac == null) return openDataset(durl, enhanceMode, buffer_size, cancelTask, iospMessage); else // must use the factory if there is one return (NetcdfDataset) fac.open(durl, buffer_size, cancelTask, iospMessage); } if (fac != null) return (NetcdfDataset) openOrAcquireFile(netcdfFileCache, fac, null, durl, buffer_size, cancelTask, iospMessage); fac = new MyNetcdfDatasetFactory(durl, enhanceMode); return (NetcdfDataset) openOrAcquireFile(netcdfFileCache, fac, fac.hashCode(), durl, buffer_size, cancelTask, iospMessage); }
ncfile = factory.open(location, buffer_size, cancelTask, spiObject); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation());
ncfile = factory.open(location, buffer_size, cancelTask, spiObject); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " acquire " + hashKey + " " + ncfile.getLocation());
ncfile = factory.open(location, buffer_size, cancelTask, spiObject); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation());
/** * Same as openDataset, but file is acquired through the File Cache. * You must first call initNetcdfFileCache() for caching to actually take place. * You still close with NetcdfDataset.close(), the release is handled automatically. * * @param fac if not null, use this factory if the file is not in the cache. If null, use the default factory. * @param location location of file, passed to FileFactory * @param enhanceMode how to enhance. if null, then no enhancement * @param buffer_size RandomAccessFile buffer size, if <= 0, use default size * @param cancelTask allow task to be cancelled; may be null. * @param iospMessage sent to iosp.setSpecial() if not null * @return NetcdfDataset object * @throws java.io.IOException on read error */ static public NetcdfDataset acquireDataset(FileFactory fac, String location, Set<Enhance> enhanceMode, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object iospMessage) throws IOException { // caching not turned on if (fileCache == null) { if (fac == null) return openDataset(location, enhanceMode, buffer_size, cancelTask, iospMessage); else // must use the factory if there is one return (NetcdfDataset) fac.open(location, buffer_size, cancelTask, iospMessage); } if (fac != null) return (NetcdfDataset) openOrAcquireFile(fileCache, fac, null, location, buffer_size, cancelTask, iospMessage); fac = new MyNetcdfDatasetFactory(location, enhanceMode); return (NetcdfDataset) openOrAcquireFile(fileCache, fac, fac.hashCode(), location, buffer_size, cancelTask, iospMessage); }
ncfile = factory.open(location, buffer_size, cancelTask, spiObject); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " acquire " + hashKey + " " + ncfile.getLocation());
/** * Same as openDataset, but file is acquired through the File Cache. * You must first call initNetcdfFileCache() for caching to actually take place. * You still close with NetcdfDataset.close(), the release is handled automatically. * * @param fac if not null, use this factory if the file is not in the cache. If null, use the default factory. * @param location location of file, passed to FileFactory * @param enhanceMode how to enhance. if null, then no enhancement * @param buffer_size RandomAccessFile buffer size, if <= 0, use default size * @param cancelTask allow task to be cancelled; may be null. * @param iospMessage sent to iosp.setSpecial() if not null * @return NetcdfDataset object * @throws java.io.IOException on read error */ static public NetcdfDataset acquireDataset(FileFactory fac, String location, Set<Enhance> enhanceMode, int buffer_size, ucar.nc2.util.CancelTask cancelTask, Object iospMessage) throws IOException { // caching not turned on if (fileCache == null) { if (fac == null) return openDataset(location, enhanceMode, buffer_size, cancelTask, iospMessage); else // must use the factory if there is one return (NetcdfDataset) fac.open(location, buffer_size, cancelTask, iospMessage); } if (fac != null) return (NetcdfDataset) openOrAcquireFile(fileCache, fac, null, location, buffer_size, cancelTask, iospMessage); fac = new MyNetcdfDatasetFactory(location, enhanceMode); return (NetcdfDataset) openOrAcquireFile(fileCache, fac, fac.hashCode(), location, buffer_size, cancelTask, iospMessage); }
ncfile = factory.open(location, buffer_size, cancelTask, spiObject); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " acquire " + hashKey + " " + ncfile.getLocation());