Skip to content

Commit c53ea5b

Browse files
committed
🧵 Use a ConcurrentHashMap for pending cookies to allow iterations on #getPendingCookies
1 parent 08f2ad9 commit c53ea5b

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

core/src/main/java/net/transferproxy/network/connection/PlayerConnectionImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.net.SocketException;
6060
import java.util.*;
6161
import java.util.concurrent.CompletableFuture;
62+
import java.util.concurrent.ConcurrentHashMap;
6263

6364
public class PlayerConnectionImpl extends SimpleChannelInboundHandler<ServerboundPacket> implements PlayerConnection {
6465

@@ -124,7 +125,7 @@ public void sendStatusResponse(final @NotNull StatusResponse response) {
124125
}
125126
CompletableFuture<byte[]> future;
126127
if (this.pendingCookies == null) {
127-
this.pendingCookies = new HashMap<>();
128+
this.pendingCookies = new ConcurrentHashMap<>();
128129
future = null;
129130
} else {
130131
future = this.pendingCookies.get(cookieKey);
@@ -153,10 +154,11 @@ public void storeCookie(final @NotNull String cookieKey, final byte @NotNull []
153154

154155
@Override
155156
public void handleCookieResponse(final @NotNull String cookieKey, final byte @Nullable [] payload) {
156-
if (this.pendingCookies == null) {
157+
final Map<String, CompletableFuture<byte[]>> pendingCookies = this.pendingCookies;
158+
if (pendingCookies == null) {
157159
return;
158160
}
159-
final CompletableFuture<byte[]> future = this.pendingCookies.get(cookieKey);
161+
final CompletableFuture<byte[]> future = pendingCookies.get(cookieKey);
160162
if (future == null) {
161163
return;
162164
}
@@ -165,7 +167,8 @@ public void handleCookieResponse(final @NotNull String cookieKey, final byte @Nu
165167

166168
@Override
167169
public @NotNull Map<String, CompletableFuture<byte[]>> getPendingCookies() {
168-
return this.pendingCookies != null ? Collections.unmodifiableMap(this.pendingCookies) : Map.of();
170+
final Map<String, CompletableFuture<byte[]>> pendingCookies = this.pendingCookies;
171+
return pendingCookies != null ? Collections.unmodifiableMap(pendingCookies) : Map.of();
169172
}
170173

171174
@Override

0 commit comments

Comments
 (0)