proxy progress

This commit is contained in:
rusefi 2020-07-22 18:24:18 -04:00
parent 679906aebb
commit 2b8f93f337
4 changed files with 31 additions and 18 deletions

View File

@ -41,7 +41,9 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
public static final Function<Integer, ServerSocket> PLAIN_SOCKET_FACTORY = port -> {
try {
return new ServerSocket(port);
ServerSocket serverSocket = new ServerSocket(port);
Logger.CONSOLE.info("ServerSocket " + port + " created");
return serverSocket;
} catch (IOException e) {
throw new IllegalStateException("Error binding server socket " + port, e);
}

View File

@ -37,7 +37,7 @@ public class BaseBroadcastingThread {
if (command == Fields.TS_HELLO_COMMAND) {
// respond on hello request with information about session
logger.info("Sending out " + sessionDetails);
logger.info("Sending to controller connector@proxy: " + sessionDetails);
new HelloCommand(logger, sessionDetails.toJson()).handle(stream);
} else {
handleCommand(packet, stream);

View File

@ -42,10 +42,10 @@ public class NetworkConnector {
}
});
System.out.println("Connecting to controller...");
Logger.CONSOLE.info("Connecting to controller...");
onConnected.await(1, TimeUnit.MINUTES);
if (onConnected.getCount() != 0) {
System.out.println("Connection to controller failed");
Logger.CONSOLE.info("Connection to controller failed");
return null;
}

View File

@ -7,8 +7,9 @@ import com.rusefi.io.IoStream;
import com.rusefi.io.commands.GetOutputsCommand;
import com.rusefi.io.commands.HelloCommand;
import com.rusefi.io.tcp.TcpIoStream;
import com.rusefi.shared.FileUtil;
import net.jcip.annotations.GuardedBy;
import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
@ -29,6 +30,8 @@ public class ControllerConnectionState {
*/
private UserDetails userDetails;
private ControllerKey controllerKey;
@GuardedBy("this")
private boolean isUsed;
public ControllerConnectionState(Socket clientSocket, Logger logger, UserDetailsResolver userDetailsResolver) {
this.clientSocket = clientSocket;
@ -56,7 +59,7 @@ public class ControllerConnectionState {
public void close() {
isClosed = true;
close(clientSocket);
FileUtil.close(clientSocket);
}
public void requestControllerInfo() throws IOException {
@ -85,21 +88,9 @@ public class ControllerConnectionState {
return sessionDetails;
}
private static void close(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException ignored) {
// ignored
}
}
}
public void runEndlessLoop() throws IOException {
while (true) {
getOutputs();
}
}
@ -112,4 +103,24 @@ public class ControllerConnectionState {
if (packet == null)
throw new IOException("No response");
}
/**
* @return true if acquired successfully, false if not
*/
public synchronized boolean acquire() {
if (isUsed)
return false;
isUsed = true;
return true;
}
public synchronized boolean isUsed() {
return isUsed;
}
public synchronized void release() {
if (!isUsed)
throw new IllegalStateException("Not acquired by anyone");
isUsed = false;
}
}