Java Console reconnection fixing (by issue #3305) (#3716)

* ADD: Port closing & and reconnection attempt at restart event

* FIX: Syntax error

* Explicitly initialization of lastTriedPort

* Explicitly initialization of isStarted

* Revert "Explicitly initialization of isStarted"

This reverts commit 4acdd44d6cb7c46caa22f1dece4aef61798756fd.

* DEL: Dead code

Co-authored-by: alxrMironov <330OMcorporative>
This commit is contained in:
alxrMironovHome 2022-01-12 07:33:05 +03:00 committed by GitHub
parent 2914f53d0f
commit fa63c99ed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -46,6 +46,8 @@ public class LinkManager implements Closeable {
public static final String LOG_VIEWER = "log viewer";
private final CommandQueue commandQueue;
private String lastTriedPort = null;
private LinkConnector connector = LinkConnector.VOID;
private boolean isStarted;
private boolean compositeLogicEnabled = true;
@ -209,6 +211,7 @@ public class LinkManager implements Closeable {
public void start(String port, ConnectionFailedListener stateListener) {
Objects.requireNonNull(port, "port");
log.info("LinkManager: Starting " + port);
lastTriedPort = port; // Save port before connection attempt
if (isLogViewerMode(port)) {
setConnector(LinkConnector.VOID);
} else if (PCAN.equals(port)) {
@ -272,13 +275,20 @@ public class LinkManager implements Closeable {
public void restart() {
ConnectionStatusLogic.INSTANCE.setValue(ConnectionStatusValue.NOT_CONNECTED);
connector.restart();
close(); // Explicitly kill the connection (call connectors destructor??????)
String[] ports = getCommPorts();
boolean isPortAvaliableAgain = Arrays.stream(ports).anyMatch(lastTriedPort::equals);
if(isPortAvaliableAgain) {
connect(lastTriedPort);
}
}
@Override
public void close() {
if (connector != null)
connector.stop();
isStarted = false; // Connector is dead and cant be in started state (Otherwise the Exception will raised)
}
public static String unpackConfirmation(String message) {