private AuthenticationMessage authenticationMessageHandler = new AuthenticationMessage();
private IRReceiverMessage irReceiverMessageHandler = new IRReceiverMessage();
private PingMessage pingMessageHandler = new PingMessage();
+ private int reconnectionCounter = 0;
public YIOremoteDockHandler(Thing thing) {
super(thing);
authenticateWebsocket();
break;
case COMMUNICATION_ERROR:
+ disposeWebsocketPollingJob();
reconnectWebsocket();
break;
case AUTHENTICATION_COMPLETE:
@Override
public void onClose() {
+ logger.debug("onClose");
disposeWebsocketPollingJob();
reconnectWebsocket();
}
@Override
public void onError(Throwable cause) {
+ logger.debug("onError");
disposeWebsocketPollingJob();
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.COMMUNICATION_ERROR;
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
@Override
public void dispose() {
disposeWebsocketPollingJob();
- if (webSocketReconnectionPollingJob != null) {
- if (!webSocketReconnectionPollingJob.isCancelled() && webSocketReconnectionPollingJob != null) {
- webSocketReconnectionPollingJob.cancel(true);
- authenticationOk = false;
- heartBeat = false;
- }
- webSocketReconnectionPollingJob = null;
- }
+ disposeWebSocketReconnectionPollingJob();
}
@Override
case AUTHENTICATION_PROCESS:
if (authenticationOk) {
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_COMPLETE;
+ disposeWebSocketReconnectionPollingJob();
+ reconnectionCounter = 0;
updateStatus(ThingStatus.ONLINE);
updateState(STATUS_STRING_CHANNEL, StringType.EMPTY);
updateState(RECEIVER_SWITCH_CHANNEL, OnOffType.OFF);
- webSocketPollingJob = scheduler.scheduleWithFixedDelay(this::pollingWebsocketJob, 0, 60,
+ webSocketPollingJob = scheduler.scheduleWithFixedDelay(this::pollingWebsocketJob, 0, 40,
TimeUnit.SECONDS);
} else {
yioRemoteDockActualStatus = YioRemoteDockHandleStatus.AUTHENTICATION_FAILED;
}
}
+ private void disposeWebSocketReconnectionPollingJob() {
+ if (webSocketReconnectionPollingJob != null) {
+ if (!webSocketReconnectionPollingJob.isCancelled() && webSocketReconnectionPollingJob != null) {
+ webSocketReconnectionPollingJob.cancel(true);
+ }
+ }
+ webSocketReconnectionPollingJob = null;
+ logger.debug("disposereconnection");
+ reconnectionCounter = 0;
+ }
+
private void pollingWebsocketJob() {
switch (yioRemoteDockActualStatus) {
case AUTHENTICATION_COMPLETE:
}
public void reconnectWebsocket() {
+ yioRemoteDockActualStatus = YioRemoteDockHandleStatus.COMMUNICATION_ERROR;
if (webSocketReconnectionPollingJob == null) {
webSocketReconnectionPollingJob = scheduler.scheduleWithFixedDelay(this::reconnectWebsocketJob, 0, 30,
TimeUnit.SECONDS);
+ } else if (reconnectionCounter == 5) {
+ reconnectionCounter = 0;
+ updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+ "Connection lost no ping from YIO DOCK");
+ if (webSocketReconnectionPollingJob == null) {
+ webSocketReconnectionPollingJob = scheduler.scheduleWithFixedDelay(this::reconnectWebsocketJob, 0, 1,
+ TimeUnit.MINUTES);
+ } else {
+ disposeWebSocketReconnectionPollingJob();
+ if (webSocketReconnectionPollingJob == null) {
+ webSocketReconnectionPollingJob = scheduler.scheduleWithFixedDelay(this::reconnectWebsocketJob, 0,
+ 5, TimeUnit.MINUTES);
+ }
+ }
+ } else {
}
}
public void reconnectWebsocketJob() {
+ reconnectionCounter++;
switch (yioRemoteDockActualStatus) {
case COMMUNICATION_ERROR:
logger.debug("Reconnecting YIORemoteHandler");
}
break;
case AUTHENTICATION_COMPLETE:
- if (webSocketReconnectionPollingJob != null) {
- if (!webSocketReconnectionPollingJob.isCancelled() && webSocketReconnectionPollingJob != null) {
- webSocketReconnectionPollingJob.cancel(true);
- }
- webSocketReconnectionPollingJob = null;
- }
+ disposeWebSocketReconnectionPollingJob();
+ reconnectionCounter = 0;
break;
default:
break;