From db47e51e45104eeaa8012cac1ca0cd9e988bed6d Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sun, 12 Aug 2018 12:26:57 +0300 Subject: [PATCH] ConnectionSystem cached values now cleared --- .../databases/sql/tables/WorldTable.java | 15 +++++++++++++ .../databases/sql/tables/WorldTimesTable.java | 21 +++++++++++++++++-- .../plan/system/file/FileSystem.java | 2 +- .../plan/system/info/InfoSystem.java | 1 - .../connection/BungeeConnectionSystem.java | 20 ------------------ .../info/connection/ConnectionSystem.java | 7 +++++++ 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTable.java index 81d907f24..482ea51ec 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTable.java @@ -178,5 +178,20 @@ public class WorldTable extends Table { return column; } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof WorldTable)) return false; + if (!super.equals(o)) return false; + WorldTable that = (WorldTable) o; + return Objects.equals(statementSelectID, that.statementSelectID) && + Objects.equals(serverTable, that.serverTable); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), statementSelectID, serverTable); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTimesTable.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTimesTable.java index 6ee5e7ff6..d1fbaf1e1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTimesTable.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/tables/WorldTimesTable.java @@ -286,8 +286,8 @@ public class WorldTimesTable extends UserIDTable { public void addWorldTimesToSessions(Map>> map) { Map worldTimesBySessionID = getAllWorldTimesBySessionID(); - for (UUID serverUUID : map.keySet()) { - for (List sessions : map.get(serverUUID).values()) { + for (Map.Entry>> entry : map.entrySet()) { + for (List sessions : entry.getValue().values()) { for (Session session : sessions) { WorldTimes worldTimes = worldTimesBySessionID.get(session.getUnsafe(SessionKeys.DB_ID)); if (worldTimes != null) { @@ -377,4 +377,21 @@ public class WorldTimesTable extends UserIDTable { return column; } } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof WorldTimesTable)) return false; + if (!super.equals(o)) return false; + WorldTimesTable that = (WorldTimesTable) o; + return Objects.equals(serverTable, that.serverTable) && + Objects.equals(worldTable, that.worldTable) && + Objects.equals(sessionsTable, that.sessionsTable) && + Objects.equals(insertStatement, that.insertStatement); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), serverTable, worldTable, sessionsTable, insertStatement); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/file/FileSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/file/FileSystem.java index a5f14ac53..ee11fe1b3 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/file/FileSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/file/FileSystem.java @@ -77,6 +77,6 @@ public class FileSystem implements SubSystem { @Override public void disable() { - + // No disable actions necessary. } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java index e99b0ad43..713a4158b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/InfoSystem.java @@ -156,7 +156,6 @@ public abstract class InfoSystem implements SubSystem { Server bungee = new Server(-1, null, "Bungee", addressToRequestServer, -1); String addressOfThisServer = WebServerSystem.getInstance().getWebServer().getAccessAddress(); - ConnectionSystem connectionSystem = ConnectionSystem.getInstance(); connectionSystem.setSetupAllowed(true); connectionSystem.sendInfoRequest(new SendDBSettingsRequest(addressOfThisServer), bungee); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java index 5dab5bd96..96aa03587 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/BungeeConnectionSystem.java @@ -14,9 +14,7 @@ import com.djrapitops.plan.system.webserver.WebServerSystem; import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.utility.log.Log; -import java.util.Optional; import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; /** * ConnectionSystem for Bungee. @@ -59,20 +57,6 @@ public class BungeeConnectionSystem extends ConnectionSystem { return server; } - private Server getOneBukkitServer() { - int rand = ThreadLocalRandom.current().nextInt(bukkitServers.size()); - int i = 0; - for (Server server : bukkitServers.values()) { - if (i == rand) { - return server; - } - i++; - } - // Fallback if code above fails (Shouldn't) - Optional first = bukkitServers.values().stream().findAny(); - return first.orElse(null); - } - @Override public void sendWideInfoRequest(WideRequest infoRequest) throws NoServersException { refreshServerMap(); @@ -99,8 +83,4 @@ public class BungeeConnectionSystem extends ConnectionSystem { refreshServerMap(); } - @Override - public void disable() { - - } } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java index 70a4054b2..080f33ee1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/info/connection/ConnectionSystem.java @@ -111,4 +111,11 @@ public abstract class ConnectionSystem implements SubSystem { public List getBukkitServers() { return new ArrayList<>(bukkitServers.values()); } + + @Override + public void disable() { + setupAllowed = false; + bukkitServers.clear(); + dataRequests.clear(); + } }