mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[tesla] Normalize thread names and avoid a possible IAE (#14351)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
43232dae2e
commit
e0a3ca2f9b
@ -22,7 +22,6 @@ import java.nio.charset.CodingErrorAction;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.eclipse.jetty.websocket.api.Session;
|
||||
@ -32,6 +31,8 @@ import org.eclipse.jetty.websocket.api.WebSocketPingPongListener;
|
||||
import org.eclipse.jetty.websocket.client.WebSocketClient;
|
||||
import org.openhab.binding.tesla.internal.protocol.Event;
|
||||
import org.openhab.core.io.net.http.WebSocketFactory;
|
||||
import org.openhab.core.thing.ThingUID;
|
||||
import org.openhab.core.thing.util.ThingWebClientUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -54,7 +55,6 @@ public class TeslaEventEndpoint implements WebSocketListener, WebSocketPingPongL
|
||||
|
||||
private String endpointId;
|
||||
protected WebSocketFactory webSocketFactory;
|
||||
private static final AtomicInteger INSTANCE_COUNTER = new AtomicInteger();
|
||||
|
||||
private WebSocketClient client;
|
||||
private ConnectionState connectionState = ConnectionState.CLOSED;
|
||||
@ -62,11 +62,12 @@ public class TeslaEventEndpoint implements WebSocketListener, WebSocketPingPongL
|
||||
private EventHandler eventHandler;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
public TeslaEventEndpoint(WebSocketFactory webSocketFactory) {
|
||||
public TeslaEventEndpoint(ThingUID uid, WebSocketFactory webSocketFactory) {
|
||||
try {
|
||||
this.endpointId = "TeslaEventEndpoint-" + INSTANCE_COUNTER.incrementAndGet();
|
||||
this.endpointId = "TeslaEventEndpoint-" + uid.getAsString();
|
||||
|
||||
client = webSocketFactory.createWebSocketClient(endpointId);
|
||||
String name = ThingWebClientUtil.buildWebClientConsumerName(uid, null);
|
||||
client = webSocketFactory.createWebSocketClient(name);
|
||||
this.client.setConnectTimeout(TIMEOUT_MILLISECONDS);
|
||||
this.client.setMaxIdleTimeout(IDLE_TIMEOUT_MILLISECONDS);
|
||||
} catch (Exception e) {
|
||||
|
@ -193,7 +193,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
|
||||
if (enableEvents) {
|
||||
if (eventThread == null) {
|
||||
eventThread = new Thread(eventRunnable, "openHAB-Tesla-Events-" + getThing().getUID());
|
||||
eventThread = new Thread(eventRunnable, "OH-binding-" + getThing().getUID() + "-events");
|
||||
eventThread.start();
|
||||
}
|
||||
}
|
||||
@ -1130,7 +1130,7 @@ public class TeslaVehicleHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
eventEndpoint = new TeslaEventEndpoint(webSocketFactory);
|
||||
eventEndpoint = new TeslaEventEndpoint(getThing().getUID(), webSocketFactory);
|
||||
eventEndpoint.addEventHandler(new TeslaEventEndpoint.EventHandler() {
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
|
Loading…
Reference in New Issue
Block a user