proxy progress - better thread names, better logging

This commit is contained in:
rusefi 2020-07-22 17:22:57 -04:00
parent 7e4a1223bb
commit 401abdc07f
6 changed files with 20 additions and 16 deletions

View File

@ -131,7 +131,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
private SensorCentral.SensorListener rpmListener;
private final Thread hook = new Thread(() -> closeComposites());
private final Thread hook = new Thread(() -> closeComposites(), "BinaryProtocol::hook");
public BinaryProtocol(LinkManager linkManager, final Logger logger, IoStream stream, IncomingDataBuffer dataBuffer) {
this.linkManager = linkManager;

View File

@ -16,8 +16,7 @@ public interface ByteReader {
* @see #COMMUNICATION_EXECUTOR
*/
Executor threadExecutor = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r);
t.setName("IO executor thread");
Thread t = new Thread(r, "IO executor thread");
t.setDaemon(true); // need daemon thread so that COM thread is also daemon
return t;
});

View File

@ -26,7 +26,7 @@ public class BinaryProtocolProxy {
TcpIoStream clientStream = new TcpIoStream("[[proxy]] ", logger, clientSocket);
runProxy(targetEcuSocket, clientStream);
} catch (IOException e) {
e.printStackTrace();
logger.error("BinaryProtocolProxy::run" + e);
}
}
};
@ -39,7 +39,6 @@ public class BinaryProtocolProxy {
/*
* Each client socket is running on it's own thread
*/
while (true) {
byte firstByte = clientStream.getDataBuffer().readByte();
if (firstByte == COMMAND_PROTOCOL) {

View File

@ -1,12 +1,12 @@
package com.rusefi.autodetect;
import com.rusefi.FileLog;
import com.rusefi.NamedThreadFactory;
import com.rusefi.io.IoStream;
import com.rusefi.io.LinkManager;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -19,6 +19,8 @@ import java.util.function.Function;
* Andrey Belomutskiy, (c) 2013-2020
*/
public class PortDetector {
private static final NamedThreadFactory AUTO_DETECT_PORT = new NamedThreadFactory("AutoDetectPort");
/**
* Connect to all serial ports and find out which one respond first
* @param callback
@ -34,7 +36,7 @@ public class PortDetector {
CountDownLatch portFound = new CountDownLatch(1);
AtomicReference<String> result = new AtomicReference<>();
for (String serialPort : serialPorts) {
Thread thread = new Thread(new SerialAutoChecker(FileLog.LOGGER, serialPort, portFound, result, callback));
Thread thread = AUTO_DETECT_PORT.newThread(new SerialAutoChecker(FileLog.LOGGER, serialPort, portFound, result, callback));
serialFinder.add(thread);
thread.start();
}

View File

@ -1,6 +1,7 @@
package com.rusefi.proxy;
import com.opensr5.Logger;
import com.rusefi.NamedThreadFactory;
import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.binaryprotocol.IncomingDataBuffer;
import com.rusefi.config.generated.Fields;
@ -16,13 +17,14 @@ import static com.rusefi.io.tcp.BinaryProtocolServer.getPacketLength;
import static com.rusefi.io.tcp.BinaryProtocolServer.readPromisedBytes;
public class BaseBroadcastingThread {
private static final NamedThreadFactory BASE_BROADCASTING_THREAD = new NamedThreadFactory("BaseBroadcastingThread");
private final Thread thread;
public BaseBroadcastingThread(Socket socket, SessionDetails sessionDetails, Logger logger) throws IOException {
TcpIoStream stream = new TcpIoStream("[broadcast] ", logger, socket);
IncomingDataBuffer in = stream.getDataBuffer();
thread = new Thread(() -> {
thread = BASE_BROADCASTING_THREAD.newThread(() -> {
try {
while (true) {
int length = getPacketLength(in, () -> {

View File

@ -37,6 +37,7 @@ public class Backend implements Closeable {
public static final String VERSION_PATH = "/version";
public static final String BACKEND_VERSION = "0.0001";
public static final int SERVER_PORT_FOR_CONTROLLERS = 8003;
public static final String MAX_PACKET_GAP = "MAX_PACKET_GAP";
private final FkRegex showOnlineControllers = new FkRegex(ProxyClient.LIST_CONTROLLERS_PATH,
(Take) req -> getControllersOnline()
@ -166,8 +167,7 @@ public class Backend implements Closeable {
BinaryProtocolProxy.runProxy(state.getStream(), applicationClientStream);
} catch (Throwable e) {
e.printStackTrace();
logger.info("Got error " + e);
logger.info("Application Connector: Got error " + e);
} finally {
close(applicationConnectionState);
}
@ -224,9 +224,12 @@ public class Backend implements Closeable {
JsonArrayBuilder builder = Json.createArrayBuilder();
List<ApplicationConnectionState> applications = getApplications();
for (ApplicationConnectionState application : applications) {
JsonObject clientObject = Json.createObjectBuilder()
JsonObject applicationObject = Json.createObjectBuilder()
.add(UserDetails.USER_ID, application.getUserDetails().getUserId())
.add(UserDetails.USERNAME, application.getUserDetails().getUserName())
.add(MAX_PACKET_GAP, application.getClientStream().getStreamStats().getMaxPacketGap())
.build();
builder.add(clientObject);
builder.add(applicationObject);
}
return new RsJson(builder.build());
}
@ -236,17 +239,16 @@ public class Backend implements Closeable {
JsonArrayBuilder builder = Json.createArrayBuilder();
List<ControllerConnectionState> clients = getControllers();
for (ControllerConnectionState client : clients) {
JsonObject clientObject = Json.createObjectBuilder()
JsonObject controllerObject = Json.createObjectBuilder()
.add(UserDetails.USER_ID, client.getUserDetails().getUserId())
.add(UserDetails.USERNAME, client.getUserDetails().getUserName())
.add(ControllerInfo.SIGNATURE, client.getSessionDetails().getControllerInfo().getSignature())
.add(ControllerInfo.VEHICLE_NAME, client.getSessionDetails().getControllerInfo().getVehicleName())
.add(ControllerInfo.ENGINE_MAKE, client.getSessionDetails().getControllerInfo().getEngineMake())
.add(ControllerInfo.ENGINE_CODE, client.getSessionDetails().getControllerInfo().getEngineCode())
.add("MAX_PACKET_GAP", client.getStream().getStreamStats().getMaxPacketGap())
.add(MAX_PACKET_GAP, client.getStream().getStreamStats().getMaxPacketGap())
.build();
builder.add(clientObject);
builder.add(controllerObject);
}
return new RsJson(builder.build());
}