Skip to content

Commit

Permalink
[oppo] Fix thread naming convention (#8347)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Lobstein <[email protected]>
  • Loading branch information
mlobstein authored Aug 26, 2020
1 parent ac3ac2b commit aea27b4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion bundles/org.openhab.binding.oppo/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit aea27b4

Please sign in to comment.