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 2e4a1aa1f0900d8b6fc4b261582336816a74e5ef..51e9dceb5a605c4f3024582125fecb85a3eaee00 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,5 +1,6 @@ package cz.it4i.fiji.haas_spim_benchmark.core; +import java.util.concurrent.Executor; import java.util.function.Function; import org.slf4j.Logger; @@ -14,50 +15,60 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob public static final Logger log = LoggerFactory .getLogger(cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.class); - private P_DownloadProgress downloadProgress = new P_DownloadProgress(); - + private P_TransferProgress downloadProgress = new P_TransferProgress(); + private P_TransferProgress uploadProgress = new P_TransferProgress(); + private Executor executor; public interface TransferProgress { public Long getRemainingSeconds(); - public boolean isDownloaded(); + public boolean isDone(); - public boolean isDonwloadind(); + public boolean isWorking(); public Float getRemainingPercents(); } public UpdatableBenchmarkJob(BenchmarkJob wrapped, Function<BenchmarkJob, UpdateStatus> updateFunction, - Function<BenchmarkJob, Object> stateProvider) { + 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_DownloadProgress implements Progress, TransferProgress { + private class P_TransferProgress implements Progress, TransferProgress { - private boolean downloading; - private boolean downloaded; + private boolean working; + private boolean done; private long start; private Long remainingSeconds; private Float remainingPercents; - @Override - public void setTitle(String title) { - } - @Override public synchronized void setCount(int count, int total) { - if(total < -1) { - downloading = false; + working = false; remainingSeconds = null; remainingPercents = null; } else { @@ -69,43 +80,43 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob } @Override - public void addItem(Object item) { - if (!downloading) { - downloaded = false; - downloading = true; + public synchronized void addItem(Object item) { + if (!working) { + done = false; + working = true; start = System.currentTimeMillis(); } fireValueChangedEvent(); } @Override - public void done() { - if (downloading) { - downloaded = true; + public synchronized void done() { + if (working) { + done = true; } - downloading = false; + working = false; remainingSeconds = 0l; remainingPercents = 0.f; fireValueChangedEvent(); } @Override - public boolean isDownloaded() { - return downloaded; + public synchronized boolean isDone() { + return done; } @Override - public boolean isDonwloadind() { - return downloading; + public synchronized boolean isWorking() { + return working; } @Override - public Long getRemainingSeconds() { + public synchronized Long getRemainingSeconds() { return remainingSeconds; } @Override - public Float getRemainingPercents() { + public synchronized Float getRemainingPercents() { return remainingPercents; } @@ -116,7 +127,12 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob @Override public void itemDone(Object item) { } + + @Override + public void setTitle(String title) { + } + } } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml index 25ad67bc7ad709ac4e560d30973dfd0b1453fe24..a40b9568427fe8460d812f9702b647f5a7345f95 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIM.fxml @@ -12,14 +12,15 @@ <HBox> <children> - <TableView fx:id="jobs" prefHeight="400.0" prefWidth="1065.0" HBox.hgrow="ALWAYS"> + <TableView fx:id="jobs" prefHeight="400.0" prefWidth="1410.0" HBox.hgrow="ALWAYS"> <columns> - <TableColumn prefWidth="75.0" text="Job Id" /> + <TableColumn prefWidth="70.0" text="Job Id" /> <TableColumn prefWidth="149.0" text="Status" /> <TableColumn prefWidth="230.0" text="Creation time" /> <TableColumn prefWidth="230.0" text="Start time" /> <TableColumn prefWidth="230.0" text="End Time" /> - <TableColumn prefWidth="150.0" text="Upload" /> + <TableColumn prefWidth="250.0" text="Upload" /> + <TableColumn prefWidth="250.0" text="Download" /> </columns> </TableView> </children> diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java index a2938a0c4cd549aa43c8e6d843c3705a63fad351..0470a0fa9e9e12984872020cbb47464affe6f9be 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/BenchmarkSPIMController.java @@ -34,6 +34,7 @@ import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager; import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.BenchmarkJob; import cz.it4i.fiji.haas_spim_benchmark.core.Constants; import cz.it4i.fiji.haas_spim_benchmark.core.FXFrameExecutorService; +import cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.TransferProgress; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.control.TableColumn; @@ -195,17 +196,29 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont } private void initTable() { - registry = new ObservableBenchmarkJobRegistry(bj -> remove(bj), executorServiceJobState); + registry = new ObservableBenchmarkJobRegistry(bj -> remove(bj), executorServiceJobState, executorServiceFX); setCellValueFactory(0, j -> j.getId() + ""); setCellValueFactoryCompletable(1, j -> j.getStateAsync(executorServiceJobState).thenApply(state -> "" + state)); setCellValueFactory(2, j -> j.getCreationTime().toString()); setCellValueFactory(3, j -> j.getStartTime().toString()); setCellValueFactory(4, j -> j.getEndTime().toString()); - // jobs.getSortOrder().add(jobs.getColumns().get(0)); + setCellValueFactory(5, j -> decorateTransfer("Upload",registry.get(j).getUploadProgress())); + setCellValueFactory(6, j -> decorateTransfer("Download",registry.get(j).getDownloadProgress())); } - private void remove(BenchmarkJob bj) { + private String decorateTransfer(String string, TransferProgress progress) { + if (!progress.isWorking() && !progress.isDone()) { + return ""; + } else if (progress.isWorking()) { + Long secs = progress.getRemainingSeconds(); + return string + "ing - time remains " + (secs != null ? secs : "N/A"); + } else if (progress.isDone()) { + return string + "ed"; + } + return "N/A"; + } + private void remove(BenchmarkJob bj) { jobs.getItems().remove(registry.get(bj)); bj.remove(); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/ObservableBenchmarkJobRegistry.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/ObservableBenchmarkJobRegistry.java index 560b3e056fe52abc7f3ea76c8f0c67875a60f325..db87380a20124762ad445232236689d55d00d23d 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/ObservableBenchmarkJobRegistry.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/ui/ObservableBenchmarkJobRegistry.java @@ -22,10 +22,12 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc private static Logger log = LoggerFactory .getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.ObservableBenchmarkJobRegistry.class); - public ObservableBenchmarkJobRegistry(Consumer<BenchmarkJob> removeConsumer, Executor exec) { + private Executor executorUI; + public ObservableBenchmarkJobRegistry(Consumer<BenchmarkJob> removeConsumer, Executor exec, Executor executorServiceFX) { super(t -> update(t,exec), t -> { return t.getStateAsync(exec).getNow(null); }, removeConsumer); + executorUI = executorServiceFX; } @Override @@ -48,7 +50,7 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc @Override protected UpdatableObservableValue<BenchmarkJob> constructObservableValue(BenchmarkJob v, Function<BenchmarkJob, UpdateStatus> updateFunction, Function<BenchmarkJob, Object> stateProvider) { - return new UpdatableBenchmarkJob(v, updateFunction, stateProvider); + return new UpdatableBenchmarkJob(v, updateFunction, stateProvider, executorUI); }