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

feat: transfer connected to UI

parent 5d71c64a
No related branches found
No related tags found
No related merge requests found
package cz.it4i.fiji.haas_spim_benchmark.core; package cz.it4i.fiji.haas_spim_benchmark.core;
import java.util.concurrent.Executor;
import java.util.function.Function; import java.util.function.Function;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -14,50 +15,60 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -14,50 +15,60 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
public static final Logger log = LoggerFactory public static final Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.class); .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 interface TransferProgress {
public Long getRemainingSeconds(); public Long getRemainingSeconds();
public boolean isDownloaded(); public boolean isDone();
public boolean isDonwloadind(); public boolean isWorking();
public Float getRemainingPercents(); public Float getRemainingPercents();
} }
public UpdatableBenchmarkJob(BenchmarkJob wrapped, Function<BenchmarkJob, UpdateStatus> updateFunction, public UpdatableBenchmarkJob(BenchmarkJob wrapped, Function<BenchmarkJob, UpdateStatus> updateFunction,
Function<BenchmarkJob, Object> stateProvider) { Function<BenchmarkJob, Object> stateProvider, Executor executorUI) {
super(wrapped, updateFunction, stateProvider); super(wrapped, updateFunction, stateProvider);
wrapped.setDownloadNotifier(downloadProgress); wrapped.setDownloadNotifier(downloadProgress);
wrapped.setUploadNotifier(uploadProgress);
wrapped.resumeTransfer(); wrapped.resumeTransfer();
this.executor = executorUI;
}
public TransferProgress getDownloadProgress() {
return downloadProgress;
}
public TransferProgress getUploadProgress() {
return uploadProgress;
} }
public void removed() { public void removed() {
getValue().setDownloadNotifier(null); 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 working;
private boolean downloaded; private boolean done;
private long start; private long start;
private Long remainingSeconds; private Long remainingSeconds;
private Float remainingPercents; private Float remainingPercents;
@Override
public void setTitle(String title) {
}
@Override @Override
public synchronized void setCount(int count, int total) { public synchronized void setCount(int count, int total) {
if(total < -1) { if(total < -1) {
downloading = false; working = false;
remainingSeconds = null; remainingSeconds = null;
remainingPercents = null; remainingPercents = null;
} else { } else {
...@@ -69,43 +80,43 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -69,43 +80,43 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
} }
@Override @Override
public void addItem(Object item) { public synchronized void addItem(Object item) {
if (!downloading) { if (!working) {
downloaded = false; done = false;
downloading = true; working = true;
start = System.currentTimeMillis(); start = System.currentTimeMillis();
} }
fireValueChangedEvent(); fireValueChangedEvent();
} }
@Override @Override
public void done() { public synchronized void done() {
if (downloading) { if (working) {
downloaded = true; done = true;
} }
downloading = false; working = false;
remainingSeconds = 0l; remainingSeconds = 0l;
remainingPercents = 0.f; remainingPercents = 0.f;
fireValueChangedEvent(); fireValueChangedEvent();
} }
@Override @Override
public boolean isDownloaded() { public synchronized boolean isDone() {
return downloaded; return done;
} }
@Override @Override
public boolean isDonwloadind() { public synchronized boolean isWorking() {
return downloading; return working;
} }
@Override @Override
public Long getRemainingSeconds() { public synchronized Long getRemainingSeconds() {
return remainingSeconds; return remainingSeconds;
} }
@Override @Override
public Float getRemainingPercents() { public synchronized Float getRemainingPercents() {
return remainingPercents; return remainingPercents;
} }
...@@ -116,7 +127,12 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob ...@@ -116,7 +127,12 @@ public class UpdatableBenchmarkJob extends UpdatableObservableValue<BenchmarkJob
@Override @Override
public void itemDone(Object item) { public void itemDone(Object item) {
} }
@Override
public void setTitle(String title) {
}
} }
} }
...@@ -12,14 +12,15 @@ ...@@ -12,14 +12,15 @@
<HBox> <HBox>
<children> <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> <columns>
<TableColumn prefWidth="75.0" text="Job Id" /> <TableColumn prefWidth="70.0" text="Job Id" />
<TableColumn prefWidth="149.0" text="Status" /> <TableColumn prefWidth="149.0" text="Status" />
<TableColumn prefWidth="230.0" text="Creation time" /> <TableColumn prefWidth="230.0" text="Creation time" />
<TableColumn prefWidth="230.0" text="Start time" /> <TableColumn prefWidth="230.0" text="Start time" />
<TableColumn prefWidth="230.0" text="End 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> </columns>
</TableView> </TableView>
</children> </children>
......
...@@ -34,6 +34,7 @@ import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager; ...@@ -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.BenchmarkJobManager.BenchmarkJob;
import cz.it4i.fiji.haas_spim_benchmark.core.Constants; 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.FXFrameExecutorService;
import cz.it4i.fiji.haas_spim_benchmark.core.UpdatableBenchmarkJob.TransferProgress;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn;
...@@ -195,17 +196,29 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont ...@@ -195,17 +196,29 @@ public class BenchmarkSPIMController extends BorderPane implements CloseableCont
} }
private void initTable() { private void initTable() {
registry = new ObservableBenchmarkJobRegistry(bj -> remove(bj), executorServiceJobState); registry = new ObservableBenchmarkJobRegistry(bj -> remove(bj), executorServiceJobState, executorServiceFX);
setCellValueFactory(0, j -> j.getId() + ""); setCellValueFactory(0, j -> j.getId() + "");
setCellValueFactoryCompletable(1, j -> j.getStateAsync(executorServiceJobState).thenApply(state -> "" + state)); setCellValueFactoryCompletable(1, j -> j.getStateAsync(executorServiceJobState).thenApply(state -> "" + state));
setCellValueFactory(2, j -> j.getCreationTime().toString()); setCellValueFactory(2, j -> j.getCreationTime().toString());
setCellValueFactory(3, j -> j.getStartTime().toString()); setCellValueFactory(3, j -> j.getStartTime().toString());
setCellValueFactory(4, j -> j.getEndTime().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)); jobs.getItems().remove(registry.get(bj));
bj.remove(); bj.remove();
} }
......
...@@ -22,10 +22,12 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc ...@@ -22,10 +22,12 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc
private static Logger log = LoggerFactory private static Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.ui.ObservableBenchmarkJobRegistry.class); .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 -> { super(t -> update(t,exec), t -> {
return t.getStateAsync(exec).getNow(null); return t.getStateAsync(exec).getNow(null);
}, removeConsumer); }, removeConsumer);
executorUI = executorServiceFX;
} }
@Override @Override
...@@ -48,7 +50,7 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc ...@@ -48,7 +50,7 @@ public class ObservableBenchmarkJobRegistry extends ObservableValueRegistry<Benc
@Override @Override
protected UpdatableObservableValue<BenchmarkJob> constructObservableValue(BenchmarkJob v, protected UpdatableObservableValue<BenchmarkJob> constructObservableValue(BenchmarkJob v,
Function<BenchmarkJob, UpdateStatus> updateFunction, Function<BenchmarkJob, Object> stateProvider) { Function<BenchmarkJob, UpdateStatus> updateFunction, Function<BenchmarkJob, Object> stateProvider) {
return new UpdatableBenchmarkJob(v, updateFunction, stateProvider); return new UpdatableBenchmarkJob(v, updateFunction, stateProvider, executorUI);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment