LaunchServer code optimizations.

This commit is contained in:
zaxar163 2019-01-02 17:53:34 +04:00 committed by Gravit
parent 3a8f4dcadc
commit f56c26ad2b
2 changed files with 2 additions and 4 deletions

View file

@ -51,7 +51,6 @@ public ProguardConf(LaunchServer srv) {
private void genConfig(boolean force) throws IOException { private void genConfig(boolean force) throws IOException {
if (IOHelper.exists(config) && !force) return; if (IOHelper.exists(config) && !force) return;
Files.deleteIfExists(config); Files.deleteIfExists(config);
config.toFile().createNewFile();
try (OutputStream out = IOHelper.newOutput(config); InputStream in = IOHelper.newInput(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/proguard.cfg"))) { try (OutputStream out = IOHelper.newOutput(config); InputStream in = IOHelper.newInput(IOHelper.getResourceURL("ru/gravit/launchserver/defaults/proguard.cfg"))) {
IOHelper.transfer(in, out); IOHelper.transfer(in, out);
} }

View file

@ -9,7 +9,7 @@
public class SessionManager implements NeedGarbageCollection { public class SessionManager implements NeedGarbageCollection {
public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут public static final long SESSION_TIMEOUT = 10 * 60 * 1000; // 10 минут
public static final boolean NON_GARBAGE_SERVER = true; public static final boolean GARBAGE_SERVER = Boolean.parseBoolean(System.getProperty("launcher.garbage.sessions", "false"));
private HashSet<Client> clientSet = new HashSet<>(128); private HashSet<Client> clientSet = new HashSet<>(128);
@ -19,10 +19,9 @@ public boolean addClient(Client client) {
} }
@Override @Override
public void garbageCollection() { public void garbageCollection() {
long time = System.currentTimeMillis(); long time = System.currentTimeMillis();
clientSet.removeIf(c -> (c.timestamp + SESSION_TIMEOUT < time) && ((c.type == Client.Type.USER) || ((c.type == Client.Type.SERVER) && !NON_GARBAGE_SERVER))); clientSet.removeIf(c -> (c.timestamp + SESSION_TIMEOUT < time) && (c.type == Client.Type.USER) && GARBAGE_SERVER);
} }