From c3ad90da1161ece1fdd2d59c0d652af9a66c2bff Mon Sep 17 00:00:00 2001 From: Harshvardhan Gupta <95761669+Harsh5488@users.noreply.github.com> Date: Sat, 4 Jan 2025 15:47:33 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20Using=20ConcurrentHashMap=20for=20m?= =?UTF-8?q?ulti-threaded=20environment=20=E2=80=A2=20Making=20clearAcks()?= =?UTF-8?q?=20public=20for=20clearing=20acknowledgement=20when=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/io/socket/client/Socket.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/socket/client/Socket.java b/src/main/java/io/socket/client/Socket.java index 334d25f5..b711005f 100644 --- a/src/main/java/io/socket/client/Socket.java +++ b/src/main/java/io/socket/client/Socket.java @@ -9,6 +9,7 @@ import org.json.JSONObject; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.logging.Level; import java.util.logging.Logger; @@ -59,7 +60,7 @@ public class Socket extends Emitter { private String nsp; private Manager io; private Map auth; - private Map acks = new HashMap<>(); + private Map acks = new ConcurrentHashMap<>(); private Queue subs; private final Queue> receiveBuffer = new ConcurrentLinkedQueue<>(); private final Queue> sendBuffer = new ConcurrentLinkedQueue<>(); @@ -283,14 +284,13 @@ private void onclose(String reason) { this.connected = false; this.id = null; super.emit(EVENT_DISCONNECT, reason); - this.clearAcks(); } /** * Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from * the server. */ - private void clearAcks() { + public void clearAcks() { for (Ack ack : this.acks.values()) { if (ack instanceof AckWithTimeout) { ((AckWithTimeout) ack).onTimeout();