diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/RotelBindingConstants.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/RotelBindingConstants.java index eedcc41344719..c8594e2b8bc8e 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/RotelBindingConstants.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/RotelBindingConstants.java @@ -151,4 +151,6 @@ public class RotelBindingConstants { // List of all properties public static final String PROPERTY_PROTOCOL = "protocol"; + + public static final String THREAD_NAME_PREFIX = "OH-" + BINDING_ID + "-"; } diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java index 719684b015d49..14e4217f875ab 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelConnector.java @@ -186,6 +186,7 @@ public abstract class RotelConnector { /** true if the connection is established, false if not */ private boolean connected; + protected String readerThreadName; private @Nullable Thread readerThread; private List listeners = new ArrayList<>(); @@ -221,13 +222,15 @@ public abstract class RotelConnector { * @param model the Rotel model in use * @param protocol the protocol to be used * @param simu whether the communication is simulated or real + * @param readerThreadName the name of thread to be created */ public RotelConnector(RotelModel model, RotelProtocol protocol, Map sourcesLabels, - boolean simu) { + boolean simu, String readerThreadName) { this.model = model; this.protocol = protocol; this.sourcesLabels = sourcesLabels; this.simu = simu; + this.readerThreadName = readerThreadName; } /** diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelIpConnector.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelIpConnector.java index 237d7f68baab7..edbf5b52e40d3 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelIpConnector.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelIpConnector.java @@ -50,10 +50,11 @@ public class RotelIpConnector extends RotelConnector { * @param port the TCP port to be used * @param model the projector model in use * @param protocol the protocol to be used + * @param readerThreadName the name of thread to be created */ public RotelIpConnector(String address, Integer port, RotelModel model, RotelProtocol protocol, - Map sourcesLabels) { - super(model, protocol, sourcesLabels, false); + Map sourcesLabels, String readerThreadName) { + super(model, protocol, sourcesLabels, false, readerThreadName); this.address = address; this.port = port; @@ -69,7 +70,7 @@ public synchronized void open() throws RotelException { dataOut = new DataOutputStream(clientSocket.getOutputStream()); dataIn = new DataInputStream(clientSocket.getInputStream()); - Thread thread = new RotelReaderThread(this); + Thread thread = new RotelReaderThread(this, readerThreadName); setReaderThread(thread); thread.start(); diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelReaderThread.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelReaderThread.java index d010eebcc0860..909eafc65fbd9 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelReaderThread.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelReaderThread.java @@ -39,7 +39,8 @@ public class RotelReaderThread extends Thread { * * @param connector the object that should handle the received message */ - public RotelReaderThread(RotelConnector connector) { + public RotelReaderThread(RotelConnector connector, String threadName) { + super(threadName); this.connector = connector; } diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSerialConnector.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSerialConnector.java index f033ce087a641..0be8cc9b68d6d 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSerialConnector.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSerialConnector.java @@ -52,10 +52,11 @@ public class RotelSerialConnector extends RotelConnector { * @param serialPortName the serial port name to be used * @param model the projector model in use * @param protocol the protocol to be used + * @param readerThreadName the name of thread to be created */ public RotelSerialConnector(SerialPortManager serialPortManager, String serialPortName, RotelModel model, - RotelProtocol protocol, Map sourcesLabels) { - super(model, protocol, sourcesLabels, false); + RotelProtocol protocol, Map sourcesLabels, String readerThreadName) { + super(model, protocol, sourcesLabels, false, readerThreadName); this.serialPortManager = serialPortManager; this.serialPortName = serialPortName; @@ -93,7 +94,7 @@ public synchronized void open() throws RotelException { } } - Thread thread = new RotelReaderThread(this); + Thread thread = new RotelReaderThread(this, readerThreadName); setReaderThread(thread); thread.start(); diff --git a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java index d627859303607..fe6df3c450501 100644 --- a/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java +++ b/bundles/org.openhab.binding.rotel/src/main/java/org/openhab/binding/rotel/internal/communication/RotelSimuConnector.java @@ -80,9 +80,11 @@ public class RotelSimuConnector extends RotelConnector { * * @param model the projector model in use * @param protocol the protocol to be used + * @param readerThreadName the name of thread to be created */ - public RotelSimuConnector(RotelModel model, RotelProtocol protocol, Map sourcesLabels) { - super(model, protocol, sourcesLabels, true); + public RotelSimuConnector(RotelModel model, RotelProtocol protocol, Map sourcesLabels, + String readerThreadName) { + super(model, protocol, sourcesLabels, true, readerThreadName); this.minVolume = 0; this.maxVolume = model.hasVolumeControl() ? model.getVolumeMax() : 0; this.maxToneLevel = model.hasToneControl() ? model.getToneLevelMax() : 0; @@ -92,7 +94,7 @@ public RotelSimuConnector(RotelModel model, RotelProtocol protocol, Map()); + private RotelConnector connector = new RotelSimuConnector(DEFAULT_MODEL, RotelProtocol.HEX, new HashMap<>(), + THREAD_NAME_PREFIX); private int minVolume; private int maxVolume; @@ -291,7 +292,9 @@ public void initialize() { Map sourcesLabels = new HashMap<>(); - connector = new RotelSimuConnector(rotelModel, rotelProtocol, sourcesLabels); + String readerThreadName = THREAD_NAME_PREFIX + getThing().getUID().getAsString(); + + connector = new RotelSimuConnector(rotelModel, rotelProtocol, sourcesLabels, readerThreadName); if (rotelModel.hasVolumeControl()) { maxVolume = rotelModel.getVolumeMax(); @@ -376,12 +379,13 @@ public void initialize() { } if (USE_SIMULATED_DEVICE) { - connector = new RotelSimuConnector(rotelModel, rotelProtocol, sourcesLabels); + connector = new RotelSimuConnector(rotelModel, rotelProtocol, sourcesLabels, readerThreadName); } else if (config.serialPort != null) { connector = new RotelSerialConnector(serialPortManager, config.serialPort, rotelModel, rotelProtocol, - sourcesLabels); + sourcesLabels, readerThreadName); } else { - connector = new RotelIpConnector(config.host, config.port, rotelModel, rotelProtocol, sourcesLabels); + connector = new RotelIpConnector(config.host, config.port, rotelModel, rotelProtocol, sourcesLabels, + readerThreadName); } if (rotelModel.hasSourceControl()) {