Skip to content

Commit

Permalink
Normalized thread names
Browse files Browse the repository at this point in the history
Related to openhab#8216

Signed-off-by: Hilbrand Bouwkamp <[email protected]>
  • Loading branch information
Hilbrand committed Dec 29, 2020
1 parent 1cc6577 commit edf5694
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void scheduleConnectRetry(long waitMinutes) {

protected void startMsgReader() {
synchronized (msgReaderThreadLock) {
Thread mrt = new Thread(this::readerThread, "AD Reader");
Thread mrt = new Thread(this::readerThread, "OH-binding-" + getThing().getUID() + "-AD Reader");
mrt.setDaemon(true);
mrt.start();
msgReaderThread = mrt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
public class SocketChannelSession implements SocketSession {
private final Logger logger = LoggerFactory.getLogger(SocketChannelSession.class);

/**
* The uid of the calling thing
*/
private final String uid;
/**
* The host/ip address to connect to
*/
Expand Down Expand Up @@ -77,17 +81,19 @@ public class SocketChannelSession implements SocketSession {
/**
* Creates the socket session from the given host and port
*
* @param uid the thing uid of the calling thing
* @param host a non-null, non-empty host/ip address
* @param port the port number between 1 and 65535
*/
public SocketChannelSession(String host, int port) {
public SocketChannelSession(String uid, String host, int port) {
if (host == null || host.trim().length() == 0) {
throw new IllegalArgumentException("Host cannot be null or empty");
}

if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1 and 65535");
}
this.uid = uid;
this.host = host;
this.port = port;
}
Expand Down Expand Up @@ -129,8 +135,8 @@ public void connect() throws IOException {
}

socketChannel.set(channel);
new Thread(dispatcher).start();
new Thread(responseReader).start();
new Thread(dispatcher, "OH-binding-" + uid + "-dispatcher").start();
new Thread(responseReader, "OH-binding-" + uid + "-responseReader").start();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public void initialize() {
return;
}

session = new SocketChannelSession(config.getIpAddress(), 23);
session = new SocketChannelSession(getThing().getUID().getAsString(), config.getIpAddress(), 23);
atlonaHandler = new AtlonaPro3PortocolHandler(session, config, getCapabilities(),
new StatefulHandlerCallback(new AtlonaHandlerCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ public void initialize() {
}, executor);

serialHandler = serialPortFuture
.thenApply(sp -> new BlueGigaSerialHandler(inputStream.get(), outputStream.get()));
.thenApply(sp -> new BlueGigaSerialHandler(getThing().getUID().getAsString(), inputStream.get(),
outputStream.get()));
transactionManager = serialHandler.thenApply(sh -> {
BlueGigaTransactionManager th = new BlueGigaTransactionManager(sh, executor);
sh.addHandlerListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public class BlueGigaSerialHandler {
private final InputStream inputStream;
private final Thread parserThread;

public BlueGigaSerialHandler(final InputStream inputStream, final OutputStream outputStream) {
public BlueGigaSerialHandler(final String uid, final InputStream inputStream, final OutputStream outputStream) {
this.outputStream = outputStream;
this.inputStream = inputStream;

flush();
parserThread = createBlueGigaBLEHandler();
parserThread = createBlueGigaBLEHandler(uid);
parserThread.setUncaughtExceptionHandler((t, th) -> {
logger.warn("BluegigaSerialHandler terminating due to unhandled error", th);
});
Expand Down Expand Up @@ -323,7 +323,7 @@ private void inboundMessageHandlerLoop() {
logger.debug("BlueGiga BLE exited.");
}

private Thread createBlueGigaBLEHandler() {
return new Thread(this::inboundMessageHandlerLoop, "BlueGigaBLEHandler");
private Thread createBlueGigaBLEHandler(String uid) {
return new Thread(this::inboundMessageHandlerLoop, "OH-binding-" + uid + "-BlueGigaBLEHandler");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public class CaddxCommunicator implements SerialPortEventListener {
private boolean unStuff = false;
private int tempAsciiByte = 0;

public CaddxCommunicator(SerialPortManager portManager, CaddxProtocol protocol, String serialPortName, int baudRate)
public CaddxCommunicator(String uid, SerialPortManager portManager, CaddxProtocol protocol, String serialPortName,
int baudRate)
throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException {
this.portManager = portManager;
this.protocol = protocol;
Expand Down Expand Up @@ -101,7 +102,7 @@ public CaddxCommunicator(SerialPortManager portManager, CaddxProtocol protocol,
serialPort.notifyOnDataAvailable(true);
serialPort.addEventListener(this);

communicator = new Thread(this::messageDispatchLoop, "Caddx Communicator");
communicator = new Thread(this::messageDispatchLoop, "OH-binding-" + uid + "-Caddx Communicator");
communicator.setDaemon(true);
communicator.start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public void initialize() {
protocol);

try {
communicator = new CaddxCommunicator(portManager, protocol, serialPortName, baudRate);
communicator = new CaddxCommunicator(getThing().getUID().getAsString(), portManager, protocol,
serialPortName, baudRate);
} catch (IOException | TooManyListenersException | UnsupportedCommOperationException | PortInUseException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Communication cannot be initialized. " + e.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void openConnection() {
tcpOutput = new OutputStreamWriter(tcpSocket.getOutputStream(), "US-ASCII");
tcpInput = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream()));

Thread tcpListener = new Thread(new TCPListener());
Thread tcpListener = new Thread(new TCPListener(), "OH-binding-" + getThing().getUID() + "-tcplistener");
tcpListener.start();

setConnected(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void openConnection() {
tcpOutput = new OutputStreamWriter(tcpSocket.getOutputStream(), "US-ASCII");
tcpInput = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream()));

Thread tcpListener = new Thread(new TCPListener());
Thread tcpListener = new Thread(new TCPListener(), "OH-binding-" + getThing().getUID() + "-tcplistener");
tcpListener.start();

setConnected(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public int getPort() {

public void start() {
running = true;
Thread localThread = new Thread(this::run, "HarmonyDiscoveryServer(tcp/" + getPort() + ")");
Thread localThread = new Thread(this::run, "OH-binding-HarmonyDiscoveryServer(tcp/" + getPort() + ")");
localThread.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void start() throws IOException {

networkService = new BinRpcNetworkService(listener, config);
networkServiceThread = new Thread(networkService);
networkServiceThread.setName("HomematicRpcServer");
networkServiceThread.setName("OH-binding-HomematicRpcServer");
networkServiceThread.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private RequestQueueManager() {

private void setParamsAndStart(@Nullable Thread thread) {
if (thread != null) {
thread.setName("Insteon Request Queue Reader");
thread.setName("OH-binding-Insteon Request Queue Reader");
thread.setDaemon(true);
thread.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void start() {

private void setParamsAndStart(@Nullable Thread thread) {
if (thread != null) {
thread.setName("Insteon Poll Queue Reader");
thread.setName("OH-binding-Insteon Poll Queue Reader");
thread.setDaemon(true);
thread.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void start() {

private void setParamsAndStart(@Nullable Thread thread, String type) {
if (thread != null) {
thread.setName("Insteon " + logName + " " + type);
thread.setName("OH-binding-Insteon " + logName + " " + type);
thread.setDaemon(true);
thread.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean open() {

private void setParamsAndStart(@Nullable Thread thread) {
if (thread != null) {
thread.setName("Insteon Hub Poller");
thread.setName("OH-binding-Insteon Hub Poller");
thread.setDaemon(true);
thread.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void start() {
selector = Selector.open();

if (transceiverThread == null) {
transceiverThread = new Thread(transceiverRunnable, "openHAB-Keba-Transceiver");
transceiverThread = new Thread(transceiverRunnable, "OH-binding-Keba-Transceiver");
transceiverThread.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private Utils() {
}

static Thread backgroundThread(Runnable r, Class<?> clazz, @Nullable String instance) {
String name = LinuxInputBindingConstants.BINDING_ID + " :: " + clazz.getSimpleName();
String name = "OH-binding-" + LinuxInputBindingConstants.BINDING_ID + " :: " + clazz.getSimpleName();
if (instance != null) {
name += " :: " + instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public PrgBridgeHandler(Bridge bridge) {
}

final PrgBridgeConfig config = getPrgBridgeConfig();
session = new SocketSession(config.getIpAddress(), 23);
session = new SocketSession(getThing().getUID().getAsString(), config.getIpAddress(), 23);

protocolHandler = new PrgProtocolHandler(session, new PrgHandlerCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
public class SocketSession {
private final Logger logger = LoggerFactory.getLogger(SocketSession.class);

/**
* The uid of the calling thing
*/
private final String uid;
/**
* The host/ip address to connect to
*/
Expand Down Expand Up @@ -87,17 +91,19 @@ public class SocketSession {
/**
* Creates the socket session from the given host and port
*
* @param uid the thing uid of the calling thing
* @param host a non-null, non-empty host/ip address
* @param port the port number between 1 and 65535
*/
public SocketSession(String host, int port) {
public SocketSession(String uid, String host, int port) {
if (host == null || host.trim().length() == 0) {
throw new IllegalArgumentException("Host cannot be null or empty");
}

if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1 and 65535");
}
this.uid = uid;
this.host = host;
this.port = port;
}
Expand Down Expand Up @@ -133,8 +139,8 @@ public void connect() throws IOException {
writer = new PrintStream(client.getOutputStream());
reader = new BufferedReader(new InputStreamReader(client.getInputStream()));

new Thread(responseReader).start();
new Thread(dispatcher).start();
new Thread(responseReader, "OH-binding-" + uid + "-responseReader").start();
new Thread(dispatcher, "OH-binding-" + uid + "-dispatcher").start();
}

/**
Expand Down

0 comments on commit edf5694

Please sign in to comment.