proxy progress - I am getting tired :(

This commit is contained in:
rusefi 2020-07-24 01:15:54 -04:00
parent fa328e8874
commit 64ec3d2f4d
3 changed files with 29 additions and 13 deletions

View File

@ -76,6 +76,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
/**
* Starts a new thread
*
* @param port server port to accept connections
* @param threadName
* @param socketRunnableFactory method to invoke on a new thread for each new client connection
@ -101,16 +102,18 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
if (serverSocketCreationCallback != null)
serverSocketCreationCallback.onResult(null);
Runnable runnable = () -> {
try {
while (!holder.isClosed()) {
// Wait for a connection
final Socket clientSocket = serverSocket.accept();
final Socket clientSocket;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
logger.info("Client socket closed right away" + e);
continue;
}
logger.info("Binary protocol proxy port connection");
new Thread(clientSocketRunnableFactory.apply(clientSocket), "proxy connection").start();
}
} catch (IOException e) {
throw new IllegalStateException(e);
}
};
new Thread(runnable, threadName).start();
return holder;

View File

@ -84,7 +84,7 @@ public class FullServerTest {
// start authenticator
int authenticatorPort = 7004; // local port on which authenticator accepts connections from Tuner Studio
LocalApplicationProxy.startAndRun(logger, serverPortForRemoteUsers, applicationRequest, authenticatorPort, httpPort);
LocalApplicationProxy.startAndRun(logger, serverPortForRemoteUsers, applicationRequest, authenticatorPort, httpPort, TcpIoStream.DisconnectListener.VOID);
CountDownLatch connectionEstablishedCountDownLatch = new CountDownLatch(1);

View File

@ -5,6 +5,8 @@ import com.rusefi.LocalApplicationProxy;
import com.rusefi.NamedThreadFactory;
import com.rusefi.SignatureHelper;
import com.rusefi.autoupdate.AutoupdateUtil;
import com.rusefi.io.tcp.ServerHolder;
import com.rusefi.io.tcp.TcpIoStream;
import com.rusefi.server.ApplicationRequest;
import com.rusefi.server.ControllerInfo;
import com.rusefi.server.SessionDetails;
@ -21,6 +23,7 @@ import java.io.IOException;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicReference;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
@ -72,7 +75,7 @@ public class RemoteTab {
}
private String getLocalPort() {
return getConfig().getRoot().getProperty(APPLICATION_PORT, "8100");
return getConfig().getRoot().getProperty(APPLICATION_PORT, "29001");
}
private void requestListDownload() {
@ -142,11 +145,21 @@ public class RemoteTab {
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, publicSession.getUserDetails().getUserId());
try {
LocalApplicationProxy.startAndRun(Logger.CONSOLE,
AtomicReference<ServerHolder> serverHolderAtomicReference = new AtomicReference<>();
TcpIoStream.DisconnectListener disconnectListener = () -> SwingUtilities.invokeLater(() -> {
setStatus("Disconnected");
ServerHolder serverHolder = serverHolderAtomicReference.get();
if (serverHolder != null)
serverHolder.close();
});
ServerHolder serverHolder = LocalApplicationProxy.startAndRun(Logger.CONSOLE,
LocalApplicationProxy.SERVER_PORT_FOR_APPLICATIONS,
applicationRequest,
Integer.parseInt(getLocalPort()),
HttpUtil.PROXY_JSON_API_HTTP_PORT, () -> SwingUtilities.invokeLater(() -> setStatus("Disconnected")));
HttpUtil.PROXY_JSON_API_HTTP_PORT, disconnectListener);
serverHolderAtomicReference.set(serverHolder);
} catch (IOException e) {
setStatus("IO error: " + e);
}