proxy progress - better thread names, better logging
This commit is contained in:
parent
0d91fec8ca
commit
4602442912
|
@ -131,7 +131,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
|
|
||||||
private SensorCentral.SensorListener rpmListener;
|
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) {
|
public BinaryProtocol(LinkManager linkManager, final Logger logger, IoStream stream, IncomingDataBuffer dataBuffer) {
|
||||||
this.linkManager = linkManager;
|
this.linkManager = linkManager;
|
||||||
|
|
|
@ -16,8 +16,7 @@ public interface ByteReader {
|
||||||
* @see #COMMUNICATION_EXECUTOR
|
* @see #COMMUNICATION_EXECUTOR
|
||||||
*/
|
*/
|
||||||
Executor threadExecutor = Executors.newSingleThreadExecutor(r -> {
|
Executor threadExecutor = Executors.newSingleThreadExecutor(r -> {
|
||||||
Thread t = new Thread(r);
|
Thread t = new Thread(r, "IO executor thread");
|
||||||
t.setName("IO executor thread");
|
|
||||||
t.setDaemon(true); // need daemon thread so that COM thread is also daemon
|
t.setDaemon(true); // need daemon thread so that COM thread is also daemon
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class BinaryProtocolProxy {
|
||||||
TcpIoStream clientStream = new TcpIoStream("[[proxy]] ", logger, clientSocket);
|
TcpIoStream clientStream = new TcpIoStream("[[proxy]] ", logger, clientSocket);
|
||||||
runProxy(targetEcuSocket, clientStream);
|
runProxy(targetEcuSocket, clientStream);
|
||||||
} catch (IOException e) {
|
} 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
|
* Each client socket is running on it's own thread
|
||||||
*/
|
*/
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
byte firstByte = clientStream.getDataBuffer().readByte();
|
byte firstByte = clientStream.getDataBuffer().readByte();
|
||||||
if (firstByte == COMMAND_PROTOCOL) {
|
if (firstByte == COMMAND_PROTOCOL) {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package com.rusefi.autodetect;
|
package com.rusefi.autodetect;
|
||||||
|
|
||||||
import com.rusefi.FileLog;
|
import com.rusefi.FileLog;
|
||||||
|
import com.rusefi.NamedThreadFactory;
|
||||||
import com.rusefi.io.IoStream;
|
import com.rusefi.io.IoStream;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -19,6 +19,8 @@ import java.util.function.Function;
|
||||||
* Andrey Belomutskiy, (c) 2013-2020
|
* Andrey Belomutskiy, (c) 2013-2020
|
||||||
*/
|
*/
|
||||||
public class PortDetector {
|
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
|
* Connect to all serial ports and find out which one respond first
|
||||||
* @param callback
|
* @param callback
|
||||||
|
@ -34,7 +36,7 @@ public class PortDetector {
|
||||||
CountDownLatch portFound = new CountDownLatch(1);
|
CountDownLatch portFound = new CountDownLatch(1);
|
||||||
AtomicReference<String> result = new AtomicReference<>();
|
AtomicReference<String> result = new AtomicReference<>();
|
||||||
for (String serialPort : serialPorts) {
|
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);
|
serialFinder.add(thread);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.rusefi.proxy;
|
package com.rusefi.proxy;
|
||||||
|
|
||||||
import com.opensr5.Logger;
|
import com.opensr5.Logger;
|
||||||
|
import com.rusefi.NamedThreadFactory;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.config.generated.Fields;
|
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;
|
import static com.rusefi.io.tcp.BinaryProtocolServer.readPromisedBytes;
|
||||||
|
|
||||||
public class BaseBroadcastingThread {
|
public class BaseBroadcastingThread {
|
||||||
|
private static final NamedThreadFactory BASE_BROADCASTING_THREAD = new NamedThreadFactory("BaseBroadcastingThread");
|
||||||
private final Thread thread;
|
private final Thread thread;
|
||||||
|
|
||||||
public BaseBroadcastingThread(Socket socket, SessionDetails sessionDetails, Logger logger) throws IOException {
|
public BaseBroadcastingThread(Socket socket, SessionDetails sessionDetails, Logger logger) throws IOException {
|
||||||
TcpIoStream stream = new TcpIoStream("[broadcast] ", logger, socket);
|
TcpIoStream stream = new TcpIoStream("[broadcast] ", logger, socket);
|
||||||
IncomingDataBuffer in = stream.getDataBuffer();
|
IncomingDataBuffer in = stream.getDataBuffer();
|
||||||
|
|
||||||
thread = new Thread(() -> {
|
thread = BASE_BROADCASTING_THREAD.newThread(() -> {
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
int length = getPacketLength(in, () -> {
|
int length = getPacketLength(in, () -> {
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class Backend implements Closeable {
|
||||||
public static final String VERSION_PATH = "/version";
|
public static final String VERSION_PATH = "/version";
|
||||||
public static final String BACKEND_VERSION = "0.0001";
|
public static final String BACKEND_VERSION = "0.0001";
|
||||||
public static final int SERVER_PORT_FOR_CONTROLLERS = 8003;
|
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,
|
private final FkRegex showOnlineControllers = new FkRegex(ProxyClient.LIST_CONTROLLERS_PATH,
|
||||||
(Take) req -> getControllersOnline()
|
(Take) req -> getControllersOnline()
|
||||||
|
@ -166,8 +167,7 @@ public class Backend implements Closeable {
|
||||||
BinaryProtocolProxy.runProxy(state.getStream(), applicationClientStream);
|
BinaryProtocolProxy.runProxy(state.getStream(), applicationClientStream);
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
logger.info("Application Connector: Got error " + e);
|
||||||
logger.info("Got error " + e);
|
|
||||||
} finally {
|
} finally {
|
||||||
close(applicationConnectionState);
|
close(applicationConnectionState);
|
||||||
}
|
}
|
||||||
|
@ -224,9 +224,12 @@ public class Backend implements Closeable {
|
||||||
JsonArrayBuilder builder = Json.createArrayBuilder();
|
JsonArrayBuilder builder = Json.createArrayBuilder();
|
||||||
List<ApplicationConnectionState> applications = getApplications();
|
List<ApplicationConnectionState> applications = getApplications();
|
||||||
for (ApplicationConnectionState application : applications) {
|
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();
|
.build();
|
||||||
builder.add(clientObject);
|
builder.add(applicationObject);
|
||||||
}
|
}
|
||||||
return new RsJson(builder.build());
|
return new RsJson(builder.build());
|
||||||
}
|
}
|
||||||
|
@ -236,17 +239,16 @@ public class Backend implements Closeable {
|
||||||
JsonArrayBuilder builder = Json.createArrayBuilder();
|
JsonArrayBuilder builder = Json.createArrayBuilder();
|
||||||
List<ControllerConnectionState> clients = getControllers();
|
List<ControllerConnectionState> clients = getControllers();
|
||||||
for (ControllerConnectionState client : clients) {
|
for (ControllerConnectionState client : clients) {
|
||||||
|
JsonObject controllerObject = Json.createObjectBuilder()
|
||||||
JsonObject clientObject = Json.createObjectBuilder()
|
|
||||||
.add(UserDetails.USER_ID, client.getUserDetails().getUserId())
|
.add(UserDetails.USER_ID, client.getUserDetails().getUserId())
|
||||||
.add(UserDetails.USERNAME, client.getUserDetails().getUserName())
|
.add(UserDetails.USERNAME, client.getUserDetails().getUserName())
|
||||||
.add(ControllerInfo.SIGNATURE, client.getSessionDetails().getControllerInfo().getSignature())
|
.add(ControllerInfo.SIGNATURE, client.getSessionDetails().getControllerInfo().getSignature())
|
||||||
.add(ControllerInfo.VEHICLE_NAME, client.getSessionDetails().getControllerInfo().getVehicleName())
|
.add(ControllerInfo.VEHICLE_NAME, client.getSessionDetails().getControllerInfo().getVehicleName())
|
||||||
.add(ControllerInfo.ENGINE_MAKE, client.getSessionDetails().getControllerInfo().getEngineMake())
|
.add(ControllerInfo.ENGINE_MAKE, client.getSessionDetails().getControllerInfo().getEngineMake())
|
||||||
.add(ControllerInfo.ENGINE_CODE, client.getSessionDetails().getControllerInfo().getEngineCode())
|
.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();
|
.build();
|
||||||
builder.add(clientObject);
|
builder.add(controllerObject);
|
||||||
}
|
}
|
||||||
return new RsJson(builder.build());
|
return new RsJson(builder.build());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue