Skip to content

Commit

Permalink
[openhabcloud] sleepSocketIO(long delay) halts entire io.socket thread
Browse files Browse the repository at this point in the history
…openhab#13210 (openhab#13421)

* sleepSocketIO(long delay) halts entire io.socket thread CI openhab#6047

Signed-off-by: lsafelix75 <lsafelix75@gmail.com>
  • Loading branch information
lsafelix75 authored and borazslo committed Jan 7, 2023
1 parent 16f638f commit 1223217
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
Expand All @@ -38,6 +40,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.openhab.core.OpenHAB;
import org.openhab.core.common.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,7 +53,6 @@
import io.socket.engineio.client.Transport;
import io.socket.parser.Packet;
import io.socket.parser.Parser;
import io.socket.thread.EventThread;
import okhttp3.OkHttpClient.Builder;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.logging.HttpLoggingInterceptor.Level;
Expand Down Expand Up @@ -135,6 +137,13 @@ public class CloudClient {
*/
private final Backoff reconnectBackoff = new Backoff();

/*
* Delay reconnect scheduler pool
*
*/
protected final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(ThreadPoolManager.THREAD_POOL_NAME_COMMON);

/**
* Constructor of CloudClient
*
Expand Down Expand Up @@ -316,8 +325,12 @@ public void call(Object... args) {
logger.warn("Error connecting to the openHAB Cloud instance. Reconnecting.");
}
socket.close();
sleepSocketIO(delay);
socket.connect();
scheduler.schedule(new Runnable() {
@Override
public void run() {
socket.connect();
}
}, delay, TimeUnit.MILLISECONDS);
}
})//

Expand Down Expand Up @@ -685,16 +698,6 @@ private JSONObject getJSONHeaders(HttpFields httpFields) {
return headersJSON;
}

private void sleepSocketIO(long delay) {
EventThread.exec(() -> {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {

}
});
}

private static String censored(String secret) {
if (secret.length() < 4) {
return "*******";
Expand Down

0 comments on commit 1223217

Please sign in to comment.