Skip to content

Commit

Permalink
use jars pre determined sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Jan 8, 2025
1 parent ea99953 commit be6e46d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.stream.Collectors;

import io.bioimage.modelrunner.engine.installation.EngineInstall;
import io.bioimage.modelrunner.versionmanagement.JarInfo;

/**
* Class that contains the methods to track the progress downloading files.
Expand Down Expand Up @@ -136,14 +137,15 @@ private DownloadTracker(String folder, TwoParameterConsumer<String, Double> cons
this.parentThread = Thread.currentThread();
this.folder = folder;
sizeFiles = new LinkedHashMap<String, Long>();
JarInfo jarInfo = JarInfo.getInstance();
for (String link : links) {
String key = folder + File.separator + DownloadModel.getFileNameFromURLString(link);
if (consumer.get().get(key + EngineInstall.NBYTES_SUFFIX) != null && consumer.get().get(key + EngineInstall.NBYTES_SUFFIX) != -1) {
sizeFiles.put(key, consumer.get().get(key + EngineInstall.NBYTES_SUFFIX).longValue());
continue;
}
try {
sizeFiles.put(key, DownloadModel.getFileSize(new URL(link)));
sizeFiles.put(key, (jarInfo.get(link) != null ? jarInfo.get(link) : DownloadModel.getFileSize(new URL(link))));
} catch (MalformedURLException e) {
throw new IOException("The URL '" + link + "' cannot be found.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import io.bioimage.modelrunner.versionmanagement.AvailableEngines;
import io.bioimage.modelrunner.versionmanagement.DeepLearningVersion;
import io.bioimage.modelrunner.versionmanagement.InstalledEngines;
import io.bioimage.modelrunner.versionmanagement.JarInfo;

/**
* Class that manages the dl-modelrunner engines.
Expand Down Expand Up @@ -596,13 +597,14 @@ public long getBasicDownloadTotalSize() throws InterruptedException {
long totalSize = 0;
for (Entry<String, String> ee : missingEngineFolders.entrySet()) {
try {
JarInfo jarInfo = JarInfo.getInstance();
long engineSize = 0;
DeepLearningVersion dlVersion = DeepLearningVersion.fromFile(new File(ee.getValue()));
for (String link : dlVersion.getJars()) {
if (Thread.currentThread().isInterrupted())
throw new InterruptedException("Retrieval of download size interrupted.");
String key = ee.getValue() + File.separator + DownloadModel.getFileNameFromURLString(link) + NBYTES_SUFFIX;
long val = DownloadModel.getFileSize(new URL(link));
long val = jarInfo.get(link) != null ? jarInfo.get(link) : DownloadModel.getFileSize(new URL(link));
this.consumersMap.get(ee.getValue()).accept(key, (double) val);
engineSize += val;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static JarInfo getInstance() throws IOException {
*
* @return Map containing the URL and their respective sizes
*/
public Map<String, Long> getUrlData() {
public Map<String, Long> getAllData() {
return urlData;
}

Expand All @@ -49,7 +49,7 @@ public Map<String, Long> getUrlData() {
* @param url The URL to look up
* @return The size associated with the URL, or null if not found
*/
public Long getSizeForUrl(String url) {
public Long get(String url) {
return urlData.get(url);
}

Expand Down

0 comments on commit be6e46d

Please sign in to comment.