Skip to content

Commit

Permalink
[rfxcom] Thread naming (openhab#8235)
Browse files Browse the repository at this point in the history
Related to openhab#8216

Signed-off-by: Laurent Garnier <[email protected]>
  • Loading branch information
lolodomo authored and CSchlipp committed Sep 12, 2020
1 parent c378f82 commit 1933a4c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,6 @@ public class RFXComBindingConstants {
put(PacketType.WIND, RFXComBindingConstants.THING_TYPE_WIND);
}
});

public static final String THREAD_NAME_PREFIX = "OH-" + BINDING_ID + "-";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -57,7 +63,7 @@ public void connect(RFXComBridgeConfiguration device) throws IOException {
in.reset();
}

readerThread = new RFXComStreamReader(this);
readerThread = new RFXComStreamReader(this, readerThreadName);
readerThread.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,7 +83,7 @@ public void connect(RFXComBridgeConfiguration device)
} catch (TooManyListenersException e) {
}

readerThread = new RFXComStreamReader(this);
readerThread = new RFXComStreamReader(this, readerThreadName);
readerThread.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -49,7 +55,7 @@ public void connect(RFXComBridgeConfiguration device) throws IOException {
in.reset();
}

readerThread = new RFXComStreamReader(this);
readerThread = new RFXComStreamReader(this, readerThreadName);
readerThread.start();
}

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

Expand Down

0 comments on commit 1933a4c

Please sign in to comment.