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

iss1007:fileExists in accessor, limit queries to server

parent 05061838
No related branches found
No related tags found
1 merge request!7Iss1007 provide task infos
......@@ -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());
}
......
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 {
......
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();
}
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;
}
}
}
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