File dest = getFile(fileName); File parent = dest.getParentFile(); AsyncUploadCacheResult result = new AsyncUploadCacheResult(); result.setFile(src); result.setAsyncUpload(false); boolean destExists = false; if ((destExists = dest.exists()) result.setFile(dest); if (tryForAsyncUpload) { result.setAsyncUpload(asyncUploadCache.add(fileName).canAsyncUpload());
/** * Store an item along with file in cache. Cache size is increased by * {@link File#length()} If file already exists in cache, * {@link File#setLastModified(long)} is updated with current time. * * @param fileName the key of cache. * @param src file to be added to cache. */ public File store(String fileName, final File src) { try { return store(fileName, src, false).getFile(); } catch (IOException ioe) { LOG.warn("Exception in addding file [" + fileName + "] to local cache.", ioe); } return null; }
/** * This methods removes file (if found) from {@link #asyncUploadMap}. If * file is found, it immediately serializes the {@link #asyncUploadMap} to * disk. This method sets * {@link AsyncUploadCacheResult#setRequiresDelete(boolean)} to true, if * asynchronous upload found to be in {@link #toBeDeleted} set i.e. marked * for delete. */ public synchronized AsyncUploadCacheResult remove(String fileName) throws IOException { long startTime = System.currentTimeMillis(); Long retVal = asyncUploadMap.remove(fileName); if (retVal != null) { serializeAsyncUploadMap(); LOG.debug("removed file [{}] from asyncUploadMap took [{}] sec", fileName, ((System.currentTimeMillis() - startTime) / 1000)); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); } else { LOG.debug("cannot removed file [{}] from asyncUploadMap took [{}] sec. File not found.", fileName, ((System.currentTimeMillis() - startTime) / 1000)); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); } AsyncUploadCacheResult result = new AsyncUploadCacheResult(); result.setRequiresDelete(toBeDeleted.contains(fileName)); return result; }
AsyncUploadCacheResult result = new AsyncUploadCacheResult(); if (asyncUploadMap.entrySet().size() >= asyncUploadLimit) { LOG.info( LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); result.setAsyncUpload(false); } else { long startTime = System.currentTimeMillis(); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); result.setAsyncUpload(true);
(System.currentTimeMillis() - currTime)); if (result != null) { if (result.canAsyncUpload()) { backend.writeAsync(identifier, result.getFile(), this); } else { backend.write(identifier, result.getFile());
AsyncUploadCacheResult result = cache.store("a1", f, true); assertTrue("should be able to add to pending upload", result.canAsyncUpload()); result = cache.store("a2", f, true); assertTrue("should be able to add to pending upload", result.canAsyncUpload()); result = cache.store("a3", f, true); assertTrue("should be able to add to pending upload", result.canAsyncUpload()); result.canAsyncUpload()); Thread.sleep(1000);
@Override public void onSuccess(AsyncUploadResult result) { DataIdentifier identifier = result.getIdentifier(); File file = result.getFile(); String fileName = getFileName(identifier); try { LOG.debug("Upload completed for [{}]", identifier); // remove from failed upload map if any. uploadRetryMap.remove(identifier); AsyncUploadCacheResult cachedResult = asyncWriteCache.remove(fileName); if (cachedResult.doRequiresDelete()) { // added record already marked for delete deleteRecord(identifier); } else { // async upload took lot of time. // getRecord to touch if required. getRecord(identifier); } } catch (IOException ie) { LOG.warn("Cannot remove pending file upload. Dataidentifer [ " + identifier + "], file [" + file.getAbsolutePath() + "]", ie); } catch (DataStoreException dse) { LOG.warn("Cannot remove pending file upload. Dataidentifer [ " + identifier + "], file [" + file.getAbsolutePath() + "]", dse); } }
(System.currentTimeMillis() - currTime)); if (result != null) { if (result.canAsyncUpload()) { backend.writeAsync(identifier, result.getFile(), this); } else { backend.write(identifier, result.getFile());
AsyncUploadCacheResult result = new AsyncUploadCacheResult(); if (asyncUploadMap.entrySet().size() >= asyncUploadLimit) { LOG.info( LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); result.setAsyncUpload(false); } else { long startTime = System.currentTimeMillis(); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); result.setAsyncUpload(true);
@Override public void onSuccess(AsyncUploadResult result) { DataIdentifier identifier = result.getIdentifier(); File file = result.getFile(); String fileName = getFileName(identifier); try { LOG.debug("Upload completed for [{}]", identifier); // remove from failed upload map if any. uploadRetryMap.remove(identifier); AsyncUploadCacheResult cachedResult = asyncWriteCache.remove(fileName); if (cachedResult.doRequiresDelete()) { // added record already marked for delete deleteRecord(identifier); } else { // async upload took lot of time. // getRecord to touch if required. getRecord(identifier); } } catch (IOException ie) { LOG.warn("Cannot remove pending file upload. Dataidentifer [ " + identifier + "], file [" + file.getAbsolutePath() + "]", ie); } catch (DataStoreException dse) { LOG.warn("Cannot remove pending file upload. Dataidentifer [ " + identifier + "], file [" + file.getAbsolutePath() + "]", dse); } }
File dest = getFile(fileName); File parent = dest.getParentFile(); AsyncUploadCacheResult result = new AsyncUploadCacheResult(); result.setFile(src); result.setAsyncUpload(false); boolean destExists = false; if ((destExists = dest.exists()) result.setFile(dest); if (tryForAsyncUpload) { result.setAsyncUpload(asyncUploadCache.add(fileName).canAsyncUpload());
(System.currentTimeMillis() - currTime)); if (result != null) { if (result.canAsyncUpload()) { backend.writeAsync(identifier, result.getFile(), this); } else { backend.write(identifier, result.getFile());
/** * This methods removes file (if found) from {@link #asyncUploadMap}. If * file is found, it immediately serializes the {@link #asyncUploadMap} to * disk. This method sets * {@link AsyncUploadCacheResult#setRequiresDelete(boolean)} to true, if * asynchronous upload found to be in {@link #toBeDeleted} set i.e. marked * for delete. */ public synchronized AsyncUploadCacheResult remove(String fileName) throws IOException { long startTime = System.currentTimeMillis(); Long retVal = asyncUploadMap.remove(fileName); if (retVal != null) { serializeAsyncUploadMap(); LOG.debug("removed file [{}] from asyncUploadMap took [{}] sec", fileName, ((System.currentTimeMillis() - startTime) / 1000)); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); } else { LOG.debug("cannot removed file [{}] from asyncUploadMap took [{}] sec. File not found.", fileName, ((System.currentTimeMillis() - startTime) / 1000)); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); } AsyncUploadCacheResult result = new AsyncUploadCacheResult(); result.setRequiresDelete(toBeDeleted.contains(fileName)); return result; }
AsyncUploadCacheResult result = new AsyncUploadCacheResult(); if (asyncUploadMap.entrySet().size() >= asyncUploadLimit) { LOG.info( LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); result.setAsyncUpload(false); } else { long startTime = System.currentTimeMillis(); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); result.setAsyncUpload(true);
/** * Store an item along with file in cache. Cache size is increased by * {@link File#length()} If file already exists in cache, * {@link File#setLastModified(long)} is updated with current time. * * @param fileName the key of cache. * @param src file to be added to cache. */ public File store(String fileName, final File src) { try { return store(fileName, src, false).getFile(); } catch (IOException ioe) { LOG.warn("Exception in addding file [" + fileName + "] to local cache.", ioe); } return null; }
@Override public void onSuccess(AsyncUploadResult result) { DataIdentifier identifier = result.getIdentifier(); File file = result.getFile(); String fileName = getFileName(identifier); try { LOG.debug("Upload completed for [{}]", identifier); // remove from failed upload map if any. uploadRetryMap.remove(identifier); AsyncUploadCacheResult cachedResult = asyncWriteCache.remove(fileName); if (cachedResult.doRequiresDelete()) { // added record already marked for delete deleteRecord(identifier); } else { // async upload took lot of time. // getRecord to touch if required. getRecord(identifier); } } catch (IOException ie) { LOG.warn("Cannot remove pending file upload. Dataidentifer [ " + identifier + "], file [" + file.getAbsolutePath() + "]", ie); } catch (DataStoreException dse) { LOG.warn("Cannot remove pending file upload. Dataidentifer [ " + identifier + "], file [" + file.getAbsolutePath() + "]", dse); } }
File dest = getFile(fileName); File parent = dest.getParentFile(); AsyncUploadCacheResult result = new AsyncUploadCacheResult(); result.setFile(src); result.setAsyncUpload(false); boolean destExists = false; if ((destExists = dest.exists()) result.setFile(dest); if (tryForAsyncUpload) { result.setAsyncUpload(asyncUploadCache.add(fileName).canAsyncUpload());
/** * This methods removes file (if found) from {@link #asyncUploadMap}. If * file is found, it immediately serializes the {@link #asyncUploadMap} to * disk. This method sets * {@link AsyncUploadCacheResult#setRequiresDelete(boolean)} to true, if * asynchronous upload found to be in {@link #toBeDeleted} set i.e. marked * for delete. */ public synchronized AsyncUploadCacheResult remove(String fileName) throws IOException { long startTime = System.currentTimeMillis(); Long retVal = asyncUploadMap.remove(fileName); if (retVal != null) { serializeAsyncUploadMap(); LOG.debug("removed file [{}] from asyncUploadMap took [{}] sec", fileName, ((System.currentTimeMillis() - startTime) / 1000)); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); } else { LOG.debug("cannot removed file [{}] from asyncUploadMap took [{}] sec. File not found.", fileName, ((System.currentTimeMillis() - startTime) / 1000)); LOG.debug("AsyncUploadCache size=[{}] and entries =[{}]", asyncUploadMap.size(), asyncUploadMap.keySet()); } AsyncUploadCacheResult result = new AsyncUploadCacheResult(); result.setRequiresDelete(toBeDeleted.contains(fileName)); return result; }
/** * Store an item along with file in cache. Cache size is increased by * {@link File#length()} If file already exists in cache, * {@link File#setLastModified(long)} is updated with current time. * * @param fileName the key of cache. * @param src file to be added to cache. */ public File store(String fileName, final File src) { try { return store(fileName, src, false).getFile(); } catch (IOException ioe) { LOG.warn("Exception in addding file [" + fileName + "] to local cache.", ioe); } return null; }