More clarity

This commit is contained in:
filoghost 2016-08-29 11:15:06 +02:00
parent 108e1bb995
commit 1548d73962

View File

@ -2,6 +2,7 @@ package com.gmail.filoghost.holographicdisplays.task;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import com.gmail.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerInfo; import com.gmail.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerInfo;
import com.gmail.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker; import com.gmail.filoghost.holographicdisplays.bridge.bungeecord.BungeeServerTracker;
@ -12,16 +13,19 @@ import com.gmail.filoghost.holographicdisplays.util.DebugHandler;
*/ */
public class BungeeCleanupTask implements Runnable { public class BungeeCleanupTask implements Runnable {
private static final long MAX_INACTIVITY = TimeUnit.MINUTES.toMillis(10);
@Override @Override
public void run() { public void run() {
long now = System.currentTimeMillis();
Iterator<Entry<String, BungeeServerInfo>> iter = BungeeServerTracker.getTrackedServers().entrySet().iterator(); Iterator<Entry<String, BungeeServerInfo>> iter = BungeeServerTracker.getTrackedServers().entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Entry<String, BungeeServerInfo> next = iter.next(); Entry<String, BungeeServerInfo> next = iter.next();
long lastRequest = next.getValue().getLastRequest(); long lastRequest = next.getValue().getLastRequest();
if (lastRequest != 0 && System.currentTimeMillis() - lastRequest > 600000) { // 10 * 60 * 1000 = 10 minutes. if (lastRequest != 0 && now - lastRequest > MAX_INACTIVITY) {
// Don't track that server anymore. // Don't track that server anymore.
iter.remove(); iter.remove();
DebugHandler.logToConsole("Removed bungee server \"" + next.getKey() + "\" from tracking due to inactivity."); DebugHandler.logToConsole("Removed bungee server \"" + next.getKey() + "\" from tracking due to inactivity.");