зеркало из https://github.com/dotnet/aspnetcore.git
Remove BiFunction Ref (#3213)
This commit is contained in:
Родитель
2ad1996220
Коммит
e1b602a7c5
|
@ -3,29 +3,45 @@
|
|||
|
||||
package com.microsoft.signalr;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
class CallbackMap {
|
||||
private final Map<String, List<InvocationHandler>> handlers = new ConcurrentHashMap<>();
|
||||
private final Map<String, List<InvocationHandler>> handlers = new HashMap<>();
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
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<>();
|
||||
try {
|
||||
lock.lock();
|
||||
InvocationHandler handler = new InvocationHandler(action, classes);
|
||||
if (!handlers.containsKey(target)) {
|
||||
handlers.put(target, new ArrayList<>());
|
||||
}
|
||||
value.add(handler);
|
||||
return value;
|
||||
});
|
||||
return handler;
|
||||
handlers.get(target).add(handler);
|
||||
return handler;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public List<InvocationHandler> get(String key) {
|
||||
return handlers.get(key);
|
||||
try {
|
||||
lock.lock();
|
||||
return handlers.get(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String key) {
|
||||
handlers.remove(key);
|
||||
try {
|
||||
lock.lock();
|
||||
handlers.remove(key);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче