diff --git a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java index c065cc4fa8b7713c1eaaead0fa6fcaaa844d5a29..4400f06b8ea443349ceaad7a4347001cf740e22c 100644 --- a/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java +++ b/haas-imagej-client/src/main/java/cz/it4i/fiji/haas/Job.java @@ -45,6 +45,10 @@ public class Job { private static final String JOB_NEEDS_DOWNLOAD = "job.needs_download"; private static final String JOB_CAN_BE_DOWNLOADED = "job.needs_download"; + + private static final String JOB_IS_DOWNLOADED = "job.downloaded"; + + private static final String JOB_IS_UPLOADED = "job.uploaded"; public static boolean isJobPath(Path p) { return isValidPath(p); @@ -144,6 +148,22 @@ public class Job { return Boolean.parseBoolean(getProperty(JOB_CAN_BE_DOWNLOADED)); } + public void setUploaded(boolean b) { + setProperty(JOB_IS_UPLOADED, b); + } + + public void setDownloaded(boolean b) { + setProperty(JOB_IS_DOWNLOADED, b); + } + + public boolean isUploaded() { + return getSafeBoolean(getProperty(JOB_IS_UPLOADED)); + } + + public boolean isDownloaded() { + return getSafeBoolean(getProperty(JOB_IS_DOWNLOADED)); + } + public void uploadFile(String file, ProgressNotifier notifier) { uploadFiles(Arrays.asList(file), notifier); } @@ -314,6 +334,10 @@ public class Job { synchronization.setUploadNotifier(notifier); } + private boolean getSafeBoolean(String value) { + return value != null ? Boolean.parseBoolean(value) : false; + } + private void setJobDirectory(Path jobDirectory) { this.jobDir = jobDirectory; try { @@ -321,7 +345,9 @@ public class Job { ()->startFileTransfer(HaaSClient.DUMMY_TRANSFER_FILE_PROGRESS), jobDir, Executors.newFixedThreadPool(2), () -> { setProperty(JOB_NEEDS_UPLOAD, false); + setUploaded(true); }, () -> { + setDownloaded(true); setProperty(JOB_NEEDS_DOWNLOAD, false); setCanBeDownloaded(false); }); @@ -331,6 +357,8 @@ public class Job { } } + + private HaaSFileTransfer startFileTransfer( TransferFileProgress progress) { return haasClientSupplier.get().startFileTransfer(getId(), progress); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java index 854a70af1130a048e5d34aa9cd76d7d9b9299491..a19610bbce1a5b9e512796b8399b82c325d80925 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java @@ -58,6 +58,7 @@ public class BenchmarkJobManager { public final class BenchmarkJob implements HaaSOutputHolder { private final Job job; + private final List<Task> tasks; private final List<BenchmarkError> nonTaskSpecificErrors; private final SPIMComputationAccessor computationAccessor; @@ -417,6 +418,22 @@ public class BenchmarkJobManager { Stream<BenchmarkError> taskSpecificErrors = tasks.stream().flatMap(s -> s.getErrors().stream()); return Stream.concat(nonTaskSpecificErrors.stream(), taskSpecificErrors).collect(Collectors.toList()); } + + public void setDownloaded(Boolean val) { + job.setDownloaded(val); + } + + public void setUploaded(boolean b) { + job.setUploaded(b); + } + + public boolean isDownloaded() { + return job.isDownloaded(); + } + + public boolean isUploaded() { + return job.isUploaded(); + } } public BenchmarkJobManager(BenchmarkSPIMParameters params) throws IOException { diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/UpdatableBenchmarkJob.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/UpdatableBenchmarkJob.java index 51e9dceb5a605c4f3024582125fecb85a3eaee00..4c55ae3af44496e0687f63f6078d4c0d40788e6d 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/UpdatableBenchmarkJob.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/UpdatableBenchmarkJob.java @@ -1,7 +1,9 @@ package cz.it4i.fiji.haas_spim_benchmark.core; import java.util.concurrent.Executor; +import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Supplier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,71 +12,80 @@ import cz.it4i.fiji.haas.ui.UpdatableObservableValue; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; import net.imagej.updater.util.Progress; -public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob>{ +public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob> { public static final Logger log = LoggerFactory .getLogger(cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.class); - - private P_TransferProgress downloadProgress = new P_TransferProgress(); - private P_TransferProgress uploadProgress = new P_TransferProgress(); + + private P_TransferProgress downloadProgress = new P_TransferProgress(val -> getValue().setDownloaded(val), + () -> getValue().isDownloaded()); + private P_TransferProgress uploadProgress = new P_TransferProgress(val -> getValue().setUploaded(val), + () -> getValue().isUploaded()); private Executor executor; + public interface TransferProgress { - + public Long getRemainingSeconds(); - + public boolean isDone(); - + public boolean isWorking(); - + public Float getRemainingPercents(); } - + public UpdatableBenchmarkJob(BenchmarkJob wrapped, Function<BenchmarkJob, UpdateStatus> updateFunction, Function<BenchmarkJob, Object> stateProvider, Executor executorUI) { super(wrapped, updateFunction, stateProvider); - + wrapped.setDownloadNotifier(downloadProgress); wrapped.setUploadNotifier(uploadProgress); wrapped.resumeTransfer(); this.executor = executorUI; } - + public TransferProgress getDownloadProgress() { return downloadProgress; } - + public TransferProgress getUploadProgress() { return uploadProgress; } - + public void removed() { getValue().setDownloadNotifier(null); } - + @Override protected void fireValueChangedEvent() { executor.execute(() -> super.fireValueChangedEvent()); } - - + private class P_TransferProgress implements Progress, TransferProgress { private boolean working; - private boolean done; + // private boolean done; private long start; private Long remainingSeconds; private Float remainingPercents; - + private Supplier<Boolean> doneStatusSupplier; + private Consumer<Boolean> doneStatusConsumer; + + public P_TransferProgress(Consumer<Boolean> doneStatusConsumer, Supplier<Boolean> doneStatusSupplier) { + this.doneStatusConsumer = doneStatusConsumer; + this.doneStatusSupplier = doneStatusSupplier; + } + @Override public synchronized void setCount(int count, int total) { - if(total < -1) { + if (total < -1) { working = false; remainingSeconds = null; remainingPercents = null; } else { long delta = System.currentTimeMillis() - start; remainingSeconds = (long) ((double) delta / count * (total - count)) / 1000; - remainingPercents = (((float)total - count) / total * 100); + remainingPercents = (((float) total - count) / total * 100); } fireValueChangedEvent(); } @@ -82,17 +93,17 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob @Override public synchronized void addItem(Object item) { if (!working) { - done = false; + setDone(false); working = true; start = System.currentTimeMillis(); } fireValueChangedEvent(); } - + @Override public synchronized void done() { if (working) { - done = true; + setDone(true); } working = false; remainingSeconds = 0l; @@ -100,11 +111,6 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob fireValueChangedEvent(); } - @Override - public synchronized boolean isDone() { - return done; - } - @Override public synchronized boolean isWorking() { return working; @@ -119,7 +125,7 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob public synchronized Float getRemainingPercents() { return remainingPercents; } - + @Override public void setItemCount(int count, int total) { } @@ -127,12 +133,19 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob @Override public void itemDone(Object item) { } - + @Override public void setTitle(String title) { } - + @Override + public boolean isDone() { + return doneStatusSupplier.get(); + } + + private void setDone(boolean val) { + doneStatusConsumer.accept(val); + } } }