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;
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
*/
/**
* 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");
}
if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1 and 65535");
}
+ this.uid = uid;
this.host = host;
this.port = port;
}
}
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
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
}, 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);
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);
});
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");
}
}
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;
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();
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());
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);
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);
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;
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();
}
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();
}
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;
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
networkService = new BinRpcNetworkService(listener, config);
networkServiceThread = new Thread(networkService);
- networkServiceThread.setName("HomematicRpcServer");
+ networkServiceThread
+ .setName("OH-binding-" + HomematicBindingConstants.THING_TYPE_BRIDGE + ":" + id + "-rpcServer");
networkServiceThread.start();
}
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;
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();
}
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;
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();
}
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();
}
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;
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();
}
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;
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);
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (thingTypeUID.equals(THING_TYPE_KECONTACTP20)) {
- return new KeContactHandler(thing);
+ return new KeContactHandler(thing, transceiver);
}
return null;
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;
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
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,
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)) {
} 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());
* @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;
selector = Selector.open();
if (transceiverThread == null) {
- transceiverThread = new Thread(transceiverRunnable, "openHAB-Keba-Transceiver");
+ transceiverThread = new Thread(transceiverRunnable, "OH-binding-Keba-Transceiver");
transceiverThread.start();
}
}
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;
}
}
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
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
*/
/**
* 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");
}
if (port < 1 || port > 65535) {
throw new IllegalArgumentException("Port must be between 1 and 65535");
}
+ this.uid = uid;
this.host = host;
this.port = port;
}
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();
}
/**