Normalized thread names (#9581)

Related to #8216

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
pull/9806/head
Hilbrand Bouwkamp 2021-01-12 22:10:01 +01:00 committed by GitHub
parent 79dfb43e42
commit ac3f907b36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 75 additions and 43 deletions

View File

@ -130,7 +130,7 @@ public abstract class ADBridgeHandler extends BaseBridgeHandler {
protected void startMsgReader() {
synchronized (msgReaderThreadLock) {
Thread mrt = new Thread(this::readerThread, "AD Reader");
Thread mrt = new Thread(this::readerThread, "OH-binding-" + getThing().getUID() + "-ADReader");
mrt.setDaemon(true);
mrt.start();
msgReaderThread = mrt;

View File

@ -39,6 +39,10 @@ import org.slf4j.LoggerFactory;
public class SocketChannelSession implements SocketSession {
private final Logger logger = LoggerFactory.getLogger(SocketChannelSession.class);
/**
* The uid of the calling thing
*/
private final String uid;
/**
* The host/ip address to connect to
*/
@ -77,10 +81,11 @@ public class SocketChannelSession implements SocketSession {
/**
* Creates the socket session from the given host and port
*
* @param uid the thing uid of the calling thing
* @param host a non-null, non-empty host/ip address
* @param port the port number between 1 and 65535
*/
public SocketChannelSession(String host, int port) {
public SocketChannelSession(String uid, String host, int port) {
if (host == null || host.trim().length() == 0) {
throw new IllegalArgumentException("Host cannot be null or empty");
}
@ -88,6 +93,7 @@ public class SocketChannelSession implements SocketSession {
if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1 and 65535");
}
this.uid = uid;
this.host = host;
this.port = port;
}
@ -129,8 +135,12 @@ public class SocketChannelSession implements SocketSession {
}
socketChannel.set(channel);
new Thread(dispatcher).start();
new Thread(responseReader).start();
Thread dispatcherThread = new Thread(dispatcher, "OH-binding-" + uid + "-dispatcher");
dispatcherThread.setDaemon(true);
dispatcherThread.start();
Thread responseReaderThread = new Thread(responseReader, "OH-binding-" + uid + "-responseReader");
responseReaderThread.setDaemon(true);
responseReaderThread.start();
}
@Override

View File

@ -449,7 +449,7 @@ public class AtlonaPro3Handler extends AtlonaHandler<AtlonaPro3Capabilities> {
return;
}
session = new SocketChannelSession(config.getIpAddress(), 23);
session = new SocketChannelSession(getThing().getUID().getAsString(), config.getIpAddress(), 23);
atlonaHandler = new AtlonaPro3PortocolHandler(session, config, getCapabilities(),
new StatefulHandlerCallback(new AtlonaHandlerCallback() {
@Override

View File

@ -234,7 +234,8 @@ public class BlueGigaBridgeHandler extends AbstractBluetoothBridgeHandler<BlueGi
}, executor);
serialHandler = serialPortFuture
.thenApply(sp -> new BlueGigaSerialHandler(inputStream.get(), outputStream.get()));
.thenApply(sp -> new BlueGigaSerialHandler(getThing().getUID().getAsString(), inputStream.get(),
outputStream.get()));
transactionManager = serialHandler.thenApply(sh -> {
BlueGigaTransactionManager th = new BlueGigaTransactionManager(sh, executor);
sh.addHandlerListener(this);

View File

@ -59,12 +59,12 @@ public class BlueGigaSerialHandler {
private final InputStream inputStream;
private final Thread parserThread;
public BlueGigaSerialHandler(final InputStream inputStream, final OutputStream outputStream) {
public BlueGigaSerialHandler(final String uid, final InputStream inputStream, final OutputStream outputStream) {
this.outputStream = outputStream;
this.inputStream = inputStream;
flush();
parserThread = createBlueGigaBLEHandler();
parserThread = createBlueGigaBLEHandler(uid);
parserThread.setUncaughtExceptionHandler((t, th) -> {
logger.warn("BluegigaSerialHandler terminating due to unhandled error", th);
});
@ -323,7 +323,7 @@ public class BlueGigaSerialHandler {
logger.debug("BlueGiga BLE exited.");
}
private Thread createBlueGigaBLEHandler() {
return new Thread(this::inboundMessageHandlerLoop, "BlueGigaBLEHandler");
private Thread createBlueGigaBLEHandler(String uid) {
return new Thread(this::inboundMessageHandlerLoop, "OH-binding-" + uid + "-blueGigaBLEHandler");
}
}

View File

@ -68,7 +68,8 @@ public class CaddxCommunicator implements SerialPortEventListener {
private boolean unStuff = false;
private int tempAsciiByte = 0;
public CaddxCommunicator(SerialPortManager portManager, CaddxProtocol protocol, String serialPortName, int baudRate)
public CaddxCommunicator(String uid, SerialPortManager portManager, CaddxProtocol protocol, String serialPortName,
int baudRate)
throws UnsupportedCommOperationException, PortInUseException, IOException, TooManyListenersException {
this.portManager = portManager;
this.protocol = protocol;
@ -101,7 +102,7 @@ public class CaddxCommunicator implements SerialPortEventListener {
serialPort.notifyOnDataAvailable(true);
serialPort.addEventListener(this);
communicator = new Thread(this::messageDispatchLoop, "Caddx Communicator");
communicator = new Thread(this::messageDispatchLoop, "OH-binding-" + uid + "-caddxCommunicator");
communicator.setDaemon(true);
communicator.start();

View File

@ -128,7 +128,8 @@ public class CaddxBridgeHandler extends BaseBridgeHandler implements CaddxPanelL
protocol);
try {
communicator = new CaddxCommunicator(portManager, protocol, serialPortName, baudRate);
communicator = new CaddxCommunicator(getThing().getUID().getAsString(), portManager, protocol,
serialPortName, baudRate);
} catch (IOException | TooManyListenersException | UnsupportedCommOperationException | PortInUseException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
"Communication cannot be initialized. " + e.toString());

View File

@ -98,7 +98,8 @@ public class EnvisalinkBridgeHandler extends DSCAlarmBaseBridgeHandler {
tcpOutput = new OutputStreamWriter(tcpSocket.getOutputStream(), "US-ASCII");
tcpInput = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream()));
Thread tcpListener = new Thread(new TCPListener());
Thread tcpListener = new Thread(new TCPListener(), "OH-binding-" + getThing().getUID() + "-tcplistener");
tcpListener.setDaemon(true);
tcpListener.start();
setConnected(true);

View File

@ -105,7 +105,8 @@ public class TCPServerBridgeHandler extends DSCAlarmBaseBridgeHandler {
tcpOutput = new OutputStreamWriter(tcpSocket.getOutputStream(), "US-ASCII");
tcpInput = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream()));
Thread tcpListener = new Thread(new TCPListener());
Thread tcpListener = new Thread(new TCPListener(), "OH-binding-" + getThing().getUID() + "-tcplistener");
tcpListener.setDaemon(true);
tcpListener.start();
setConnected(true);

View File

@ -37,6 +37,7 @@ import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.harmonyhub.internal.HarmonyHubBindingConstants;
import org.openhab.binding.harmonyhub.internal.handler.HarmonyHubHandler;
import org.openhab.core.config.discovery.AbstractDiscoveryService;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
@ -222,7 +223,9 @@ public class HarmonyHubDiscoveryService extends AbstractDiscoveryService {
public void start() {
running = true;
Thread localThread = new Thread(this::run, "HarmonyDiscoveryServer(tcp/" + getPort() + ")");
Thread localThread = new Thread(this::run,
"OH-binding-" + HarmonyHubBindingConstants.BINDING_ID + "discoveryServer");
localThread.setDaemon(true);
localThread.start();
}

View File

@ -249,7 +249,7 @@ public abstract class AbstractHomematicGateway implements RpcEventListener, Home
for (TransferMode mode : availableInterfaces.values()) {
if (!rpcServers.containsKey(mode)) {
RpcServer rpcServer = mode == TransferMode.XML_RPC ? new XmlRpcServer(this, config)
: new BinRpcServer(this, config);
: new BinRpcServer(this, config, id);
rpcServers.put(mode, rpcServer);
rpcServer.start();
}

View File

@ -14,6 +14,7 @@ package org.openhab.binding.homematic.internal.communicator.server;
import java.io.IOException;
import org.openhab.binding.homematic.internal.HomematicBindingConstants;
import org.openhab.binding.homematic.internal.common.HomematicConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -28,12 +29,14 @@ public class BinRpcServer implements RpcServer {
private Thread networkServiceThread;
private BinRpcNetworkService networkService;
private HomematicConfig config;
private RpcEventListener listener;
private final HomematicConfig config;
private final RpcEventListener listener;
private final String id;
public BinRpcServer(RpcEventListener listener, HomematicConfig config) {
public BinRpcServer(RpcEventListener listener, HomematicConfig config, String id) {
this.listener = listener;
this.config = config;
this.id = id;
}
@Override
@ -42,7 +45,8 @@ public class BinRpcServer implements RpcServer {
networkService = new BinRpcNetworkService(listener, config);
networkServiceThread = new Thread(networkService);
networkServiceThread.setName("HomematicRpcServer");
networkServiceThread
.setName("OH-binding-" + HomematicBindingConstants.THING_TYPE_BRIDGE + ":" + id + "-rpcServer");
networkServiceThread.start();
}

View File

@ -19,6 +19,7 @@ import java.util.Queue;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -52,7 +53,7 @@ public class RequestQueueManager {
private void setParamsAndStart(@Nullable Thread thread) {
if (thread != null) {
thread.setName("Insteon Request Queue Reader");
thread.setName("OH-binding-" + InsteonBindingConstants.BINDING_ID + "-requestQueueReader");
thread.setDaemon(true);
thread.start();
}

View File

@ -19,6 +19,7 @@ import java.util.TreeSet;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
import org.openhab.binding.insteon.internal.device.InsteonDevice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -112,7 +113,7 @@ public class Poller {
private void setParamsAndStart(@Nullable Thread thread) {
if (thread != null) {
thread.setName("Insteon Poll Queue Reader");
thread.setName("OH-binding-" + InsteonBindingConstants.BINDING_ID + "-pollQueueReader");
thread.setDaemon(true);
thread.start();
}

View File

@ -192,7 +192,7 @@ public class Port {
private void setParamsAndStart(@Nullable Thread thread, String type) {
if (thread != null) {
thread.setName("Insteon " + logName + " " + type);
thread.setName("OH-binding-Insteon " + logName + " " + type);
thread.setDaemon(true);
thread.start();
}

View File

@ -25,6 +25,7 @@ import java.util.Base64;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.insteon.internal.InsteonBindingConstants;
import org.openhab.binding.insteon.internal.driver.IOStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -102,7 +103,7 @@ public class HubIOStream extends IOStream implements Runnable {
private void setParamsAndStart(@Nullable Thread thread) {
if (thread != null) {
thread.setName("Insteon Hub Poller");
thread.setName("OH-binding-" + InsteonBindingConstants.BINDING_ID + "-hubPoller");
thread.setDaemon(true);
thread.start();
}

View File

@ -18,6 +18,7 @@ import java.util.Collections;
import java.util.Set;
import org.openhab.binding.keba.internal.handler.KeContactHandler;
import org.openhab.binding.keba.internal.handler.KeContactTransceiver;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
@ -36,6 +37,8 @@ public class KebaHandlerFactory extends BaseThingHandlerFactory {
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.singleton(THING_TYPE_KECONTACTP20);
private final KeContactTransceiver transceiver = new KeContactTransceiver();
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
@ -46,7 +49,7 @@ public class KebaHandlerFactory extends BaseThingHandlerFactory {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_KECONTACTP20)) {
return new KeContactHandler(thing);
return new KeContactHandler(thing, transceiver);
}
return null;

View File

@ -74,10 +74,10 @@ public class KeContactHandler extends BaseThingHandler {
private final Logger logger = LoggerFactory.getLogger(KeContactHandler.class);
protected JsonParser parser = new JsonParser();
protected final JsonParser parser = new JsonParser();
private final KeContactTransceiver transceiver;
private ScheduledFuture<?> pollingJob;
private static KeContactTransceiver transceiver = new KeContactTransceiver();
private ExpiringCacheMap<String, ByteBuffer> cache;
private int maxPresetCurrent = 0;
@ -87,8 +87,9 @@ public class KeContactHandler extends BaseThingHandler {
private int lastState = -1; // trigger a report100 at startup
private boolean isReport100needed = true;
public KeContactHandler(Thing thing) {
public KeContactHandler(Thing thing, KeContactTransceiver transceiver) {
super(thing);
this.transceiver = transceiver;
}
@Override
@ -106,7 +107,7 @@ public class KeContactHandler extends BaseThingHandler {
if (pollingJob == null || pollingJob.isCancelled()) {
try {
pollingJob = scheduler.scheduleWithFixedDelay(pollingRunnable, 0,
pollingJob = scheduler.scheduleWithFixedDelay(this::pollingRunnable, 0,
((BigDecimal) getConfig().get(POLLING_REFRESH_INTERVAL)).intValue(), TimeUnit.SECONDS);
} catch (Exception e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
@ -147,7 +148,7 @@ public class KeContactHandler extends BaseThingHandler {
return super.getConfig();
}
private Runnable pollingRunnable = () -> {
private void pollingRunnable() {
try {
long stamp = System.currentTimeMillis();
if (!InetAddress.getByName(((String) getConfig().get(IP_ADDRESS))).isReachable(PING_TIME_OUT)) {
@ -194,7 +195,7 @@ public class KeContactHandler extends BaseThingHandler {
} catch (InterruptedException e) {
logger.debug("Polling job has been interrupted for handler of thing '{}'.", getThing().getUID());
}
};
}
protected void onData(ByteBuffer byteBuffer) {
String response = new String(byteBuffer.array(), 0, byteBuffer.limit());

View File

@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
* @author Karel Goderis - Initial contribution
*/
class KeContactTransceiver {
public class KeContactTransceiver {
public static final int LISTENER_PORT_NUMBER = 7090;
public static final int REMOTE_PORT_NUMBER = 7090;
@ -74,7 +74,7 @@ class KeContactTransceiver {
selector = Selector.open();
if (transceiverThread == null) {
transceiverThread = new Thread(transceiverRunnable, "openHAB-Keba-Transceiver");
transceiverThread = new Thread(transceiverRunnable, "OH-binding-Keba-Transceiver");
transceiverThread.start();
}

View File

@ -27,11 +27,8 @@ class Utils {
}
static Thread backgroundThread(Runnable r, String type, @Nullable Thing thing) {
String name = "OH-binding-" + LinuxInputBindingConstants.BINDING_ID + "-" + type;
if (thing != null) {
name += "-" + thing.getUID();
}
Thread t = new Thread(r, name);
String id = thing == null ? LinuxInputBindingConstants.BINDING_ID : thing.getUID().getAsString();
Thread t = new Thread(r, "OH-binding-" + id + "-" + type);
t.setDaemon(true);
return t;
}

View File

@ -71,7 +71,7 @@ public class PrgBridgeHandler extends BaseBridgeHandler {
}
final PrgBridgeConfig config = getPrgBridgeConfig();
session = new SocketSession(config.getIpAddress(), 23);
session = new SocketSession(getThing().getUID().getAsString(), config.getIpAddress(), 23);
protocolHandler = new PrgProtocolHandler(session, new PrgHandlerCallback() {
@Override

View File

@ -39,6 +39,10 @@ import org.slf4j.LoggerFactory;
public class SocketSession {
private final Logger logger = LoggerFactory.getLogger(SocketSession.class);
/**
* The uid of the calling thing
*/
private final String uid;
/**
* The host/ip address to connect to
*/
@ -87,10 +91,11 @@ public class SocketSession {
/**
* Creates the socket session from the given host and port
*
* @param uid the thing uid of the calling thing
* @param host a non-null, non-empty host/ip address
* @param port the port number between 1 and 65535
*/
public SocketSession(String host, int port) {
public SocketSession(String uid, String host, int port) {
if (host == null || host.trim().length() == 0) {
throw new IllegalArgumentException("Host cannot be null or empty");
}
@ -98,6 +103,7 @@ public class SocketSession {
if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1 and 65535");
}
this.uid = uid;
this.host = host;
this.port = port;
}
@ -133,8 +139,8 @@ public class SocketSession {
writer = new PrintStream(client.getOutputStream());
reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
new Thread(responseReader).start();
new Thread(dispatcher).start();
new Thread(responseReader, "OH-binding-" + uid + "-responseReader").start();
new Thread(dispatcher, "OH-binding-" + uid + "-dispatcher").start();
}
/**