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
Branches
Tags
No related merge requests found
...@@ -418,28 +418,24 @@ public class BenchmarkJobManager implements Closeable { ...@@ -418,28 +418,24 @@ public class BenchmarkJobManager implements Closeable {
String mainFile = job.getProperty(SPIM_OUTPUT_FILENAME_PATTERN) + ".xml"; String mainFile = job.getProperty(SPIM_OUTPUT_FILENAME_PATTERN) + ".xml";
final ProgressNotifierTemporarySwitchOff notifierSwitch = new ProgressNotifierTemporarySwitchOff(downloadNotifier, job); final ProgressNotifierTemporarySwitchOff notifierSwitch = new ProgressNotifierTemporarySwitchOff(downloadNotifier, job);
job.startDownload(downloadFileNameExtractDecorator(fileName->fileName.equals(mainFile))) job.startDownload(downloadFileNameExtractDecorator(fileName -> fileName.equals(mainFile)))
.whenComplete((X,e1)-> { .whenComplete((X, E) -> {
notifierSwitch.switchOn(); notifierSwitch.switchOn();
if(e1 == null) { }).thenCompose(X -> {
Set<String> otherFiles = extractNames(getOutputDirectory().resolve(mainFile)); Set<String> otherFiles = extractNames(getOutputDirectory().resolve(mainFile));
try { try {
job.startDownload(downloadFileNameExtractDecorator(name -> otherFiles.contains(name))) return job
.whenComplete((X2,e2) -> { .startDownload(downloadFileNameExtractDecorator(name -> otherFiles.contains(name)));
result.complete(null); } catch (IOException e) {
if(e2 != null) { throw new RuntimeException(e);
log.error(e2.getMessage(), e2); }
}
}); }).whenComplete((X, e) -> {
} catch (IOException e) { if (e != null) {
e1 = e; log.error(e.getMessage(), e);
} }
} result.complete(null);
if(e1 != null){ });
log.error(e1.getMessage(), e1);
result.complete(null);
}
});
} }
private Set<String> extractNames(Path resolve) { private Set<String> extractNames(Path resolve) {
......
...@@ -6,7 +6,7 @@ import cz.it4i.fiji.haas_java_client.ProgressNotifier; ...@@ -6,7 +6,7 @@ import cz.it4i.fiji.haas_java_client.ProgressNotifier;
public class ProgressNotifierTemporarySwitchOff { public class ProgressNotifierTemporarySwitchOff {
private final ProgressNotifier notifier; private ProgressNotifier notifier;
private final Job job; private final Job job;
public ProgressNotifierTemporarySwitchOff(ProgressNotifier downloadNotifier, Job job) { public ProgressNotifierTemporarySwitchOff(ProgressNotifier downloadNotifier, Job job) {
...@@ -17,10 +17,11 @@ public class ProgressNotifierTemporarySwitchOff { ...@@ -17,10 +17,11 @@ public class ProgressNotifierTemporarySwitchOff {
} }
} }
public void switchOn() { synchronized public void switchOn() {
if(notifier != null) { if(notifier != null) {
this.job.setDownloadNotifier(notifier); 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