13
0
geforkt von Mirrors/Velocity

Use channel factories to create new channels

Dieser Commit ist enthalten in:
xDark 2020-07-30 17:34:37 +03:00
Ursprung e3a95b4783
Commit d65507d4d5
2 geänderte Dateien mit 40 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -26,7 +26,6 @@ import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.RequestBuilder;
import org.asynchttpclient.filter.FilterContext;
import org.asynchttpclient.filter.FilterContext.FilterContextBuilder;
import org.asynchttpclient.filter.FilterException;
import org.asynchttpclient.filter.RequestFilter;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -93,7 +92,7 @@ public final class ConnectionManager {
*/
public void bind(final InetSocketAddress address) {
final ServerBootstrap bootstrap = new ServerBootstrap()
.channel(this.transportType.serverSocketChannelClass)
.channelFactory(this.transportType.serverSocketChannelFactory)
.group(this.bossGroup, this.workerGroup)
.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, SERVER_WRITE_MARK)
.childHandler(this.serverChannelInitializer.get())
@ -126,7 +125,7 @@ public final class ConnectionManager {
public void queryBind(final String hostname, final int port) {
InetSocketAddress address = new InetSocketAddress(hostname, port);
final Bootstrap bootstrap = new Bootstrap()
.channel(this.transportType.datagramChannelClass)
.channelFactory(this.transportType.datagramChannelFactory)
.group(this.workerGroup)
.handler(new GS4QueryHandler(this.server))
.localAddress(address);
@ -151,7 +150,7 @@ public final class ConnectionManager {
*/
public Bootstrap createWorker(@Nullable EventLoopGroup group) {
Bootstrap bootstrap = new Bootstrap()
.channel(this.transportType.socketChannelClass)
.channelFactory(this.transportType.socketChannelFactory)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
this.server.getConfiguration().getConnectTimeout())

Datei anzeigen

@ -1,7 +1,9 @@
package com.velocitypowered.proxy.network;
import com.velocitypowered.proxy.util.concurrent.VelocityNettyThreadFactory;
import io.netty.channel.ChannelFactory;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ReflectiveChannelFactory;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollDatagramChannel;
import io.netty.channel.epoll.EpollEventLoopGroup;
@ -18,28 +20,55 @@ import java.util.concurrent.ThreadFactory;
import java.util.function.BiFunction;
enum TransportType {
NIO("NIO", NioServerSocketChannel.class, NioSocketChannel.class, NioDatagramChannel.class,
NIO("NIO", NioServerSocketChannel::new, NioServerSocketChannel.class,
NioSocketChannel::new, NioSocketChannel.class,
NioDatagramChannel::new, NioDatagramChannel.class,
(name, type) -> new NioEventLoopGroup(0, createThreadFactory(name, type))),
EPOLL("epoll", EpollServerSocketChannel.class, EpollSocketChannel.class,
EpollDatagramChannel.class,
EPOLL("epoll", EpollServerSocketChannel::new, EpollServerSocketChannel.class,
EpollSocketChannel::new, EpollSocketChannel.class,
EpollDatagramChannel::new, EpollDatagramChannel.class,
(name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type)));
final String name;
@Deprecated
final Class<? extends ServerSocketChannel> serverSocketChannelClass;
@Deprecated
final Class<? extends SocketChannel> socketChannelClass;
@Deprecated
final Class<? extends DatagramChannel> datagramChannelClass;
final ChannelFactory<? extends ServerSocketChannel> serverSocketChannelFactory;
final ChannelFactory<? extends SocketChannel> socketChannelFactory;
final ChannelFactory<? extends DatagramChannel> datagramChannelFactory;
final BiFunction<String, Type, EventLoopGroup> eventLoopGroupFactory;
TransportType(final String name,
final ChannelFactory<? extends ServerSocketChannel> serverSocketChannelFactory,
final Class<? extends ServerSocketChannel> serverSocketChannelClass,
final ChannelFactory<? extends SocketChannel> socketChannelFactory,
final Class<? extends SocketChannel> socketChannelClass,
final ChannelFactory<? extends DatagramChannel> datagramChannelFactory,
final Class<? extends DatagramChannel> datagramChannelClass,
final BiFunction<String, Type, EventLoopGroup> eventLoopGroupFactory) {
this.name = name;
this.serverSocketChannelClass = serverSocketChannelClass;
this.socketChannelClass = socketChannelClass;
this.datagramChannelClass = datagramChannelClass;
this.serverSocketChannelFactory = serverSocketChannelFactory;
this.socketChannelFactory = socketChannelFactory;
this.datagramChannelFactory = datagramChannelFactory;
this.eventLoopGroupFactory = eventLoopGroupFactory;
}
@Deprecated
TransportType(final String name,
final Class<? extends ServerSocketChannel> serverSocketChannelClass,
final Class<? extends SocketChannel> socketChannelClass,
final Class<? extends DatagramChannel> datagramChannelClass,
final BiFunction<String, Type, EventLoopGroup> eventLoopGroupFactory) {
this.name = name;
this.serverSocketChannelClass = serverSocketChannelClass;
this.socketChannelClass = socketChannelClass;
this.datagramChannelClass = datagramChannelClass;
this.eventLoopGroupFactory = eventLoopGroupFactory;
this(name, new ReflectiveChannelFactory<>(serverSocketChannelClass), serverSocketChannelClass,
new ReflectiveChannelFactory<>(socketChannelClass), socketChannelClass,
new ReflectiveChannelFactory<>(datagramChannelClass), datagramChannelClass,
eventLoopGroupFactory);
}
@Override