Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sclassen committed Apr 21, 2021
1 parent cb69084 commit dd52b91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private void waitForCompletion(Resource... resources) {
final int threadCount = Math.min(configuredThreadCount, resources.length);
final ExecutorService downloadExecutor = Executors.newFixedThreadPool(threadCount, new DaemonThreadFactory());
try {
final List<Future<Resource>> futures = Arrays.asList(resources).stream()
final List<Future<Resource>> futures = Arrays.stream(resources)
.map(r -> triggerDownloadFor(r, downloadExecutor))
.collect(Collectors.toList());

Expand All @@ -397,9 +397,10 @@ private void waitForCompletion(Resource... resources) {
LOG.debug("Download done. Shutting down executor");
downloadExecutor.shutdownNow();
}
if (resources.length == 1 && resources[0].isSet(Status.ERROR))

if (resources.length == 1 && resources[0].isSet(Status.ERROR)) {
throw new RuntimeException("Error while downloading initial resource " + resources[0]);
}
}

private Future<Resource> triggerDownloadFor(Resource resource, final Executor downloadExecutor) {
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/java/net/sourceforge/jnlp/cache/CacheUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,29 @@ public static String hex(String origName, String candidate) throws NoSuchAlgorit
* @param title name of the download
*/
public static void waitForResources(final JNLPClassLoader jnlpClassLoader, final ResourceTracker tracker, final URL[] resources, final String title) {
// download first initial jar : so in case of client certificate, only 1 https client handshake is done
// download first initial jar : so in case of client certificate, only 1 https client handshake is done
boolean downloadInitialJarFirst = resources.length > 1 && resources[0].getProtocol().equals("https");
try {
final DownloadIndicator indicator = Optional.ofNullable(JNLPRuntime.getDefaultDownloadIndicator())
.orElseGet(() -> new DummyDownloadIndicator());
.orElseGet(DummyDownloadIndicator::new);
final DownloadServiceListener listener = getDownloadServiceListener(jnlpClassLoader, title, resources, indicator);
try {
for (URL url : resources) {
tracker.addDownloadListener(url, resources, listener);
}
if (downloadInitialJarFirst)
if (downloadInitialJarFirst) {
tracker.waitForResources(resources[0]);
}
// download all remaining ones
tracker.waitForResources(resources);
} finally {
indicator.disposeListener(listener);
}
} catch (Exception ex) {
LOG.error("Downloading of resources ended with error", ex);
if (downloadInitialJarFirst)
throw new RuntimeException(ex);
if (downloadInitialJarFirst) {
throw new RuntimeException(ex);
}
}
}

Expand Down

0 comments on commit dd52b91

Please sign in to comment.