Skip to content
Snippets Groups Projects
Commit 0023d16c authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

ISS-1213: download of job data is not marked as done at start

parent af93c68f
No related branches found
No related tags found
1 merge request!34ISS-1213: download of job data is not marked as done at start
......@@ -69,6 +69,11 @@ import cz.it4i.fiji.haas_java_client.UploadingFile;
public class BenchmarkJobManager implements Closeable {
public interface DownloadingStatusProvider {
boolean isDownloaded();
boolean needsDownload();
}
private static Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.class);
......@@ -82,6 +87,18 @@ public class BenchmarkJobManager implements Closeable {
private boolean verifiedStateProcessed;
private CompletableFuture<JobState> running;
private ProgressNotifier downloadNotifier;
private DownloadingStatusProvider downloadingStatus = new DownloadingStatusProvider() {
@Override
public boolean needsDownload() {
return job.needsDownload();
}
@Override
public boolean isDownloaded() {
return job.isDownloaded();
}
};
private boolean visibleInBDV;
......@@ -221,7 +238,7 @@ public class BenchmarkJobManager implements Closeable {
}
public boolean needsDownload() {
return job.needsDownload();
return downloadingStatus.needsDownload();
}
public void setDownloadNotifier(Progress progress) {
......@@ -239,7 +256,7 @@ public class BenchmarkJobManager implements Closeable {
}
public boolean isDownloaded() {
return job.isDownloaded();
return downloadingStatus.isDownloaded();
}
public void resumeTransfer() {
......@@ -383,12 +400,16 @@ public class BenchmarkJobManager implements Closeable {
throws IOException
{
String mainFile = job.getProperty(SPIM_OUTPUT_FILENAME_PATTERN) + ".xml";
final ProgressNotifierTemporarySwitchOff notifierSwitch =
final StillRunningDownloadSwitcher stillRunningTemporarySwitch =
new StillRunningDownloadSwitcher(() -> downloadingStatus,
val -> downloadingStatus = val);
final ProgressNotifierTemporarySwitchOff progressNotifierTemporarySwitchOff =
new ProgressNotifierTemporarySwitchOff(downloadNotifier, job);
job.startDownload(downloadFileNameExtractDecorator(fileName -> fileName
.equals(mainFile))).whenComplete((X, E) -> {
notifierSwitch.switchOn();
.equals(mainFile))).exceptionally(__ -> {
progressNotifierTemporarySwitchOff.switchOn();
stillRunningTemporarySwitch.switchBack();
return null;
}).thenCompose(X -> {
Set<String> otherFiles = extractNames(getOutputDirectory().resolve(
mainFile));
......@@ -399,7 +420,10 @@ public class BenchmarkJobManager implements Closeable {
catch (IOException e) {
throw new RuntimeException(e);
}
finally {
progressNotifierTemporarySwitchOff.switchOn();
stillRunningTemporarySwitch.switchBack();
}
}).whenComplete((X, e) -> {
if (e != null) {
log.error(e.getMessage(), e);
......
package cz.it4i.fiji.haas_spim_benchmark.core;
import cz.it4i.fiji.haas.Job;
import cz.it4i.fiji.haas.ui.DummyProgress;
import cz.it4i.fiji.haas_java_client.ProgressNotifier;
public class ProgressNotifierTemporarySwitchOff {
private ProgressNotifier notifier;
private ProgressNotifier innerProgressNotifier = new ProgressNotifier() {
@Override
public void setTitle(String title) {
notifier.setTitle(title);
}
@Override
public void setItemCount(int count, int total) {
//none
}
@Override
public void setCount(int count, int total) {
//none
}
@Override
public void itemDone(Object item) {
notifier.itemDone(item);
}
@Override
public void done() {
//none
}
@Override
public void addItem(Object item) {
notifier.addItem(item);
}
};
private final Job job;
public ProgressNotifierTemporarySwitchOff(ProgressNotifier downloadNotifier, Job job) {
this.notifier = downloadNotifier;
this.job = job;
if(this.notifier != null) {
job.setDownloadNotifier(new ProgressNotifierAdapter(new DummyProgress()));
job.setDownloadNotifier(innerProgressNotifier);
}
}
......
package cz.it4i.fiji.haas_spim_benchmark.core;
import java.util.function.Consumer;
import java.util.function.Supplier;
import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.DownloadingStatusProvider;
public class StillRunningDownloadSwitcher {
private final DownloadingStatusProvider originalProvider;
private final Consumer<DownloadingStatusProvider> setter;
private final DownloadingStatusProvider providerReportingStillRunning = new DownloadingStatusProvider() {
@Override
public boolean needsDownload() {
return true;
}
@Override
public boolean isDownloaded() {
return false;
}
};
public StillRunningDownloadSwitcher(Supplier<DownloadingStatusProvider> getter, Consumer<DownloadingStatusProvider> setter) {
originalProvider = getter.get();
this.setter = setter;
setter.accept(providerReportingStillRunning);
}
synchronized public void switchBack() {
setter.accept(originalProvider);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment