diff options
author | Simon Rettberg | 2023-03-24 14:22:04 +0100 |
---|---|---|
committer | Simon Rettberg | 2023-03-24 14:22:04 +0100 |
commit | ed5c0c4258ac4cb2a6b6fdddb7acb389b41ba1c4 (patch) | |
tree | 4528537f424f187c27446c45796920e4d3a66f54 | |
parent | Reduce logging spam (diff) | |
download | bwlp-guacamole-ext-ed5c0c4258ac4cb2a6b6fdddb7acb389b41ba1c4.tar.gz bwlp-guacamole-ext-ed5c0c4258ac4cb2a6b6fdddb7acb389b41ba1c4.tar.xz bwlp-guacamole-ext-ed5c0c4258ac4cb2a6b6fdddb7acb389b41ba1c4.zip |
Refactor meta data merging
-rw-r--r-- | src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java index 5e4cb90..8db6ff9 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java @@ -255,36 +255,24 @@ public class ConnectionManager { synchronized (clientPool) { HashSet<JsonGroup> processedGroups = new HashSet<JsonGroup>(); + HashSet<JsonGroup> redoClientMapping = new HashSet<JsonGroup>(); for (JsonGroup gnew : root.locations) { if (gnew.locationids == null) continue; JsonGroup existing = groupPool.get(gnew.id); - boolean redoClientMapping = false; if (existing == null) { groupPool.put(gnew.id, gnew); existing = gnew; - redoClientMapping = true; + redoClientMapping.add(existing); LOGGER.info("Group " + gnew.name + " with pw " + gnew.password); } else { if (!Arrays.equals(existing.locationids, gnew.locationids)) { - redoClientMapping = true; + redoClientMapping.add(existing); existing.locationids = gnew.locationids; } existing.name = gnew.name; existing.password = gnew.password; } - if (redoClientMapping) { - existing.clientList = new ConcurrentLinkedQueue<AvailableClient>(); - for (AvailableClient client : clientPool.values()) { - int locationid = client.getLocationid(); - for (int id : existing.locationids) { - if (id == locationid) { - existing.clientList.add(client); - break; - } - } - } - } processedGroups.add(existing); } for (Iterator<JsonGroup> it = groupPool.values().iterator(); it.hasNext();) { @@ -293,9 +281,7 @@ public class ConnectionManager { it.remove(); } } - } - synchronized (clientPool) { for (JsonClient cnew : root.clients) { if (cnew.password == null || cnew.clientip == null) continue; // Invalid @@ -330,6 +316,22 @@ public class ConnectionManager { existing.update(cnew); } } + + // Finally, re-assign clients to their groups, for groups where the locationids + // have changed since the last update + for (JsonGroup existing : redoClientMapping) { + existing.clientList = new ConcurrentLinkedQueue<AvailableClient>(); + for (AvailableClient client : clientPool.values()) { + int locationid = client.getLocationid(); + for (int id : existing.locationids) { + if (id == locationid) { + existing.clientList.add(client); + break; + } + } + } + } + final long NOW = System.currentTimeMillis(); for (Iterator<AvailableClient> it = clientPool.values().iterator(); it.hasNext();) { AvailableClient c = it.next(); |