Commit f432dcd7 authored by Piotr Różański's avatar Piotr Różański Committed by Marian Dovgialo

#45486 Better error handling when initializing signal saving

parent ac0d87a0
......@@ -6,8 +6,10 @@
import org.signalml.app.view.common.dialogs.errors.Dialogs;
import org.signalml.app.worker.monitor.Helper;
import org.signalml.app.worker.monitor.exceptions.OpenbciCommunicationException;
import org.signalml.app.worker.monitor.messages.BaseMessage;
import org.signalml.app.worker.monitor.messages.FinishSavingSignal;
import org.signalml.app.worker.monitor.messages.MessageType;
import org.signalml.app.worker.monitor.messages.SavingSignalError;
import org.signalml.app.worker.monitor.messages.SavingSignalStarting;
import org.signalml.app.worker.monitor.messages.StartSavingSignal;
......@@ -31,22 +33,30 @@ public void addRecordingListener(RecordingListener listener) {
public boolean startRecording(StartSavingSignal request) {
if (state.compareAndSet(RecordingState.FINISHED, RecordingState.INITIALIZATION)) {
String errorMessage = _("Failed to start recording");
try {
SavingSignalStarting response = (SavingSignalStarting) Helper.sendRequestAndParseResponse(
BaseMessage response = Helper.sendRequestAndParseResponse(
request,
Helper.getOpenBCIIpAddress(), Helper.getOpenbciPort(),
MessageType.SAVING_SIGNAL_STARTING
null
);
savingSessionID = response.savingSessionID;
RecordingStateChecker checker = new RecordingStateChecker(savingSessionID, state);
checker.start();
return true;
if (response instanceof SavingSignalStarting) {
savingSessionID = ((SavingSignalStarting) response).savingSessionID;
RecordingStateChecker checker = new RecordingStateChecker(savingSessionID, state);
checker.start();
return true;
} else if (response instanceof SavingSignalError) {
errorMessage += ": " + ((SavingSignalError) response).details.toString();
} else {
errorMessage += ": received incompatible message type " + response.getClass().getSimpleName();
}
} catch (OpenbciCommunicationException ex) {
logger.error("cannot send recording request", ex);
// restoring the original state
state.set(RecordingState.FINISHED);
Dialogs.showError(_("Failed to start recording"));
errorMessage = ": " + ex.getMessage();
}
// restoring the original state
state.set(RecordingState.FINISHED);
Dialogs.showError(errorMessage);
}
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment