Run NextGenLocalRecorder.startRecordingProcess() async
This commit is contained in:
parent
1ed2190a3b
commit
fb77e51e53
|
@ -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<Recording> 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<Void> 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<Recording> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue