From 479987959fb29c30e0ca65e042946641bea20e27 Mon Sep 17 00:00:00 2001 From: mlobstein Date: Wed, 26 Aug 2020 14:49:12 -0500 Subject: [PATCH] [oppo] Fix thread naming convention (#8347) Signed-off-by: Michael Lobstein --- bundles/org.openhab.binding.oppo/pom.xml | 4 +++- .../oppo/internal/communication/OppoIpConnector.java | 7 +++++-- .../oppo/internal/communication/OppoReaderThread.java | 6 +++--- .../oppo/internal/communication/OppoSerialConnector.java | 7 +++++-- .../openhab/binding/oppo/internal/handler/OppoHandler.java | 5 +++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.oppo/pom.xml b/bundles/org.openhab.binding.oppo/pom.xml index 76d018b504c76..1f882c2d4d5bf 100644 --- a/bundles/org.openhab.binding.oppo/pom.xml +++ b/bundles/org.openhab.binding.oppo/pom.xml @@ -1,4 +1,6 @@ - + + 4.0.0 diff --git a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoIpConnector.java b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoIpConnector.java index 3ecd13c724925..b1bc436b68dc4 100644 --- a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoIpConnector.java +++ b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoIpConnector.java @@ -37,6 +37,7 @@ public class OppoIpConnector extends OppoConnector { private final @Nullable String address; private final int port; + private final String uid; private @Nullable Socket clientSocket; @@ -45,10 +46,12 @@ public class OppoIpConnector extends OppoConnector { * * @param address the IP address of the player or serial over ip adapter * @param port the TCP port to be used + * @param uid the thing uid string */ - public OppoIpConnector(@Nullable String address, int port) { + public OppoIpConnector(@Nullable String address, int port, String uid) { this.address = address; this.port = port; + this.uid = uid; } @Override @@ -61,7 +64,7 @@ public synchronized void open() throws OppoException { dataOut = new DataOutputStream(clientSocket.getOutputStream()); dataIn = new DataInputStream(clientSocket.getInputStream()); - Thread thread = new OppoReaderThread(this, this.address + ":" + this.port); + Thread thread = new OppoReaderThread(this, this.uid, this.address + ":" + this.port); setReaderThread(thread); thread.start(); diff --git a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoReaderThread.java b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoReaderThread.java index 9d99e4596e1b8..eaa61bc452d42 100644 --- a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoReaderThread.java +++ b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoReaderThread.java @@ -15,7 +15,6 @@ import java.util.Arrays; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.oppo.internal.OppoBindingConstants; import org.openhab.binding.oppo.internal.OppoException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,10 +39,11 @@ public class OppoReaderThread extends Thread { * Constructor * * @param connector the object that should handle the received message + * @param uid the thing uid string * @param connectionId a string that uniquely identifies the particular connection */ - public OppoReaderThread(OppoConnector connector, String connectionId) { - super("OH-binding-" + OppoBindingConstants.THING_TYPE_PLAYER + "-" + connectionId); + public OppoReaderThread(OppoConnector connector, String uid, String connectionId) { + super("OH-binding-" + uid + "-" + connectionId); this.connector = connector; setDaemon(true); } diff --git a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoSerialConnector.java b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoSerialConnector.java index ff288e0dcf7a9..9e8d282f01a50 100644 --- a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoSerialConnector.java +++ b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/communication/OppoSerialConnector.java @@ -39,6 +39,7 @@ public class OppoSerialConnector extends OppoConnector { private final String serialPortName; private final SerialPortManager serialPortManager; + private final String uid; private @Nullable SerialPort serialPort; @@ -47,10 +48,12 @@ public class OppoSerialConnector extends OppoConnector { * * @param serialPortManager the serial port manager * @param serialPortName the serial port name to be used + * @param uid the thing uid string */ - public OppoSerialConnector(SerialPortManager serialPortManager, String serialPortName) { + public OppoSerialConnector(SerialPortManager serialPortManager, String serialPortName, String uid) { this.serialPortManager = serialPortManager; this.serialPortName = serialPortName; + this.uid = uid; } @Override @@ -83,7 +86,7 @@ public synchronized void open() throws OppoException { } } - Thread thread = new OppoReaderThread(this, this.serialPortName); + Thread thread = new OppoReaderThread(this, this.uid, this.serialPortName); setReaderThread(thread); thread.start(); diff --git a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java index 46aefa1be1363..0f588878ade01 100644 --- a/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java +++ b/bundles/org.openhab.binding.oppo/src/main/java/org/openhab/binding/oppo/internal/handler/OppoHandler.java @@ -112,6 +112,7 @@ public OppoHandler(Thing thing, OppoStateDescriptionOptionProvider stateDescript @Override public void initialize() { OppoThingConfiguration config = getConfigAs(OppoThingConfiguration.class); + final String uid = this.getThing().getUID().getAsString(); // Check configuration settings String configError = null; @@ -157,9 +158,9 @@ public void initialize() { } if (serialPort != null) { - connector = new OppoSerialConnector(serialPortManager, serialPort); + connector = new OppoSerialConnector(serialPortManager, serialPort, uid); } else if (port != null) { - connector = new OppoIpConnector(host, port); + connector = new OppoIpConnector(host, port, uid); connector.overrideCmdPreamble(override); } else { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,