Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Merge pull request #340 from xxDark/channel-factory
Use channel factories to create new channels
Dieser Commit ist enthalten in:
Commit
5dcc0460a1
@ -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())
|
||||
|
@ -1,6 +1,7 @@
|
||||
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.epoll.Epoll;
|
||||
import io.netty.channel.epoll.EpollDatagramChannel;
|
||||
@ -18,27 +19,30 @@ import java.util.concurrent.ThreadFactory;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
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))),
|
||||
EPOLL("epoll", EpollServerSocketChannel.class, EpollSocketChannel.class,
|
||||
EpollDatagramChannel.class,
|
||||
EPOLL("epoll", EpollServerSocketChannel::new,
|
||||
EpollSocketChannel::new,
|
||||
EpollDatagramChannel::new,
|
||||
(name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type)));
|
||||
|
||||
final String name;
|
||||
final Class<? extends ServerSocketChannel> serverSocketChannelClass;
|
||||
final Class<? extends SocketChannel> socketChannelClass;
|
||||
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 Class<? extends ServerSocketChannel> serverSocketChannelClass,
|
||||
final Class<? extends SocketChannel> socketChannelClass,
|
||||
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) {
|
||||
this.name = name;
|
||||
this.serverSocketChannelClass = serverSocketChannelClass;
|
||||
this.socketChannelClass = socketChannelClass;
|
||||
this.datagramChannelClass = datagramChannelClass;
|
||||
this.serverSocketChannelFactory = serverSocketChannelFactory;
|
||||
this.socketChannelFactory = socketChannelFactory;
|
||||
this.datagramChannelFactory = datagramChannelFactory;
|
||||
this.eventLoopGroupFactory = eventLoopGroupFactory;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren