mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[yioremote] Stop the web socket client when disposing thing handler (#14340)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
8306210a13
commit
1f877cae6d
@ -68,6 +68,7 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
private ClientUpgradeRequest yioremoteDockwebSocketClientrequest = new ClientUpgradeRequest();
|
private ClientUpgradeRequest yioremoteDockwebSocketClientrequest = new ClientUpgradeRequest();
|
||||||
private @Nullable URI websocketAddress;
|
private @Nullable URI websocketAddress;
|
||||||
private YioRemoteDockHandleStatus yioRemoteDockActualStatus = YioRemoteDockHandleStatus.UNINITIALIZED_STATE;
|
private YioRemoteDockHandleStatus yioRemoteDockActualStatus = YioRemoteDockHandleStatus.UNINITIALIZED_STATE;
|
||||||
|
private @Nullable Future<?> initJob;
|
||||||
private @Nullable Future<?> webSocketPollingJob;
|
private @Nullable Future<?> webSocketPollingJob;
|
||||||
private @Nullable Future<?> webSocketReconnectionPollingJob;
|
private @Nullable Future<?> webSocketReconnectionPollingJob;
|
||||||
public String receivedMessage = "";
|
public String receivedMessage = "";
|
||||||
@ -90,7 +91,7 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
updateStatus(ThingStatus.UNKNOWN);
|
updateStatus(ThingStatus.UNKNOWN);
|
||||||
scheduler.execute(() -> {
|
initJob = scheduler.submit(() -> {
|
||||||
try {
|
try {
|
||||||
websocketAddress = new URI("ws://" + localConfig.host + ":946");
|
websocketAddress = new URI("ws://" + localConfig.host + ":946");
|
||||||
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_PROCESS;
|
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_PROCESS;
|
||||||
@ -257,8 +258,18 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
Future<?> job = initJob;
|
||||||
|
if (job != null) {
|
||||||
|
job.cancel(true);
|
||||||
|
initJob = null;
|
||||||
|
}
|
||||||
disposeWebsocketPollingJob();
|
disposeWebsocketPollingJob();
|
||||||
disposeWebSocketReconnectionPollingJob();
|
disposeWebSocketReconnectionPollingJob();
|
||||||
|
try {
|
||||||
|
webSocketClient.stop();
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.debug("Could not stop webSocketClient, message {}", e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -342,21 +353,19 @@ public class YIOremoteDockHandler extends BaseThingHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void disposeWebsocketPollingJob() {
|
private void disposeWebsocketPollingJob() {
|
||||||
if (webSocketPollingJob != null) {
|
Future<?> job = webSocketPollingJob;
|
||||||
if (!webSocketPollingJob.isCancelled() && webSocketPollingJob != null) {
|
if (job != null) {
|
||||||
webSocketPollingJob.cancel(true);
|
job.cancel(true);
|
||||||
}
|
|
||||||
webSocketPollingJob = null;
|
webSocketPollingJob = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disposeWebSocketReconnectionPollingJob() {
|
private void disposeWebSocketReconnectionPollingJob() {
|
||||||
if (webSocketReconnectionPollingJob != null) {
|
Future<?> job = webSocketReconnectionPollingJob;
|
||||||
if (!webSocketReconnectionPollingJob.isCancelled() && webSocketReconnectionPollingJob != null) {
|
if (job != null) {
|
||||||
webSocketReconnectionPollingJob.cancel(true);
|
job.cancel(true);
|
||||||
}
|
webSocketReconnectionPollingJob = null;
|
||||||
}
|
}
|
||||||
webSocketReconnectionPollingJob = null;
|
|
||||||
logger.debug("disposereconnection");
|
logger.debug("disposereconnection");
|
||||||
reconnectionCounter = 0;
|
reconnectionCounter = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user