diff --git a/common/src/main/java/ctbrec/recorder/NextGenLocalRecorder.java b/common/src/main/java/ctbrec/recorder/NextGenLocalRecorder.java index 134d1466..a7d5e57d 100644 --- a/common/src/main/java/ctbrec/recorder/NextGenLocalRecorder.java +++ b/common/src/main/java/ctbrec/recorder/NextGenLocalRecorder.java @@ -262,27 +262,31 @@ public class NextGenLocalRecorder implements Recorder { } } - private void startRecordingProcess(Model model) throws IOException, InvalidKeyException, NoSuchAlgorithmException { - recorderLock.lock(); - try { - preconditions.check(model); - LOG.info("Starting recording for model {}", model.getName()); - Download download = createDownload(model); - Recording rec = createRecording(download); - setRecordingStatus(rec, State.RECORDING); - rec.getModel().setLastRecorded(rec.getStartDate()); - recordingManager.saveRecording(rec); - ScheduledFuture future = downloadPool.schedule(rec, 0, TimeUnit.MILLISECONDS); - downloadFutureQueue.add(future); - downloadFutureRecordingMap.put(future, rec); - } catch (RecordUntilExpiredException e) { - LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage()); - executeRecordUntilSubsequentAction(model); - } catch (PreconditionNotMetException e) { - LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage()); - } finally { - recorderLock.unlock(); - } + private CompletableFuture startRecordingProcess(Model model) throws IOException { + return CompletableFuture.runAsync(() -> { + recorderLock.lock(); + try { + preconditions.check(model); + LOG.info("Starting recording for model {}", model.getName()); + Download download = createDownload(model); + Recording rec = createRecording(download); + setRecordingStatus(rec, State.RECORDING); + rec.getModel().setLastRecorded(rec.getStartDate()); + recordingManager.saveRecording(rec); + ScheduledFuture future = downloadPool.schedule(rec, 0, TimeUnit.MILLISECONDS); + downloadFutureQueue.add(future); + downloadFutureRecordingMap.put(future, rec); + } catch (RecordUntilExpiredException e) { + LOG.info("Precondition not met to record {}: {}", model, e.getLocalizedMessage()); + 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); } }