bugfix: unhandled exception if trying to run two instances of console
This commit is contained in:
parent
fef0d4d768
commit
ecf930214e
|
@ -0,0 +1,5 @@
|
|||
package com.rusefi.io;
|
||||
|
||||
public interface ConnectionFailedListener {
|
||||
void onConnectionFailed();
|
||||
}
|
|
@ -4,13 +4,11 @@ package com.rusefi.io;
|
|||
* @author Andrey Belomutskiy
|
||||
* 3/1/2017
|
||||
*/
|
||||
public interface ConnectionStateListener {
|
||||
public interface ConnectionStateListener extends ConnectionFailedListener {
|
||||
ConnectionStateListener VOID = new AbstractConnectionStateListener();
|
||||
|
||||
/**
|
||||
* This method is invoked once we have connection & configuration from controller
|
||||
*/
|
||||
void onConnectionEstablished();
|
||||
|
||||
void onConnectionFailed();
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class LinkManager implements Closeable {
|
|||
return connector;
|
||||
}
|
||||
|
||||
public void start(String port, ConnectionStateListener stateListener) {
|
||||
public void start(String port, ConnectionFailedListener stateListener) {
|
||||
Objects.requireNonNull(port, "port");
|
||||
log.info("LinkManager: Starting " + port);
|
||||
if (isLogViewerMode(port)) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class BinaryProtocolProxy {
|
|||
*/
|
||||
public static final int USER_IO_TIMEOUT = 10 * Timeouts.MINUTE;
|
||||
|
||||
public static ServerSocketReference createProxy(IoStream targetEcuSocket, int serverProxyPort, AtomicInteger relayCommandCounter) {
|
||||
public static ServerSocketReference createProxy(IoStream targetEcuSocket, int serverProxyPort, AtomicInteger relayCommandCounter) throws IOException {
|
||||
Function<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
||||
TcpIoStream clientStream = null;
|
||||
try {
|
||||
|
|
|
@ -43,25 +43,25 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
|
||||
public AtomicInteger unknownCommands = new AtomicInteger();
|
||||
|
||||
public static final Function<Integer, ServerSocket> SECURE_SOCKET_FACTORY = rusEFISSLContext::getSSLServerSocket;
|
||||
public static final ServerSocketFunction SECURE_SOCKET_FACTORY = rusEFISSLContext::getSSLServerSocket;
|
||||
|
||||
public static final Function<Integer, ServerSocket> PLAIN_SOCKET_FACTORY = port -> {
|
||||
try {
|
||||
ServerSocket serverSocket = new ServerSocket(port);
|
||||
log.info("ServerSocket " + port + " created");
|
||||
return serverSocket;
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Error binding server socket " + port, e);
|
||||
}
|
||||
public static final ServerSocketFunction PLAIN_SOCKET_FACTORY = port -> {
|
||||
ServerSocket serverSocket = new ServerSocket(port);
|
||||
log.info("ServerSocket " + port + " created");
|
||||
return serverSocket;
|
||||
};
|
||||
|
||||
private static ConcurrentHashMap<String, ThreadFactory> THREAD_FACTORIES_BY_NAME = new ConcurrentHashMap<>();
|
||||
|
||||
public void start(LinkManager linkManager) {
|
||||
try {
|
||||
start(linkManager, DEFAULT_PROXY_PORT, Listener.empty(), new Context());
|
||||
} catch (IOException e) {
|
||||
log.error("Error starting local proxy", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void start(LinkManager linkManager, int port, Listener serverSocketCreationCallback, Context context) {
|
||||
public void start(LinkManager linkManager, int port, Listener serverSocketCreationCallback, Context context) throws IOException {
|
||||
log.info("BinaryProtocolServer on " + port);
|
||||
|
||||
Function<Socket, Runnable> clientSocketRunnableFactory = clientSocket -> () -> {
|
||||
|
@ -84,11 +84,11 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
* @param serverSocketCreationCallback this callback is invoked once we open the server socket
|
||||
* @return
|
||||
*/
|
||||
public static ServerSocketReference tcpServerSocket(int port, String threadName, Function<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback) {
|
||||
public static ServerSocketReference tcpServerSocket(int port, String threadName, Function<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback) throws IOException {
|
||||
return tcpServerSocket(socketRunnableFactory, port, threadName, serverSocketCreationCallback, PLAIN_SOCKET_FACTORY);
|
||||
}
|
||||
|
||||
public static ServerSocketReference tcpServerSocket(Function<Socket, Runnable> clientSocketRunnableFactory, int port, String threadName, Listener serverSocketCreationCallback, Function<Integer, ServerSocket> nonSecureSocketFunction) {
|
||||
public static ServerSocketReference tcpServerSocket(Function<Socket, Runnable> clientSocketRunnableFactory, int port, String threadName, Listener serverSocketCreationCallback, ServerSocketFunction nonSecureSocketFunction) throws IOException {
|
||||
ThreadFactory threadFactory = getThreadFactory(threadName);
|
||||
|
||||
Objects.requireNonNull(serverSocketCreationCallback, "serverSocketCreationCallback");
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.rusefi.io.tcp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
||||
public interface ServerSocketFunction {
|
||||
ServerSocket apply(int port) throws IOException;
|
||||
}
|
|
@ -47,7 +47,7 @@ public class TestHelper {
|
|||
}
|
||||
|
||||
@NotNull
|
||||
public static BinaryProtocolServer createVirtualController(ConfigurationImage ci, int port, Listener serverSocketCreationCallback, BinaryProtocolServer.Context context) {
|
||||
public static BinaryProtocolServer createVirtualController(ConfigurationImage ci, int port, Listener serverSocketCreationCallback, BinaryProtocolServer.Context context) throws IOException {
|
||||
BinaryProtocolState state = new BinaryProtocolState();
|
||||
state.setController(ci);
|
||||
state.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
|
||||
|
@ -83,9 +83,13 @@ public class TestHelper {
|
|||
|
||||
public static BinaryProtocolServer createVirtualController(int controllerPort, ConfigurationImage controllerImage, BinaryProtocolServer.Context context) throws InterruptedException {
|
||||
CountDownLatch controllerCreated = new CountDownLatch(1);
|
||||
BinaryProtocolServer server = createVirtualController(controllerImage, controllerPort, parameter -> controllerCreated.countDown(), context);
|
||||
assertLatch(controllerCreated);
|
||||
return server;
|
||||
try {
|
||||
BinaryProtocolServer server = createVirtualController(controllerImage, controllerPort, parameter -> controllerCreated.countDown(), context);
|
||||
assertLatch(controllerCreated);
|
||||
return server;
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static SessionDetails createTestSession(String authToken, String signature) {
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.rusefi.ui.util.UiUtils;
|
|||
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
|
||||
|
||||
public class MainFrame {
|
||||
|
@ -21,7 +22,7 @@ public class MainFrame {
|
|||
/**
|
||||
* @see StartupFrame
|
||||
*/
|
||||
private FrameHelper frame = new FrameHelper() {
|
||||
private final FrameHelper frame = new FrameHelper() {
|
||||
@Override
|
||||
protected void onWindowOpened() {
|
||||
FileLog.MAIN.logLine("onWindowOpened");
|
||||
|
@ -42,22 +43,13 @@ public class MainFrame {
|
|||
}
|
||||
};
|
||||
|
||||
public ConnectionStateListener listener;
|
||||
public ConnectionFailedListener listener;
|
||||
|
||||
public MainFrame(ConsoleUI consoleUI, TabbedPanel tabbedPane) {
|
||||
this.consoleUI = consoleUI;
|
||||
|
||||
this.tabbedPane = tabbedPane;
|
||||
listener = new AbstractConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
FileLog.MAIN.logLine("onConnectionEstablished");
|
||||
// tabbedPane.romEditorPane.showContent();
|
||||
tabbedPane.settingsTab.showContent();
|
||||
tabbedPane.logsManager.showContent();
|
||||
tabbedPane.fuelTunePane.showContent();
|
||||
new BinaryProtocolServer().start(consoleUI.uiContext.getLinkManager());
|
||||
}
|
||||
listener = () -> {
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -87,8 +79,6 @@ public class MainFrame {
|
|||
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
FileLog.MAIN.logLine("onConnectionEstablished");
|
||||
// tabbedPane.romEditorPane.showContent();
|
||||
tabbedPane.settingsTab.showContent();
|
||||
tabbedPane.logsManager.showContent();
|
||||
tabbedPane.fuelTunePane.showContent();
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.rusefi.server.rusEFISSLContext;
|
|||
import com.rusefi.tools.online.HttpUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
|
@ -16,13 +17,21 @@ import static com.rusefi.TestHelper.assertLatch;
|
|||
public class BackendTestHelper {
|
||||
public static void runApplicationConnectorBlocking(Backend backend, int serverPortForRemoteUsers) throws InterruptedException {
|
||||
CountDownLatch applicationServerCreated = new CountDownLatch(1);
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
||||
try {
|
||||
backend.runApplicationConnector(serverPortForRemoteUsers, parameter -> applicationServerCreated.countDown());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
assertLatch(applicationServerCreated);
|
||||
}
|
||||
|
||||
public static void runControllerConnectorBlocking(Backend backend, int serverPortForControllers) throws InterruptedException {
|
||||
CountDownLatch controllerServerCreated = new CountDownLatch(1);
|
||||
backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown());
|
||||
try {
|
||||
backend.runControllerConnector(serverPortForControllers, parameter -> controllerServerCreated.countDown());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
assertLatch(controllerServerCreated);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.rusefi.io.tcp.BinaryProtocolProxy;
|
|||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -83,7 +84,7 @@ public class TcpCommunicationIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testProxy() throws InterruptedException {
|
||||
public void testProxy() throws InterruptedException, IOException {
|
||||
ConfigurationImage serverImage = TestHelper.prepareImage(239, TestHelper.createIniField(Fields.CYLINDERSCOUNT));
|
||||
int controllerPort = 6102;
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ public class Backend implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
public void runApplicationConnector(int serverPortForApplications, Listener<?> serverSocketCreationCallback) {
|
||||
public void runApplicationConnector(int serverPortForApplications, Listener<?> serverSocketCreationCallback) throws IOException {
|
||||
this.serverPortForApplications = serverPortForApplications;
|
||||
// connection from authenticator app which proxies for Tuner Studio
|
||||
// authenticator pushed hello packet on connect
|
||||
|
@ -246,7 +246,7 @@ public class Backend implements Closeable {
|
|||
log.info("Disconnecting application " + applicationConnectionState);
|
||||
}
|
||||
|
||||
public void runControllerConnector(int serverPortForControllers, Listener<?> serverSocketCreationCallback) {
|
||||
public void runControllerConnector(int serverPortForControllers, Listener<?> serverSocketCreationCallback) throws IOException {
|
||||
this.serverPortForControllers = serverPortForControllers;
|
||||
log.info("Starting controller connector at " + serverPortForControllers);
|
||||
controllerConnector = BinaryProtocolServer.tcpServerSocket(controllerSocket -> () -> {
|
||||
|
|
|
@ -4,8 +4,10 @@ import com.rusefi.proxy.client.LocalApplicationProxy;
|
|||
import com.rusefi.tools.online.HttpUtil;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class BackendLauncher {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
/* todo
|
||||
rusEFISSLContext.setupCertificates(new File("keystore.jks"), System.getProperty("RUSEFI_KEYSTORE_PASSWORD"));
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue