@Override public Long get(Object key) { if( isInPurgeMode()) { LOG.debug("cache is purge mode: get is no-op"); return null; } synchronized (this) { return super.get(key); } }
@Override public Long get(Object key) { if( isInPurgeMode()) { LOG.debug("cache is purge mode: get is no-op"); return null; } synchronized (this) { return super.get(key); } }
@Override public Long get(Object key) { if( isInPurgeMode()) { LOG.debug("cache is purge mode: get is no-op"); return null; } synchronized (this) { return super.get(key); } }
/** * Delete file from cache. Size of cache is reduced by file length. The * method is no-op if file doesn't exist in cache. * * @param fileName file name that need to be removed from cache. */ public void delete(String fileName) { if (isInPurgeMode()) { LOG.debug("purgeMode true :delete returned"); return; } fileName = fileName.replace("\\", "/"); cache.remove(fileName); }
/** * Delete file from cache. Size of cache is reduced by file length. The * method is no-op if file doesn't exist in cache. * * @param fileName file name that need to be removed from cache. */ public void delete(String fileName) { if (isInPurgeMode()) { LOG.debug("purgeMode true :delete returned"); return; } fileName = fileName.replace("\\", "/"); cache.remove(fileName); }
/** * Check if cache can admit file of given length. * @param length of the file. * @return true if yes else return false. */ private boolean canAdmitFile(final long length) { //order is important here boolean value = !isInPurgeMode() && (cache.canAdmitFile(length)); if (!value) { LOG.debug("cannot admit file of length=[{}] and currentSizeInBytes=[{}] ", length, cache.currentSizeInBytes); } return value; }
/** * Check if cache can admit file of given length. * @param length of the file. * @return true if yes else return false. */ private boolean canAdmitFile(final long length) { //order is important here boolean value = !isInPurgeMode() && (cache.canAdmitFile(length)); if (!value) { LOG.debug("cannot admit file of length=[{}] and currentSizeInBytes=[{}] ", length, cache.currentSizeInBytes); } return value; }
/** * Check if cache can admit file of given length. * @param length of the file. * @return true if yes else return false. */ private boolean canAdmitFile(final long length) { //order is important here boolean value = !isInPurgeMode() && (cache.canAdmitFile(length)); if (!value) { LOG.debug("cannot admit file of length=[{}] and currentSizeInBytes=[{}] ", length, cache.currentSizeInBytes); } return value; }
/** * Delete file from cache. Size of cache is reduced by file length. The * method is no-op if file doesn't exist in cache. * * @param fileName file name that need to be removed from cache. */ public void delete(String fileName) { if (isInPurgeMode()) { LOG.debug("purgeMode true :delete returned"); return; } fileName = fileName.replace("\\", "/"); cache.remove(fileName); }
@Override public Long put(final String fileName, final Long value) { if( isInPurgeMode()) { LOG.debug("cache is purge mode: put is no-op"); return null; } synchronized (this) { Long oldValue = cache.get(fileName); if (oldValue == null) { long flength = value.longValue(); currentSizeInBytes += flength; return super.put(fileName.replace("\\", "/"), value); } toBeDeleted.remove(fileName); return oldValue; } }
@Override public Long put(final String fileName, final Long value) { if( isInPurgeMode()) { LOG.debug("cache is purge mode: put is no-op"); return null; } synchronized (this) { Long oldValue = cache.get(fileName); if (oldValue == null) { long flength = value.longValue(); currentSizeInBytes += flength; return super.put(fileName.replace("\\", "/"), value); } toBeDeleted.remove(fileName); return oldValue; } }
@Override public Long put(final String fileName, final Long value) { if( isInPurgeMode()) { LOG.debug("cache is purge mode: put is no-op"); return null; } synchronized (this) { Long oldValue = cache.get(fileName); if (oldValue == null) { long flength = value.longValue(); currentSizeInBytes += flength; return super.put(fileName.replace("\\", "/"), value); } toBeDeleted.remove(fileName); return oldValue; } }
public File getFileIfStored(String fileName) throws IOException { fileName = fileName.replace("\\", "/"); File f = getFile(fileName); long diff = (System.currentTimeMillis() - cacheMissDuration.get()) / 1000; // logged at 5 minute interval minimum if (diff > 5 * 60) { LOG.info("local cache misses [{}] in [{}] sec", new Object[] { cacheMissCounter.getAndSet(0), diff }); cacheMissDuration.set(System.currentTimeMillis()); } // return file in purge mode = true and file present in asyncUploadCache // as asyncUploadCache's files will be not be deleted in cache purge. if (!f.exists() || (isInPurgeMode() && !asyncUploadCache.hasEntry(fileName, false))) { LOG.debug( "getFileIfStored returned: purgeMode=[{}], file=[{}] exists=[{}]", new Object[] { isInPurgeMode(), f.getAbsolutePath(), f.exists() }); cacheMissCounter.incrementAndGet(); return null; } else { // touch entry in LRU caches f.setLastModified(System.currentTimeMillis()); cache.get(fileName); return f; } }
public File getFileIfStored(String fileName) throws IOException { fileName = fileName.replace("\\", "/"); File f = getFile(fileName); long diff = (System.currentTimeMillis() - cacheMissDuration.get()) / 1000; // logged at 5 minute interval minimum if (diff > 5 * 60) { LOG.info("local cache misses [{}] in [{}] sec", new Object[] { cacheMissCounter.getAndSet(0), diff }); cacheMissDuration.set(System.currentTimeMillis()); } // return file in purge mode = true and file present in asyncUploadCache // as asyncUploadCache's files will be not be deleted in cache purge. if (!f.exists() || (isInPurgeMode() && !asyncUploadCache.hasEntry(fileName, false))) { LOG.debug( "getFileIfStored returned: purgeMode=[{}], file=[{}] exists=[{}]", new Object[] { isInPurgeMode(), f.getAbsolutePath(), f.exists() }); cacheMissCounter.incrementAndGet(); return null; } else { // touch entry in LRU caches f.setLastModified(System.currentTimeMillis()); cache.get(fileName); return f; } }
public File getFileIfStored(String fileName) throws IOException { fileName = fileName.replace("\\", "/"); File f = getFile(fileName); long diff = (System.currentTimeMillis() - cacheMissDuration.get()) / 1000; // logged at 5 minute interval minimum if (diff > 5 * 60) { LOG.info("local cache misses [{}] in [{}] sec", new Object[] { cacheMissCounter.getAndSet(0), diff }); cacheMissDuration.set(System.currentTimeMillis()); } // return file in purge mode = true and file present in asyncUploadCache // as asyncUploadCache's files will be not be deleted in cache purge. if (!f.exists() || (isInPurgeMode() && !asyncUploadCache.hasEntry(fileName, false))) { LOG.debug( "getFileIfStored returned: purgeMode=[{}], file=[{}] exists=[{}]", new Object[] { isInPurgeMode(), f.getAbsolutePath(), f.exists() }); cacheMissCounter.incrementAndGet(); return null; } else { // touch entry in LRU caches f.setLastModified(System.currentTimeMillis()); cache.get(fileName); return f; } }
/** * This method tries purging of local cache. It checks if local cache * has exceeded the defined limit then it triggers purge cache job in a * seperate thread. */ synchronized void tryPurge() { if (!isInPurgeMode() && cache.currentSizeInBytes > cache.cachePurgeTrigSize) { setPurgeMode(true); LOG.info( "cache.entries = [{}], currentSizeInBytes=[{}] exceeds cachePurgeTrigSize=[{}]", new Object[] { cache.size(), cache.currentSizeInBytes, cache.cachePurgeTrigSize }); new Thread(new PurgeJob()).start(); } else { LOG.debug( "currentSizeInBytes=[{}],cachePurgeTrigSize=[{}], isInPurgeMode =[{}]", new Object[] { cache.currentSizeInBytes, cache.cachePurgeTrigSize, isInPurgeMode() }); } }
/** * This method tries purging of local cache. It checks if local cache * has exceeded the defined limit then it triggers purge cache job in a * seperate thread. */ synchronized void tryPurge() { if (!isInPurgeMode() && cache.currentSizeInBytes > cache.cachePurgeTrigSize) { setPurgeMode(true); LOG.info( "cache.entries = [{}], currentSizeInBytes=[{}] exceeds cachePurgeTrigSize=[{}]", new Object[] { cache.size(), cache.currentSizeInBytes, cache.cachePurgeTrigSize }); new Thread(new PurgeJob()).start(); } else { LOG.debug( "currentSizeInBytes=[{}],cachePurgeTrigSize=[{}], isInPurgeMode =[{}]", new Object[] { cache.currentSizeInBytes, cache.cachePurgeTrigSize, isInPurgeMode() }); } }
/** * This method tries purging of local cache. It checks if local cache * has exceeded the defined limit then it triggers purge cache job in a * seperate thread. */ synchronized void tryPurge() { if (!isInPurgeMode() && cache.currentSizeInBytes > cache.cachePurgeTrigSize) { setPurgeMode(true); LOG.info( "cache.entries = [{}], currentSizeInBytes=[{}] exceeds cachePurgeTrigSize=[{}]", new Object[] { cache.size(), cache.currentSizeInBytes, cache.cachePurgeTrigSize }); new Thread(new PurgeJob()).start(); } else { LOG.debug( "currentSizeInBytes=[{}],cachePurgeTrigSize=[{}], isInPurgeMode =[{}]", new Object[] { cache.currentSizeInBytes, cache.cachePurgeTrigSize, isInPurgeMode() }); } }
File f = getFile(fileName); long length = 0; if (!f.exists() || isInPurgeMode()) { OutputStream out = null; File transFile = null;
do { Thread.sleep(1000); } while (cache.isInPurgeMode());