diff options
Diffstat (limited to 'src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java')
-rw-r--r-- | src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java index 00ec284..97dd851 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/ConnectionManager.java @@ -82,6 +82,7 @@ public class ConnectionManager { } for (AvailableClient ac : clients) { + LOGGER.info("Looking for existing mapping: Checking client " + ac); if (ac.isInUseBy(user)) { LOGGER.info("Client " + ac + " is in use by " + user); freeClient = ac; @@ -90,6 +91,7 @@ public class ConnectionManager { } if (freeClient == null) { for (AvailableClient ac : clients) { + LOGGER.info("Looking for free client: Checking client " + ac); if (ac.claim(user)) { LOGGER.info("Claiming client " + ac + " for " + user); freeClient = ac; @@ -168,7 +170,6 @@ public class ConnectionManager { private static void populateList(byte[] data) { ObjectMapper mapper = new ObjectMapper(); - JsonClient[] list; JsonRoot root; try { root = mapper.readValue(data, JsonRoot.class); @@ -185,6 +186,7 @@ public class ConnectionManager { LOGGER.info("Group list null"); } synchronized (groupPool) { + HashSet<JsonGroup> processedGroups = new HashSet<JsonGroup>(); for (JsonGroup gnew : groups) { JsonGroup existing = groupPool.get(gnew.id); boolean redoClientMapping = false; @@ -210,12 +212,17 @@ public class ConnectionManager { } } } - existing.checked = true; + processedGroups.add(existing); LOGGER.info("Group " + gnew.name + " with pw " + gnew.password); } - for (JsonGroup group : groupPool.values()) { - if (group.checked) group.checked = false; - else groupPool.remove(group.id); + for (Iterator<JsonGroup> it = groupPool.values().iterator(); it.hasNext();) { + JsonGroup g = it.next(); + if (!processedGroups.contains(g)) { + for (AvailableClient client : g.clientList) { + client.groupList.remove(g); + } + it.remove(); + } } } @@ -223,32 +230,51 @@ public class ConnectionManager { LOGGER.info("Client list null"); } synchronized (clientPool) { + HashSet<AvailableClient> processedClients = new HashSet<AvailableClient>(); for (JsonClient cnew : root.clients) { if (cnew.password == null || cnew.clientip == null) continue; // Invalid AvailableClient existing = clientPool.get(cnew.clientip); if (existing == null) { // New client - AvailableClient newClient = new AvailableClient(cnew); - clientPool.put(cnew.clientip, newClient); + existing = new AvailableClient(cnew); + clientPool.put(cnew.clientip, existing); for (JsonGroup group : groupPool.values()) { for (int id : group.locationids) { if (id == cnew.locationid) { - group.clientList.add(newClient); - newClient.groupList.add(group); + group.clientList.add(existing); + existing.groupList.add(group); break; } } } LOGGER.info("New client " + cnew.clientip); } else { + if (existing.getLocationid() != cnew.locationid) { + for (JsonGroup group : groupPool.values()) { + for (int id : group.locationids) { + if (id == existing.getLocationid()) { + group.clientList.remove(existing); + existing.groupList.remove(group); + } + if (id == cnew.locationid) { + group.clientList.add(existing); + existing.groupList.add(group); + } + } + } + } existing.update(cnew); } + processedClients.add(existing); } final long NOW = System.currentTimeMillis(); for (Iterator<AvailableClient> it = clientPool.values().iterator(); it.hasNext();) { AvailableClient c = it.next(); + if (!processedClients.contains(c)) { + c.markAsMissing(); + } if (c.isTimeout(NOW)) { LOGGER.info("Removing client " + c + " from list"); for (JsonGroup group : c.groupList) { @@ -256,7 +282,6 @@ public class ConnectionManager { } it.remove(); } - } LOGGER.info("List updated. " + clientPool.size() + " clients."); } |