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 cecce16bc731b00f077ef5e3ff05b9dc43e088cd..a314a7e4fd1230119688d8f4a308f66d37e3b641 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 @@ -5,6 +5,7 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.Calendar; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; @@ -243,6 +244,10 @@ public class Job { } + public Collection<String> getChangedFiles() { + return haasClientSupplier.get().getChangedFiles(getId()); + } + 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 756073c43933a14686576fb86313b30fa7a9e0cf..3d792c9f079bc70226a05185cf7f836adb26a996 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 @@ -1,7 +1,6 @@ package cz.it4i.fiji.haas_spim_benchmark.core; import java.io.BufferedReader; -import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; @@ -56,27 +55,28 @@ public class BenchmarkJobManager { private List<Task> tasks; - private SPIMComputationAccessor computationAccessor = new SPIMComputationAccessor() { - - private HaaSOutputHolder outputOfSnakemake = - new HaaSOutputHolderImpl(BenchmarkJob.this, SynchronizableFileType.StandardErrorFile); - - @Override - public String getActualOutput() { - return outputOfSnakemake.getActualOutput(); - } - - @Override - public boolean fileExists(String filePath) { - File f = new File(job.getDirectory().resolve(filePath).toString()); - return f.exists() && !f.isDirectory(); - } - }; + private SPIMComputationAccessor computationAccessor; public BenchmarkJob(Job job) { super(); this.job = job; + computationAccessor = new SPIMComputationAccessor() { + + private HaaSOutputHolder outputOfSnakemake = + new HaaSOutputHolderImpl(BenchmarkJob.this, SynchronizableFileType.StandardErrorFile); + + @Override + public String getActualOutput() { + return outputOfSnakemake.getActualOutput(); + } + + public java.util.Collection<String> getChangedFiles() { + return job.getChangedFiles(); + }; + }; + + computationAccessor = new SPIMComputationAccessorDecoratorWithTimeout(computationAccessor, Constants.HAAS_UPDATE_TIMEOUT); } public void startJob(Progress progress) throws IOException { diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessor.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessor.java index 5c01528dc5befd2462c2ee6c0eb1f7ca205181e6..b1dc0c1610248f7a639bc8106958db13622d74e7 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessor.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessor.java @@ -1,9 +1,13 @@ package cz.it4i.fiji.haas_spim_benchmark.core; -import java.nio.file.Path; +import java.util.Collection; import cz.it4i.fiji.haas.HaaSOutputHolder; public interface SPIMComputationAccessor extends HaaSOutputHolder { - boolean fileExists(String fileName); + default boolean fileExists(String fileName) { + return getChangedFiles().contains(fileName); + } + + Collection<String> getChangedFiles(); } diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessorDecoratorWithTimeout.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessorDecoratorWithTimeout.java new file mode 100644 index 0000000000000000000000000000000000000000..8f215c3ac7f5aa673c93fca22754cc005d00e724 --- /dev/null +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/SPIMComputationAccessorDecoratorWithTimeout.java @@ -0,0 +1,61 @@ +package cz.it4i.fiji.haas_spim_benchmark.core; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.function.Function; + +public class SPIMComputationAccessorDecoratorWithTimeout implements SPIMComputationAccessor { + private long intervalForQueryInMs; + + private P_ResultCacheHolder<String> outputCache; + + private P_ResultCacheHolder<Set<String>> changedFilesCache; + + public SPIMComputationAccessorDecoratorWithTimeout(SPIMComputationAccessor decorated, long intervalForQueryInMs) { + super(); + this.intervalForQueryInMs = intervalForQueryInMs; + outputCache = new P_ResultCacheHolder<>(x -> decorated.getActualOutput()); + changedFilesCache = new P_ResultCacheHolder<>(set -> { + if (set == null) { + set = new HashSet<>(); + } else { + set.clear(); + } + set.addAll(decorated.getChangedFiles()); + return null; + }); + } + + @Override + public String getActualOutput() { + + return outputCache.getResult(); + } + + @Override + public Collection<String> getChangedFiles() { + return changedFilesCache.getResult(); + } + + private class P_ResultCacheHolder<T> { + private Long lastQuery; + private T value; + private Function<T, T> producer; + + public P_ResultCacheHolder(Function<T, T> producer) { + super(); + this.producer = producer; + } + + public T getResult() { + long time = System.currentTimeMillis(); + + if (lastQuery == null || (time - lastQuery) > intervalForQueryInMs) { + value = producer.apply(value); + lastQuery = time; + } + return value; + } + } +}