Skip to content

Commit

Permalink
Add delay when notifying node listeners
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Cunningham <[email protected]>
  • Loading branch information
digitaldan committed Sep 2, 2024
1 parent 438f48a commit 3bb3b65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class MatterWebsocketClient implements WebSocketListener {
private static final String MATTER_JS_PATH = "/matter-server/matter.js";

private final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool("matter-js.MatterWebsocketClient");
.getScheduledPool("matter.MatterWebsocketClient");
private final Gson gson = new GsonBuilder().registerTypeAdapter(Node.class, new NodeDeserializer())
.registerTypeAdapter(BigInteger.class, new BigIntegerSerializer()).create();
private final WebSocketClient client = new WebSocketClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.openhab.core.common.ThreadPoolManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -45,6 +48,7 @@ public class NodeRunner {
private int port;
private final List<NodeProcessListener> processListeners = new ArrayList<>();
private final ExecutorService executorService = Executors.newFixedThreadPool(2);
private final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("matter.NodeRunner");

public NodeRunner(String nodePath) {
this.nodePath = nodePath;
Expand Down Expand Up @@ -119,7 +123,9 @@ private void processStream(InputStream inputStream, String errorMessage) {
while ((line = reader.readLine()) != null) {
if (!ready) {
ready = true;
notifyReadyListeners();
scheduler.schedule(() -> {
notifyReadyListeners();
}, 1, TimeUnit.SECONDS);
}
Matcher matcher = LOG_PATTERN.matcher(line);
if (matcher.matches()) {
Expand Down

0 comments on commit 3bb3b65

Please sign in to comment.