private void updateCache(String fsId, List<String> fhirBundles) throws CacheException { // fetchStatusService.setCaching(fsId); for (String xml : fhirBundles) { logger.trace("will put in cache:" + xml); cache.put(xml); } }
@Override public String getData(String fullUri) throws FetcherException { List<String> fhirBundles = null; String cacheResponse = null; FetchRequest req = new FetchRequest(fullUri); String fsId = req.genId(); try { // wait for fetchStatus to unlock // if (1 == 1) // return fetchStatusService.getFetchStatus(fsId).toString(); while (isFetchStatusLocked(fsId)) { try { Thread.sleep(SLEEP_DURATION); logger.trace("in while loop"); // return getData(fullUri); } catch (InterruptedException e) { throw new FetcherException(e.getMessage(), e); } } fetchStatusService.setFetching(fsId); // lock fetchStatus // Date lastFetchDT = fetchStatusService.getLastFetchDT(fsId); Date lastCacheUpdateDT = fetchStatusService.getLastCacheUpdateDT(fsId); if (lastCacheUpdateDT != null) { req.setStartDate(lastCacheUpdateDT); logger.debug("lastCacheUPdateDT:" + lastCacheUpdateDT.toString()); } else { logger.debug("lastCacheUPdateDT is null"); } // if ((lastFetchDT==null)|| // lastCacheUpdateDT==null|| // ((lastCacheUpdateDT.getTime() - lastFetchDT.getTime()) > // CACHE_DELAY) // ) { // retrieve delta // Thread.sleep(15000); try { fhirBundles = fetchData(req); logger.debug("fhirBundleXml:" + fhirBundles); } catch (ConverterException e) { logger.error(">>>" + e.getMessage(), e); } // } // find last update date of cache // update cache // return data from cache updateCache(fsId, fhirBundles); cacheResponse = cache.get(req); } catch (Exception e) { fetchStatusService.setUnlocked(fsId); throw new FetcherException(e.getMessage(), e); } fetchStatusService.setUnlocked(fsId); return cacheResponse; }