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;
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) {
}
}
}
......@@ -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>
......
......@@ -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();
}
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment