[FEATURE] Автозапуск netty сервера при его настройке

This commit is contained in:
Gravit 2019-01-29 22:42:31 +07:00
parent e2c7b455d2
commit 0e215899e4
No known key found for this signature in database
GPG key ID: 061981E1E85D3216

View file

@ -27,6 +27,7 @@
import ru.gravit.launchserver.manangers.hook.BuildHookManager; import ru.gravit.launchserver.manangers.hook.BuildHookManager;
import ru.gravit.launchserver.manangers.hook.SocketHookManager; import ru.gravit.launchserver.manangers.hook.SocketHookManager;
import ru.gravit.launchserver.response.Response; import ru.gravit.launchserver.response.Response;
import ru.gravit.launchserver.socket.NettyServerSocketHandler;
import ru.gravit.launchserver.socket.ServerSocketHandler; import ru.gravit.launchserver.socket.ServerSocketHandler;
import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.RequestTextureProvider;
import ru.gravit.launchserver.texture.TextureProvider; import ru.gravit.launchserver.texture.TextureProvider;
@ -289,6 +290,8 @@ public static void main(String... args) throws Throwable {
public final ServerSocketHandler serverSocketHandler; public final ServerSocketHandler serverSocketHandler;
public final NettyServerSocketHandler nettyServerSocketHandler;
private final AtomicBoolean started = new AtomicBoolean(false); private final AtomicBoolean started = new AtomicBoolean(false);
// Updates and profiles // Updates and profiles
@ -450,6 +453,10 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
modulesManager.postInitModules(); modulesManager.postInitModules();
// start updater // start updater
this.updater = new Updater(this); this.updater = new Updater(this);
if(config.netty != null)
nettyServerSocketHandler = new NettyServerSocketHandler(this);
else
nettyServerSocketHandler = null;
} }
public static void initGson() { public static void initGson() {
@ -587,6 +594,11 @@ public void rebindServerSocket() {
CommonHelper.newThread("Server Socket Thread", false, serverSocketHandler).start(); CommonHelper.newThread("Server Socket Thread", false, serverSocketHandler).start();
} }
public void rebindNettyServerSocket() {
nettyServerSocketHandler.close();
CommonHelper.newThread("Netty Server Socket Thread", false, nettyServerSocketHandler).start();
}
@Override @Override
public void run() { public void run() {
if (started.getAndSet(true)) if (started.getAndSet(true))
@ -596,6 +608,8 @@ public void run() {
JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close)); JVMHelper.RUNTIME.addShutdownHook(CommonHelper.newThread(null, false, this::close));
CommonHelper.newThread("Command Thread", true, commandHandler).start(); CommonHelper.newThread("Command Thread", true, commandHandler).start();
rebindServerSocket(); rebindServerSocket();
if(config.netty != null)
rebindNettyServerSocket();
modulesManager.finishModules(); modulesManager.finishModules();
} }