diff options
Diffstat (limited to 'src')
-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(); |