nicer thread names

This commit is contained in:
rusefi 2020-07-26 15:15:28 -04:00
parent a8f45d960a
commit e070a2854a
3 changed files with 9 additions and 11 deletions

View File

@ -2,10 +2,9 @@ package com.rusefi.io;
import com.devexperts.logging.Logging;
import com.opensr5.io.DataListener;
import com.rusefi.NamedThreadFactory;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.serial.AbstractIoStream;
import com.rusefi.io.tcp.TcpIoStream;
import com.rusefi.io.tcp.BinaryProtocolServer;
import java.io.IOException;
import java.util.Arrays;
@ -15,9 +14,6 @@ import java.util.concurrent.Executors;
import static com.devexperts.logging.Logging.getLogging;
public interface ByteReader {
NamedThreadFactory THREAD_FACTORY = new NamedThreadFactory("TCP connector loop", true);
Logging log = getLogging(ByteReader.class);
static void runReaderLoop(String loggingPrefix, DataListener listener, ByteReader reader, AbstractIoStream ioStream) {
@ -26,7 +22,7 @@ public interface ByteReader {
*
* @see #COMMUNICATION_EXECUTOR
*/
Executor threadExecutor = Executors.newSingleThreadExecutor(THREAD_FACTORY);
Executor threadExecutor = Executors.newSingleThreadExecutor(BinaryProtocolServer.getThreadFactory(loggingPrefix + "TCP reader"));
threadExecutor.execute(() -> {
log.info(loggingPrefix + "Running TCP connection loop");

View File

@ -11,6 +11,7 @@ import com.rusefi.io.IoStream;
import com.rusefi.io.LinkManager;
import com.rusefi.io.commands.HelloCommand;
import com.rusefi.server.rusEFISSLContext;
import org.jetbrains.annotations.NotNull;
import java.io.*;
import java.net.ServerSocket;
@ -88,7 +89,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
}
public static ServerSocketReference tcpServerSocket(Function<Socket, Runnable> clientSocketRunnableFactory, int port, String threadName, Listener serverSocketCreationCallback, Function<Integer, ServerSocket> nonSecureSocketFunction) {
ThreadFactory threadFactory = THREAD_FACTORIES_BY_NAME.computeIfAbsent(threadName, NamedThreadFactory::new);
ThreadFactory threadFactory = getThreadFactory(threadName);
Objects.requireNonNull(serverSocketCreationCallback, "serverSocketCreationCallback");
ServerSocket serverSocket = nonSecureSocketFunction.apply(port);
@ -114,6 +115,11 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
return holder;
}
@NotNull
public static ThreadFactory getThreadFactory(String threadName) {
return THREAD_FACTORIES_BY_NAME.computeIfAbsent(threadName, NamedThreadFactory::new);
}
@SuppressWarnings("InfiniteLoopStatement")
private void runProxy(LinkManager linkManager, Socket clientSocket) throws IOException {
TcpIoStream stream = new TcpIoStream("[proxy] ", clientSocket);

View File

@ -26,10 +26,6 @@ public class TcpIoStream extends AbstractIoStream {
private final Socket socket;
private final IncomingDataBuffer dataBuffer;
public TcpIoStream(Socket socket) throws IOException {
this("", socket);
}
public TcpIoStream(String loggingPrefix, Socket socket) throws IOException {
this(loggingPrefix, socket, DisconnectListener.VOID);
}