13
0
geforkt von Mirrors/Velocity

Merge pull request #340 from xxDark/channel-factory

Use channel factories to create new channels
Dieser Commit ist enthalten in:
Andrew Steinborn 2020-07-31 07:49:11 -04:00 committet von GitHub
Commit 5dcc0460a1
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 19 neuen und 16 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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