mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE][EXPERIMENTAL] NettyThreadFactory
This commit is contained in:
parent
3a3aafe5fa
commit
584e07328c
3 changed files with 25 additions and 6 deletions
|
@ -42,8 +42,8 @@ public LauncherNettyServer(LaunchServer server) {
|
||||||
if (config.performance.usingEpoll && !Epoll.isAvailable()) {
|
if (config.performance.usingEpoll && !Epoll.isAvailable()) {
|
||||||
LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause());
|
LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause());
|
||||||
}
|
}
|
||||||
bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread);
|
bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread, "LauncherNettyServer.bossGroup");
|
||||||
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread);
|
workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread, "LauncherNettyServer.workerGroup");
|
||||||
serverBootstrap = new ServerBootstrap();
|
serverBootstrap = new ServerBootstrap();
|
||||||
service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), server);
|
service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), server);
|
||||||
serverBootstrap.group(bossGroup, workerGroup)
|
serverBootstrap.group(bossGroup, workerGroup)
|
||||||
|
|
|
@ -15,11 +15,11 @@ public static void setUsingEpoll(boolean value) {
|
||||||
epoll = value;
|
epoll = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EventLoopGroup newEventLoopGroup(int threads) {
|
public static EventLoopGroup newEventLoopGroup(int threads, String poolName) {
|
||||||
if (epoll)
|
if (epoll)
|
||||||
return new EpollEventLoopGroup(threads);
|
return new EpollEventLoopGroup(threads, new NettyThreadFactory(poolName));
|
||||||
else
|
else
|
||||||
return new NioEventLoopGroup(threads);
|
return new NioEventLoopGroup(threads, new NettyThreadFactory(poolName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChannelFactory<? extends ServerChannel> getServerSocketChannelFactory() {
|
public static ChannelFactory<? extends ServerChannel> getServerSocketChannelFactory() {
|
||||||
|
@ -28,5 +28,4 @@ public static ChannelFactory<? extends ServerChannel> getServerSocketChannelFact
|
||||||
else
|
else
|
||||||
return NioServerSocketChannel::new;
|
return NioServerSocketChannel::new;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package pro.gravit.launchserver.socket;
|
||||||
|
|
||||||
|
import io.netty.util.concurrent.DefaultThreadFactory;
|
||||||
|
import pro.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
public class NettyThreadFactory extends DefaultThreadFactory {
|
||||||
|
public NettyThreadFactory(String poolName) {
|
||||||
|
super(poolName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Thread newThread(Runnable r, String name) {
|
||||||
|
Thread thread = super.newThread(r, name);
|
||||||
|
thread.setUncaughtExceptionHandler((th, e) -> {
|
||||||
|
if(LogHelper.isDebugEnabled())
|
||||||
|
LogHelper.error(e);
|
||||||
|
});
|
||||||
|
return thread;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue