void close() { // really close the file ncfile.setFileCache(null); try { ncfile.close(); } catch (IOException e) { log.error("close failed on "+ncfile.getLocation(), e); } if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCacheARC " + name + " remove " + ncfile.getLocation()); if (debugPrint) System.out.println(" FileCacheARC " + name + " remove " + ncfile.getLocation()); ncfile = null; }
private CacheFile(FileCacheable ncfile) { this.ncfile = ncfile; this.lastModified = ncfile.getLastModified(); this.lastAccessed = System.currentTimeMillis(); ncfile.setFileCache(FileCache.this); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " add to cache " + hashKey); if (debugPrint) System.out.printf(" FileCache %s add to cache %s (hash %d)%n", name, hashKey, this.hashCode()); }
ncfile.setFileCache(null); // prevent infinite loops ncfile.close(); return false; cacheLog.warn("FileCache " + name + " release " + ncfile.getLocation() + " not locked; hash= "+ncfile.hashCode()); file.ncfile.release(); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " release " + ncfile.getLocation()+"; hash= "+ncfile.hashCode()); if (debugPrint) System.out.printf(" FileCache %s release %s lock=%s count=%d%n", name, ncfile.getLocation(), file.isLocked.get(), countLocked()); return true;
long lastModified = want.ncfile.getLastModified(); boolean changed = lastModified != want.lastModified; if (cacheLog.isDebugEnabled() && changed) cacheLog.debug("FileCache " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard"); if (changed) { want.remove(); files.remove(want.ncfile); want.ncfile.setFileCache(null); try { want.ncfile.close(); } catch (IOException e) { log.error("close failed on "+want.ncfile.getLocation(), e);
file.ncfile.setFileCache(null); file.ncfile.close();
public String toString() { return isLocked + " " + ncfile.getLocation(); }
cacheLog.debug("FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation()); if (debugPrint) System.out.println(" FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation()); if (ncfile != null) ncfile.close(); return null;
long lastModified = want.ncfile.getLastModified(); boolean changed = lastModified != want.lastModified; cacheLog.debug("FileCache " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard"); if (changed) { remove(want); want.ncfile.reacquire(); // rehydrate } catch (IOException ioe) { if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCache " + name + " acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " failed: " + ioe.getMessage());
long lastModified = want.ncfile.getLastModified(); if (lastModified != wantCacheElem.lastModified.get()) { // underlying file was modified if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCacheARC " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard");
private CacheFile(FileCacheable ncfile) { this.ncfile = ncfile; ncfile.setFileCache(FileCacheARC.this); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCacheARC " + name + " add to cache " + hashKey); if (debugPrint) System.out.println(" FileCacheARC " + name + " add to cache " + hashKey); }
private void testPeriodicCleanup(FileCache cache) throws IOException { loadFilesIntoCache(new File(TestDir.cdmLocalTestDataDir), cache); System.out.println(" loaded " + count); // close all Map<Object, FileCache.CacheElement> map = cache.getCache(); List<FileCacheable> files = new ArrayList<>(); for (Object key : map.keySet()) { FileCache.CacheElement elem = map.get(key); assert elem.list.size() == 1; for (FileCache.CacheElement.CacheFile file : elem.list) { files.add(file.ncfile); } } System.out.println(" close " + files.size()); for (FileCacheable ncfile : files) { ncfile.close(); } cache.showCache(new Formatter(System.out)); cache.cleanup(10); }
CacheFile addFile(FileCacheable ncfile) { CacheFile file = new CacheFile(ncfile); list.add(file); this.lastModified.set(ncfile.getLastModified()); this.lastAccessed.set(System.currentTimeMillis()); this.countAccessed.incrementAndGet(); int hashcode = System.identityHashCode(ncfile); // using Object hashCode of the FileCacheable if (debug) { if (files.get(hashcode) != null) cacheLog.error("files (2) already has " + hashKey + " " + name); } files.put(hashcode, file); if (cacheLog.isDebugEnabled()) cacheLog.debug("CacheElement add to cache " + hashKey + " " + name); return file; }
long lastModified = want.ncfile.getLastModified(); boolean changed = lastModified != want.lastModified; if (cacheLog.isDebugEnabled() && changed) cacheLog.debug("FileCache " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard"); if (changed) { want.remove(); files.remove(want.ncfile); want.ncfile.setFileCache(null); try { want.ncfile.close(); } catch (IOException e) { log.error("close failed on "+want.ncfile.getLocation(), e);
file.ncfile.setFileCache(null); file.ncfile.close();
String getCacheName() { return ncfile.getLocation(); }
cacheLog.debug("FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation()); if (debugPrint) System.out.println(" FileCacheARC " + name + " acquire " + hashKey + " " + ncfile.getLocation()); if (ncfile != null) ncfile.close(); return null;
long lastModified = want.ncfile.getLastModified(); boolean changed = lastModified != wantCacheElem.lastModified.get(); cacheLog.debug("FileCacheARC " + name + ": acquire from cache " + hashKey + " " + want.ncfile.getLocation() + " was changed; discard");
private CacheFile(FileCacheable ncfile) { this.ncfile = ncfile; ncfile.setFileCache(FileCacheARC.this); if (cacheLog.isDebugEnabled()) cacheLog.debug("FileCacheARC " + name + " add to cache " + hashKey); if (debugPrint) System.out.println(" FileCacheARC " + name + " add to cache " + hashKey); }
CacheFile addFile(FileCacheable ncfile) { CacheFile file = new CacheFile(ncfile); list.add(file); this.lastModified.set(ncfile.getLastModified()); this.lastAccessed.set(System.currentTimeMillis()); this.countAccessed.incrementAndGet(); int hashcode = System.identityHashCode(ncfile); // using Object hashCode of the FileCacheable if (debug) { if (files.get(hashcode) != null) cacheLog.error("files (2) already has " + hashKey + " " + name); } files.put(hashcode, file); if (cacheLog.isDebugEnabled()) cacheLog.debug("CacheElement add to cache " + hashKey + " " + name); return file; }