// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

package com.microsoft.signalr;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

class CallbackMap {
    private final Map<String, List<InvocationHandler>> handlers = new ConcurrentHashMap<>();

    public InvocationHandler put(String target, ActionBase action, Class<?>... classes) {
        InvocationHandler handler = new InvocationHandler(action, classes);
        handlers.compute(target, (key, value) -> {
            if (value == null) {
                value = new ArrayList<>();
            }
            value.add(handler);
            return value;
        });
        return handler;
    }

    public List<InvocationHandler> get(String key) {
        return handlers.get(key);
    }

    public void remove(String key) {
        handlers.remove(key);
    }
}

@@ -214,9 +214,88 @@
 til.
-*
+ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0Aim
@@ -320,33 +320,35 @@
 current.
-ConcurrentHashMap
+locks.ReentrantLock
 ;%0A%0Aclass
@@ -436,18 +436,8 @@
 new 
-Concurrent
 Hash
@@ -444,16 +444,76 @@
 Map%3C%3E();
+%0A    private final ReentrantLock lock = new ReentrantLock();
 %0A%0A    pu
@@ -592,24 +592,67 @@
  classes) %7B%0A
+        try %7B%0A            lock.lock();%0A    
         Invo
@@ -715,32 +715,41 @@
 asses);%0A        
+    if (!
 handlers.compute
@@ -747,96 +747,65 @@
 s.co
-mpute(target, (key, value) -%3E %7B%0A            if (value == null) %7B%0A                value =
+ntainsKey(target)) %7B%0A                handlers.put(target,
  new
@@ -814,24 +814,25 @@
 rrayList%3C%3E()
+)
 ;%0A          
@@ -847,21 +847,36 @@
         
-value
+handlers.get(target)
 .add(han
@@ -905,13 +905,15 @@
 urn 
-value
+handler
 ;%0A  
@@ -923,34 +923,55 @@
    %7D
-);%0A        return handler;
+ finally %7B%0A            lock.unlock();%0A        %7D
 %0A   
@@ -1039,107 +1039,307 @@
     
-return handlers.get(key);%0A    %7D%0A%0A    public void remove(String key) %7B%0A        handlers.remove(key);
+try %7B%0A            lock.lock();%0A            return handlers.get(key);%0A        %7D finally %7B%0A            lock.unlock();%0A        %7D%0A    %7D%0A%0A    public void remove(String key) %7B%0A        try %7B%0A            lock.lock();%0A            handlers.remove(key);%0A        %7D finally %7B%0A            lock.unlock();%0A        %7D
 %0A   

Remove BiFunction Ref (#3213)