@Test public void testAvailableCache() throws Exception { FileServer server = new FileServer(); server.start(); String uri = server.getUri("/dtd/web-app_2_3.dtd"); try { cacheResourcesManager.getResource(uri); fail("cacheResourcesManager should be busy downloading the url"); } catch (CacheResourceDownloadingException ignored) { } TimeUnit.MILLISECONDS.sleep(200); assertNotNull(cacheResourcesManager.getResource(uri)); server.stop(); TimeUnit.SECONDS.sleep(1); assertNotNull(cacheResourcesManager.getResource(uri)); }
public Path getResource(final String resourceURI) throws IOException { Path resourceCachePath = getResourceCachePath(resourceURI); if (Files.exists(resourceCachePath)) { return resourceCachePath; } if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) { throw new CacheResourceDownloadingException(resourceURI); } if (unavailableURICache.getIfPresent(resourceURI) != null) { LOGGER.info("Ignored unavailable schema URI: " + resourceURI + "\n"); return null; } CompletableFuture<Path> f = null; synchronized (resourcesLoading) { if (resourcesLoading.containsKey(resourceURI)) { CompletableFuture<Path> future = resourcesLoading.get(resourceURI); throw new CacheResourceDownloadingException(resourceURI, future); } f = downloadResource(resourceURI, resourceCachePath); resourcesLoading.put(resourceURI, f); } if (f.getNow(null) == null) { throw new CacheResourceDownloadingException(resourceURI, f); } return resourceCachePath; }
CacheResourcesManager { public Path getResource(final String resourceURI) throws IOException { Path resourceCachePath = getResourceCachePath(resourceURI); if (Files.exists(resourceCachePath)) { return resourceCachePath; } if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) { throw new CacheResourceDownloadingException(resourceURI); } if (unavailableURICache.getIfPresent(resourceURI) != null) { LOGGER.info("Ignored unavailable schema URI: " + resourceURI + "\n"); return null; } CompletableFuture<Path> f = null; synchronized (resourcesLoading) { if (resourcesLoading.containsKey(resourceURI)) { CompletableFuture<Path> future = resourcesLoading.get(resourceURI); throw new CacheResourceDownloadingException(resourceURI, future); } f = downloadResource(resourceURI, resourceCachePath); resourcesLoading.put(resourceURI, f); } if (f.getNow(null) == null) { throw new CacheResourceDownloadingException(resourceURI, f); } return resourceCachePath; } }
CacheResourcesManager { public Path getResource(final String resourceURI) throws IOException { Path resourceCachePath = getResourceCachePath(resourceURI); if (Files.exists(resourceCachePath)) { return resourceCachePath; } if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) { throw new CacheResourceDownloadingException(resourceURI); } if (unavailableURICache.getIfPresent(resourceURI) != null) { LOGGER.info("Ignored unavailable schema URI: " + resourceURI + "\n"); return null; } CompletableFuture<Path> f = null; synchronized (resourcesLoading) { if (resourcesLoading.containsKey(resourceURI)) { CompletableFuture<Path> future = resourcesLoading.get(resourceURI); throw new CacheResourceDownloadingException(resourceURI, future); } f = downloadResource(resourceURI, resourceCachePath); resourcesLoading.put(resourceURI, f); } if (f.getNow(null) == null) { throw new CacheResourceDownloadingException(resourceURI, f); } return resourceCachePath; } CacheResourcesManager();  CacheResourcesManager(Cache<String, Boolean> cache); }
CacheResourcesManager { public Path getResource(final String resourceURI) throws IOException { Path resourceCachePath = getResourceCachePath(resourceURI); if (Files.exists(resourceCachePath)) { return resourceCachePath; } if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) { throw new CacheResourceDownloadingException(resourceURI); } if (unavailableURICache.getIfPresent(resourceURI) != null) { LOGGER.info("Ignored unavailable schema URI: " + resourceURI + "\n"); return null; } CompletableFuture<Path> f = null; synchronized (resourcesLoading) { if (resourcesLoading.containsKey(resourceURI)) { CompletableFuture<Path> future = resourcesLoading.get(resourceURI); throw new CacheResourceDownloadingException(resourceURI, future); } f = downloadResource(resourceURI, resourceCachePath); resourcesLoading.put(resourceURI, f); } if (f.getNow(null) == null) { throw new CacheResourceDownloadingException(resourceURI, f); } return resourceCachePath; } CacheResourcesManager();  CacheResourcesManager(Cache<String, Boolean> cache); Path getResource(final String resourceURI); static Path getResourceCachePath(String resourceURI); static Path getResourceCachePath(URI uri); static Path getResourceCachePath(ResourceToDeploy resource); boolean canUseCache(String url); void setUseCache(boolean useCache); boolean isUseCache(); }
CacheResourcesManager { public Path getResource(final String resourceURI) throws IOException { Path resourceCachePath = getResourceCachePath(resourceURI); if (Files.exists(resourceCachePath)) { return resourceCachePath; } if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) { throw new CacheResourceDownloadingException(resourceURI); } if (unavailableURICache.getIfPresent(resourceURI) != null) { LOGGER.info("Ignored unavailable schema URI: " + resourceURI + "\n"); return null; } CompletableFuture<Path> f = null; synchronized (resourcesLoading) { if (resourcesLoading.containsKey(resourceURI)) { CompletableFuture<Path> future = resourcesLoading.get(resourceURI); throw new CacheResourceDownloadingException(resourceURI, future); } f = downloadResource(resourceURI, resourceCachePath); resourcesLoading.put(resourceURI, f); } if (f.getNow(null) == null) { throw new CacheResourceDownloadingException(resourceURI, f); } return resourceCachePath; } CacheResourcesManager();  CacheResourcesManager(Cache<String, Boolean> cache); Path getResource(final String resourceURI); static Path getResourceCachePath(String resourceURI); static Path getResourceCachePath(URI uri); static Path getResourceCachePath(ResourceToDeploy resource); boolean canUseCache(String url); void setUseCache(boolean useCache); boolean isUseCache();  }