Skip to content

Commit 76b6868

Browse files
Copy invocation handler list in Java client (#43402)
1 parent 2304371 commit 76b6868

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/CallbackMap.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ public InvocationHandler put(String target, Object action, Type... types) {
3131
}
3232
}
3333
}
34+
methodHandlers = new ArrayList<>(methodHandlers);
3435
methodHandlers.add(handler);
36+
37+
// replace List in handlers map
38+
handlers.remove(target);
39+
handlers.put(target, methodHandlers);
3540
return handler;
3641
} finally {
3742
lock.unlock();
@@ -41,7 +46,7 @@ public InvocationHandler put(String target, Object action, Type... types) {
4146
public List<InvocationHandler> get(String key) {
4247
try {
4348
lock.lock();
44-
return handlers.get(key);
49+
return this.handlers.get(key);
4550
} finally {
4651
lock.unlock();
4752
}
@@ -55,4 +60,21 @@ public void remove(String key) {
5560
lock.unlock();
5661
}
5762
}
63+
64+
public void remove(String key, InvocationHandler handler) {
65+
try {
66+
lock.lock();
67+
List<InvocationHandler> handlers = this.handlers.get(key);
68+
if (handlers != null) {
69+
handlers = new ArrayList<>(handlers);
70+
handlers.remove(handler);
71+
72+
// replace List in handlers map
73+
this.handlers.remove(key);
74+
this.handlers.put(key, handlers);
75+
}
76+
} finally {
77+
lock.unlock();
78+
}
79+
}
5880
}

src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/Subscription.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ public class Subscription {
2323
* Removes the client method handler represented by this subscription.
2424
*/
2525
public void unsubscribe() {
26-
List<InvocationHandler> handler = this.handlers.get(target);
27-
if (handler != null) {
28-
handler.remove(this.handler);
29-
}
26+
this.handlers.remove(this.target, this.handler);
3027
}
3128
}

0 commit comments

Comments
 (0)