refactoring
This commit is contained in:
parent
dd4d9677fe
commit
75c5df0a4e
|
@ -75,8 +75,6 @@ public class Backend implements Closeable {
|
|||
// good enough to begin with
|
||||
private final Object lock = new Object();
|
||||
|
||||
@GuardedBy("lock")
|
||||
private final Set<ControllerConnectionState> controllers = new HashSet<>();
|
||||
@GuardedBy("lock")
|
||||
private final HashMap<ControllerKey, ControllerConnectionState> controllersByKey = new HashMap<>();
|
||||
@GuardedBy("lock")
|
||||
|
@ -357,7 +355,7 @@ public class Backend implements Closeable {
|
|||
|
||||
List<ControllerConnectionState> controllers;
|
||||
synchronized (lock) {
|
||||
controllers = new ArrayList<>(this.controllers);
|
||||
controllers = new ArrayList<>(this.controllersByKey.values());
|
||||
}
|
||||
|
||||
for (ControllerConnectionState controllerConnectionState : controllers) {
|
||||
|
@ -369,7 +367,6 @@ public class Backend implements Closeable {
|
|||
public void register(ControllerConnectionState controllerConnectionState) {
|
||||
Objects.requireNonNull(controllerConnectionState.getControllerKey(), "ControllerKey");
|
||||
synchronized (lock) {
|
||||
controllers.add(controllerConnectionState);
|
||||
controllersByKey.put(controllerConnectionState.getControllerKey(), controllerConnectionState);
|
||||
}
|
||||
}
|
||||
|
@ -378,7 +375,6 @@ public class Backend implements Closeable {
|
|||
inactiveClient.close();
|
||||
synchronized (lock) {
|
||||
// in case of exception in the initialization phase we do not even add client into the the collection
|
||||
controllers.remove(inactiveClient);
|
||||
controllersByKey.remove(inactiveClient.getControllerKey());
|
||||
}
|
||||
}
|
||||
|
@ -397,7 +393,7 @@ public class Backend implements Closeable {
|
|||
|
||||
public List<ControllerConnectionState> getControllers() {
|
||||
synchronized (lock) {
|
||||
return new ArrayList<>(controllers);
|
||||
return new ArrayList<>(controllersByKey.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -409,7 +405,7 @@ public class Backend implements Closeable {
|
|||
|
||||
public int getControllersCount() {
|
||||
synchronized (lock) {
|
||||
return controllers.size();
|
||||
return controllersByKey.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue