From 1933a4c31a0d98b8b24a456fa9c1009c12159bff Mon Sep 17 00:00:00 2001 From: lolodomo Date: Sat, 1 Aug 2020 13:03:31 +0200 Subject: [PATCH] [rfxcom] Thread naming (#8235) Related to #8216 Signed-off-by: Laurent Garnier --- .../binding/rfxcom/internal/RFXComBindingConstants.java | 2 ++ .../rfxcom/internal/connector/RFXComJD2XXConnector.java | 8 +++++++- .../rfxcom/internal/connector/RFXComSerialConnector.java | 8 +++++--- .../rfxcom/internal/connector/RFXComStreamReader.java | 3 ++- .../rfxcom/internal/connector/RFXComTcpConnector.java | 8 +++++++- .../rfxcom/internal/handler/RFXComBridgeHandler.java | 8 +++++--- 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/RFXComBindingConstants.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/RFXComBindingConstants.java index e5b5beb82d423..8776fa83c9dfa 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/RFXComBindingConstants.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/RFXComBindingConstants.java @@ -242,4 +242,6 @@ public class RFXComBindingConstants { put(PacketType.WIND, RFXComBindingConstants.THING_TYPE_WIND); } }); + + public static final String THREAD_NAME_PREFIX = "OH-" + BINDING_ID + "-"; } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComJD2XXConnector.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComJD2XXConnector.java index 2caa0a91296cb..255f3fc222286 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComJD2XXConnector.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComJD2XXConnector.java @@ -34,8 +34,14 @@ public class RFXComJD2XXConnector extends RFXComBaseConnector { private JD2XX serialPort; private JD2XXOutputStream out; + private final String readerThreadName; private Thread readerThread; + public RFXComJD2XXConnector(String readerThreadName) { + super(); + this.readerThreadName = readerThreadName; + } + @Override public void connect(RFXComBridgeConfiguration device) throws IOException { logger.info("Connecting to RFXCOM device '{}' using JD2XX.", device.bridgeId); @@ -57,7 +63,7 @@ public void connect(RFXComBridgeConfiguration device) throws IOException { in.reset(); } - readerThread = new RFXComStreamReader(this); + readerThread = new RFXComStreamReader(this, readerThreadName); readerThread.start(); } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComSerialConnector.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComSerialConnector.java index 07191a61fd495..9dfa423f5a7cd 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComSerialConnector.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComSerialConnector.java @@ -39,13 +39,15 @@ public class RFXComSerialConnector extends RFXComBaseConnector implements Serial private OutputStream out; private SerialPort serialPort; - private SerialPortManager serialPortManager; + private final SerialPortManager serialPortManager; + private final String readerThreadName; private Thread readerThread; - public RFXComSerialConnector(SerialPortManager serialPortManager) { + public RFXComSerialConnector(SerialPortManager serialPortManager, String readerThreadName) { super(); this.serialPortManager = serialPortManager; + this.readerThreadName = readerThreadName; } @Override @@ -81,7 +83,7 @@ public void connect(RFXComBridgeConfiguration device) } catch (TooManyListenersException e) { } - readerThread = new RFXComStreamReader(this); + readerThread = new RFXComStreamReader(this, readerThreadName); readerThread.start(); } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComStreamReader.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComStreamReader.java index e35d17c363580..b7774e6671013 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComStreamReader.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComStreamReader.java @@ -42,7 +42,8 @@ public void uncaughtException(Thread thread, Throwable throwable) { } } - public RFXComStreamReader(RFXComBaseConnector connector) { + public RFXComStreamReader(RFXComBaseConnector connector, String threadName) { + super(threadName); this.connector = connector; setUncaughtExceptionHandler(new ExceptionHandler()); } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComTcpConnector.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComTcpConnector.java index e2a0b088e76c9..3fdd4d77ffb9e 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComTcpConnector.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/connector/RFXComTcpConnector.java @@ -34,8 +34,14 @@ public class RFXComTcpConnector extends RFXComBaseConnector { private OutputStream out; private Socket socket; + private final String readerThreadName; private Thread readerThread; + public RFXComTcpConnector(String readerThreadName) { + super(); + this.readerThreadName = readerThreadName; + } + @Override public void connect(RFXComBridgeConfiguration device) throws IOException { logger.info("Connecting to RFXCOM at {}:{} over TCP/IP", device.host, device.port); @@ -49,7 +55,7 @@ public void connect(RFXComBridgeConfiguration device) throws IOException { in.reset(); } - readerThread = new RFXComStreamReader(this); + readerThread = new RFXComStreamReader(this, readerThreadName); readerThread.start(); } diff --git a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java index a3b37a5a61034..d7a29297f05a7 100644 --- a/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java +++ b/bundles/org.openhab.binding.rfxcom/src/main/java/org/openhab/binding/rfxcom/internal/handler/RFXComBridgeHandler.java @@ -31,6 +31,7 @@ import org.eclipse.smarthome.core.util.HexUtils; import org.eclipse.smarthome.io.transport.serial.SerialPortManager; import org.openhab.binding.rfxcom.internal.DeviceMessageListener; +import org.openhab.binding.rfxcom.internal.RFXComBindingConstants; import org.openhab.binding.rfxcom.internal.config.RFXComBridgeConfiguration; import org.openhab.binding.rfxcom.internal.connector.RFXComConnectorInterface; import org.openhab.binding.rfxcom.internal.connector.RFXComEventListener; @@ -169,17 +170,18 @@ private synchronized void connect() { logger.debug("Connecting to RFXCOM transceiver"); try { + String readerThreadName = RFXComBindingConstants.THREAD_NAME_PREFIX + getThing().getUID().getAsString(); if (configuration.serialPort != null) { if (connector == null) { - connector = new RFXComSerialConnector(serialPortManager); + connector = new RFXComSerialConnector(serialPortManager, readerThreadName); } } else if (configuration.bridgeId != null) { if (connector == null) { - connector = new RFXComJD2XXConnector(); + connector = new RFXComJD2XXConnector(readerThreadName); } } else if (configuration.host != null) { if (connector == null) { - connector = new RFXComTcpConnector(); + connector = new RFXComTcpConnector(readerThreadName); } }