diff --git a/src/main/java/it/tdlight/common/InternalClient.java b/src/main/java/it/tdlight/common/InternalClient.java index 501ff41..0aee7c7 100644 --- a/src/main/java/it/tdlight/common/InternalClient.java +++ b/src/main/java/it/tdlight/common/InternalClient.java @@ -76,6 +76,7 @@ public class InternalClient implements ClientEventsHandler, TelegramClient { handleResponse(eventId, new Error(500, "Instance closed"), handler); }); handlers.clear(); + logger.info("Client closed {}", clientId); } /** diff --git a/src/main/java/it/tdlight/common/InternalClientManager.java b/src/main/java/it/tdlight/common/InternalClientManager.java index 1c79f3b..b665933 100644 --- a/src/main/java/it/tdlight/common/InternalClientManager.java +++ b/src/main/java/it/tdlight/common/InternalClientManager.java @@ -51,11 +51,11 @@ public class InternalClientManager implements AutoCloseable { } public void registerClient(int clientId, ClientEventsHandler internalClient) { - responseReceiver.registerClient(clientId); boolean replaced = registeredClientEventHandlers.put(clientId, internalClient) != null; if (replaced) { throw new IllegalStateException("Client " + clientId + " already registered"); } + responseReceiver.registerClient(clientId); } public String getImplementationName() { diff --git a/src/main/java/it/tdlight/common/InternalReactiveClient.java b/src/main/java/it/tdlight/common/InternalReactiveClient.java index 6555d07..c14ae03 100644 --- a/src/main/java/it/tdlight/common/InternalReactiveClient.java +++ b/src/main/java/it/tdlight/common/InternalReactiveClient.java @@ -134,6 +134,7 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele if (isClosed.get()) { if (alreadyCompleted.compareAndSet(false, true)) { subscriber.onComplete(); + logger.info("Client closed {}", clientId); } } } diff --git a/src/main/java/it/tdlight/common/ResponseReceiver.java b/src/main/java/it/tdlight/common/ResponseReceiver.java index e0ef9fa..e6fb3fa 100644 --- a/src/main/java/it/tdlight/common/ResponseReceiver.java +++ b/src/main/java/it/tdlight/common/ResponseReceiver.java @@ -8,7 +8,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; import java.util.stream.Collectors; @@ -32,7 +32,7 @@ public class ResponseReceiver extends Thread implements AutoCloseable { private final TdApi.Object[] events = new TdApi.Object[MAX_EVENTS]; private final CountDownLatch closeWait = new CountDownLatch(1); - private final Set registeredClients = new ConcurrentSkipListSet<>(); + private final Set registeredClients = new ConcurrentHashMap().keySet(new java.lang.Object()); private volatile boolean closeRequested = false;