From ed5c0c4258ac4cb2a6b6fdddb7acb389b41ba1c4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Mar 2023 14:22:04 +0100 Subject: Refactor meta data merging --- .../de/bwlehrpool/bwlp_guac/ConnectionManager.java | 36 ++++++++++++---------- 1 file 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 processedGroups = new HashSet(); + HashSet redoClientMapping = new HashSet(); 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(); - 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 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(); + 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 it = clientPool.values().iterator(); it.hasNext();) { AvailableClient c = it.next(); -- cgit v1.2.3-55-g7522