[FEATURE] Перезагрузка конфига LaunchServer'а без его рестарта

This commit is contained in:
Gravit 2019-03-10 19:28:22 +07:00
parent 6c59b86779
commit 24b8227685
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
7 changed files with 69 additions and 20 deletions

View file

@ -53,7 +53,22 @@
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.zip.CRC32; import java.util.zip.CRC32;
public final class LaunchServer implements Runnable { public final class LaunchServer implements Runnable, AutoCloseable, Reloadable {
@Override
public void reload() throws Exception {
config.close();
LogHelper.info("Reading LaunchServer config file");
try (BufferedReader reader = IOHelper.newReader(configFile)) {
config = Launcher.gson.fromJson(reader, Config.class);
}
config.verify();
Launcher.applyLauncherEnv(config.env);
for (AuthProvider provider : config.authProvider) {
provider.init();
}
config.authHandler.init();
}
public static final class Config { public static final class Config {
public int port; public int port;
@ -170,6 +185,34 @@ public void verify() {
throw new NullPointerException("Netty must not be null"); throw new NullPointerException("Netty must not be null");
} }
} }
public void close()
{
try {
authHandler.close();
} catch (IOException e) {
LogHelper.error(e);
}
try {
for (AuthProvider p : authProvider) p.close();
} catch (IOException e) {
LogHelper.error(e);
}
try {
textureProvider.close();
} catch (IOException e) {
LogHelper.error(e);
}
try {
hwidHandler.close();
} catch (Exception e) {
LogHelper.error(e);
}
try {
permissionsHandler.close();
} catch (Exception e) {
LogHelper.error(e);
}
}
} }
public static class ExeConf { public static class ExeConf {
@ -269,7 +312,7 @@ public static void main(String... args) throws Throwable {
public final Path profilesDir; public final Path profilesDir;
// Server config // Server config
public final Config config; public Config config;
public final RSAPublicKey publicKey; public final RSAPublicKey publicKey;
@ -417,6 +460,7 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
authHookManager = new AuthHookManager(); authHookManager = new AuthHookManager();
GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(sessionManager);
GarbageManager.registerNeedGC(limiter); GarbageManager.registerNeedGC(limiter);
reloadManager.registerReloadable("launchServer", this);
if (config.permissionsHandler instanceof Reloadable) if (config.permissionsHandler instanceof Reloadable)
reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler); reloadManager.registerReloadable("permissionsHandler", (Reloadable) config.permissionsHandler);
if (config.authHandler instanceof Reloadable) if (config.authHandler instanceof Reloadable)
@ -521,22 +565,7 @@ public void close() {
serverSocketHandler.close(); serverSocketHandler.close();
// Close handlers & providers // Close handlers & providers
try { config.close();
config.authHandler.close();
} catch (IOException e) {
LogHelper.error(e);
}
try {
for (AuthProvider p : config.authProvider) p.close();
} catch (IOException e) {
LogHelper.error(e);
}
try {
config.textureProvider.close();
} catch (IOException e) {
LogHelper.error(e);
}
config.hwidHandler.close();
modulesManager.close(); modulesManager.close();
// Print last message before death :( // Print last message before death :(
LogHelper.info("LaunchServer stopped"); LogHelper.info("LaunchServer stopped");

View file

@ -38,7 +38,7 @@ public void check(HWID hwid, String username) throws HWIDException {
public abstract void check0(HWID hwid, String username) throws HWIDException; public abstract void check0(HWID hwid, String username) throws HWIDException;
@Override @Override
public abstract void close(); public abstract void close() throws Exception;
public abstract List<HWID> getHwid(String username) throws HWIDException; public abstract List<HWID> getHwid(String username) throws HWIDException;

View file

@ -13,4 +13,9 @@ public ClientPermissions getPermissions(String username) {
permissions.canAdmin = isAdmin; permissions.canAdmin = isAdmin;
return permissions; return permissions;
} }
@Override
public void close() {
}
} }

View file

@ -7,4 +7,9 @@ public class DefaultPermissionsHandler extends PermissionsHandler {
public ClientPermissions getPermissions(String username) { public ClientPermissions getPermissions(String username) {
return ClientPermissions.DEFAULT; return ClientPermissions.DEFAULT;
} }
@Override
public void close() throws Exception {
}
} }

View file

@ -33,6 +33,11 @@ public void reload() {
} }
} }
@Override
public void close() throws Exception {
}
public static class Enity { public static class Enity {
public String username; public String username;
public ClientPermissions permissions; public ClientPermissions permissions;

View file

@ -34,6 +34,11 @@ public void reload() {
} }
} }
@Override
public void close() throws Exception {
}
public static class Enity { public static class Enity {
public String username; public String username;
public ClientPermissions permissions; public ClientPermissions permissions;

View file

@ -7,7 +7,7 @@
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public abstract class PermissionsHandler { public abstract class PermissionsHandler implements AutoCloseable {
private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4); private static final Map<String, Class<? extends PermissionsHandler>> PERMISSIONS_HANDLERS = new ConcurrentHashMap<>(4);
private static boolean registredHandl = false; private static boolean registredHandl = false;