Run NextGenLocalRecorder.startRecordingProcess() async

This commit is contained in:
0xb00bface 2021-01-02 11:44:36 +01:00
parent 1ed2190a3b
commit fb77e51e53
1 changed files with 27 additions and 23 deletions

View File

@ -262,7 +262,8 @@ public class NextGenLocalRecorder implements Recorder {
}
}
private void startRecordingProcess(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException {
private CompletableFuture<Void> startRecordingProcess(Model model) throws IOException {
return CompletableFuture.runAsync(() -> {
recorderLock.lock();
try {
preconditions.check(model);
@ -280,9 +281,12 @@ public class NextGenLocalRecorder implements Recorder {
executeRecordUntilSubsequentAction(model);
} catch (PreconditionNotMetException e) {
LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage());
} catch (IOException e) {
LOG.error("Couldn't start recording process for {}", model, e);
} finally {
recorderLock.unlock();
}
}, segmentDownloadPool);
}
private Download createDownload(Model model) throws IOException {
@ -294,14 +298,14 @@ public class NextGenLocalRecorder implements Recorder {
return download;
}
private void executeRecordUntilSubsequentAction(Model model) throws IOException {
private void executeRecordUntilSubsequentAction(Model model) {
if (model.getRecordUntilSubsequentAction() == PAUSE) {
model.setSuspended(true);
} else if (model.getRecordUntilSubsequentAction() == REMOVE) {
try {
LOG.info("Removing {} because the recording timeframe ended at {}", model, model.getRecordUntil().atZone(ZoneId.systemDefault()));
stopRecording(model);
} catch (InvalidKeyException | NoSuchAlgorithmException e1) {
} catch (Exception e1) {
LOG.error("Error while stopping recording", e1);
}
}