Commit caf635ed authored by Marian Dovgialo's avatar Marian Dovgialo

#45946 Svarog hangup during while closing online signal which doesn't exist anymore

parent ccc9e1d4
......@@ -194,6 +194,23 @@ public void openDocument() throws SignalMLException, IOException {
logger.info("Monitor executed.");
}
private void disconnectFromExperiment()
{
DisconnectFromExperimentWorker worker = new DisconnectFromExperimentWorker(null, descriptor);
worker.execute();
while (!worker.isDone())
{
try
{
Thread.sleep(10);
}
catch (InterruptedException e)
{
}
}
}
@Override
public void closeDocument() throws SignalMLException {
......@@ -208,7 +225,7 @@ public void closeDocument() throws SignalMLException {
monitorWorker.cancel(false);
do {
try {
Thread.sleep(1);
Thread.sleep(10);
} catch (InterruptedException e) {
}
} while (!monitorWorker.isFinished());
......@@ -217,14 +234,11 @@ public void closeDocument() throws SignalMLException {
tagSet.stopTagsRemoving();
//disconnect from Jmx
DisconnectFromExperimentWorker worker = new DisconnectFromExperimentWorker(descriptor);
worker.execute();
while (!worker.isDone())
;
disconnectFromExperiment();
//close document
super.closeDocument();
logger.debug("Closed document");
}
......
......@@ -33,9 +33,9 @@
public static final int TIMEOUT_MILIS = 500;
public static final int TRYOUT_COUNT = 20;
public static final int EXPERIMENT_START_TIMEOUT_MILIS = 10000;
private Container parentContainer;
private static Logger logger = Logger.getLogger(ConnectToExperimentWorker.class);
private ExperimentDescriptor experimentDescriptor;
private String multiplexerAddress;
......@@ -46,6 +46,7 @@
public ConnectToExperimentWorker(Container parentContainer, ExperimentDescriptor experimentDescriptor) {
super(parentContainer);
this.parentContainer = parentContainer;
this.experimentDescriptor = experimentDescriptor;
getBusyDialog().setText(_("Connecting to the experiment"));
getBusyDialog().setCancellable(false);
......@@ -179,7 +180,7 @@ protected void done() {
}
if (shouldDisconnect) {
DisconnectFromExperimentWorker worker = new DisconnectFromExperimentWorker(experimentDescriptor);
DisconnectFromExperimentWorker worker = new DisconnectFromExperimentWorker(this.parentContainer, experimentDescriptor);
worker.execute();
}
}
......
package org.signalml.app.worker.monitor;
import java.awt.Container;
import java.util.List;
import static org.signalml.app.util.i18n.SvarogI18n._R;
......@@ -19,18 +20,23 @@
import org.signalml.app.worker.monitor.messages.RequestErrorResponse;
import org.signalml.peer.Peer;
import static org.signalml.app.util.i18n.SvarogI18n._;
import org.signalml.app.worker.SwingWorkerWithBusyDialog;
public class DisconnectFromExperimentWorker extends SwingWorker<Void, Void> {
public class DisconnectFromExperimentWorker extends SwingWorkerWithBusyDialog<Void, Void> {
private static Logger logger = Logger.getLogger(DisconnectFromExperimentWorker.class);
private ExperimentDescriptor experimentDescriptor;
public DisconnectFromExperimentWorker(ExperimentDescriptor experimentDescriptor) {
public DisconnectFromExperimentWorker(Container parentContainer, ExperimentDescriptor experimentDescriptor) {
super(parentContainer);
getBusyDialog().setText(_("Disconnecting from experiment"));
this.experimentDescriptor = experimentDescriptor;
}
@Override
protected Void doInBackground() throws Exception {
showBusyDialog();
logger.debug("Disconnecting from experiment");
if (!experimentDescriptor.isConnected()) {
......@@ -39,7 +45,18 @@ protected Void doInBackground() throws Exception {
}
disconnectFromMultiplexer();
sendLeaveExperimentRequest();
try
{
sendLeaveExperimentRequest();
}
catch (OpenbciCommunicationException e)
{
//cannot communicate with server - server down?
// we are disconnected
experimentDescriptor.setConnected(false);
return null;
}
if (experimentDescriptor.getRecommendedScenario() != null)
sendKillExperimentRequest();
......@@ -65,7 +82,9 @@ private void sendLeaveExperimentRequest() throws OpenbciCommunicationException {
Helper.sendRequestAndParseResponse(request,
experimentDescriptor.getFirstRepHost(),
experimentDescriptor.getFirstRepPort(),
MessageType.REQUEST_OK_RESPONSE);
MessageType.REQUEST_OK_RESPONSE,
1000
);
}
private void sendKillExperimentRequest() throws OpenbciCommunicationException {
......
......@@ -44,13 +44,22 @@ public static int getOpenbciPort() {
public static BaseMessage sendRequestAndParseResponse(LauncherMessage request, String destinationIP, int destinationPort, MessageType awaitedMessageType) throws OpenbciCommunicationException {
return sendRequestAndParseResponse(request, destinationIP, destinationPort, awaitedMessageType, true);
}
public static BaseMessage sendRequestAndParseResponse(LauncherMessage request, String destinationIP, int destinationPort, MessageType awaitedMessageType, int timeout) throws OpenbciCommunicationException {
return sendRequestAndParseResponse(request, destinationIP, destinationPort, awaitedMessageType, true, timeout);
}
public static BaseMessage sendRequestAndParseResponse(LauncherMessage request, String destinationIP, int destinationPort, MessageType awaitedMessageType, boolean handleException) throws OpenbciCommunicationException {
return sendRequestAndParseResponse(request, destinationIP, destinationPort, awaitedMessageType, handleException, DEFAULT_TIMEOUT);
}
public static BaseMessage sendRequestAndParseResponse(LauncherMessage request, String destinationIP, int destinationPort, MessageType awaitedMessageType, boolean handleException) throws OpenbciCommunicationException {
public static BaseMessage sendRequestAndParseResponse(LauncherMessage request, String destinationIP, int destinationPort, MessageType awaitedMessageType, boolean handleException, int timeout) throws OpenbciCommunicationException {
List<byte[]> response;
if (handleException) {
response = sendRequest(request, destinationIP, destinationPort, DEFAULT_TIMEOUT);
response = sendRequest(request, destinationIP, destinationPort, timeout);
} else {
response = sendRequestWithoutHandlingExceptions(request, destinationIP, destinationPort, DEFAULT_TIMEOUT);
response = sendRequestWithoutHandlingExceptions(request, destinationIP, destinationPort, timeout);
}
if (awaitedMessageType != null) {
Helper.checkIfResponseIsOK(response, awaitedMessageType);
......
......@@ -135,7 +135,7 @@ else if (sampleMsg == null) {
if (result == DIALOG_OPTIONS.YES) {
continue;
} else {
DisconnectFromExperimentWorker disconnectWorker = new DisconnectFromExperimentWorker(experimentDescriptor);
DisconnectFromExperimentWorker disconnectWorker = new DisconnectFromExperimentWorker(null, experimentDescriptor);
disconnectWorker.execute();
break;
}
......
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