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

code: use whenComplete, thenCompose for more readable code

parent 7d306eff
No related branches found
No related tags found
No related merge requests found
......@@ -418,28 +418,24 @@ public class BenchmarkJobManager implements Closeable {
String mainFile = job.getProperty(SPIM_OUTPUT_FILENAME_PATTERN) + ".xml";
final ProgressNotifierTemporarySwitchOff notifierSwitch = new ProgressNotifierTemporarySwitchOff(downloadNotifier, job);
job.startDownload(downloadFileNameExtractDecorator(fileName->fileName.equals(mainFile)))
.whenComplete((X,e1)-> {
notifierSwitch.switchOn();
if(e1 == null) {
Set<String> otherFiles = extractNames(getOutputDirectory().resolve(mainFile));
try {
job.startDownload(downloadFileNameExtractDecorator(name -> otherFiles.contains(name)))
.whenComplete((X2,e2) -> {
result.complete(null);
if(e2 != null) {
log.error(e2.getMessage(), e2);
}
});
} catch (IOException e) {
e1 = e;
}
}
if(e1 != null){
log.error(e1.getMessage(), e1);
result.complete(null);
}
});
job.startDownload(downloadFileNameExtractDecorator(fileName -> fileName.equals(mainFile)))
.whenComplete((X, E) -> {
notifierSwitch.switchOn();
}).thenCompose(X -> {
Set<String> otherFiles = extractNames(getOutputDirectory().resolve(mainFile));
try {
return job
.startDownload(downloadFileNameExtractDecorator(name -> otherFiles.contains(name)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}).whenComplete((X, e) -> {
if (e != null) {
log.error(e.getMessage(), e);
}
result.complete(null);
});
}
private Set<String> extractNames(Path resolve) {
......
......@@ -6,7 +6,7 @@ import cz.it4i.fiji.haas_java_client.ProgressNotifier;
public class ProgressNotifierTemporarySwitchOff {
private final ProgressNotifier notifier;
private ProgressNotifier notifier;
private final Job job;
public ProgressNotifierTemporarySwitchOff(ProgressNotifier downloadNotifier, Job job) {
......@@ -17,10 +17,11 @@ public class ProgressNotifierTemporarySwitchOff {
}
}
public void switchOn() {
synchronized public void switchOn() {
if(notifier != null) {
this.job.setDownloadNotifier(notifier);
}
notifier = null;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment