geforkt von Mirrors/Velocity
Use channel factories to create new channels
Dieser Commit ist enthalten in:
Ursprung
e3a95b4783
Commit
d65507d4d5
@ -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())
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
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.ReflectiveChannelFactory;
|
||||||
import io.netty.channel.epoll.Epoll;
|
import io.netty.channel.epoll.Epoll;
|
||||||
import io.netty.channel.epoll.EpollDatagramChannel;
|
import io.netty.channel.epoll.EpollDatagramChannel;
|
||||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||||
@ -18,30 +20,57 @@ 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, NioServerSocketChannel.class,
|
||||||
|
NioSocketChannel::new, NioSocketChannel.class,
|
||||||
|
NioDatagramChannel::new, NioDatagramChannel.class,
|
||||||
(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, EpollServerSocketChannel.class,
|
||||||
EpollDatagramChannel.class,
|
EpollSocketChannel::new, EpollSocketChannel.class,
|
||||||
|
EpollDatagramChannel::new, EpollDatagramChannel.class,
|
||||||
(name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type)));
|
(name, type) -> new EpollEventLoopGroup(0, createThreadFactory(name, type)));
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
|
@Deprecated
|
||||||
final Class<? extends ServerSocketChannel> serverSocketChannelClass;
|
final Class<? extends ServerSocketChannel> serverSocketChannelClass;
|
||||||
|
@Deprecated
|
||||||
final Class<? extends SocketChannel> socketChannelClass;
|
final Class<? extends SocketChannel> socketChannelClass;
|
||||||
|
@Deprecated
|
||||||
final Class<? extends DatagramChannel> datagramChannelClass;
|
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;
|
final BiFunction<String, Type, EventLoopGroup> eventLoopGroupFactory;
|
||||||
|
|
||||||
TransportType(final String name,
|
TransportType(final String name,
|
||||||
|
final ChannelFactory<? extends ServerSocketChannel> serverSocketChannelFactory,
|
||||||
final Class<? extends ServerSocketChannel> serverSocketChannelClass,
|
final Class<? extends ServerSocketChannel> serverSocketChannelClass,
|
||||||
|
final ChannelFactory<? extends SocketChannel> socketChannelFactory,
|
||||||
final Class<? extends SocketChannel> socketChannelClass,
|
final Class<? extends SocketChannel> socketChannelClass,
|
||||||
|
final ChannelFactory<? extends DatagramChannel> datagramChannelFactory,
|
||||||
final Class<? extends DatagramChannel> datagramChannelClass,
|
final Class<? extends DatagramChannel> datagramChannelClass,
|
||||||
final BiFunction<String, Type, EventLoopGroup> eventLoopGroupFactory) {
|
final BiFunction<String, Type, EventLoopGroup> eventLoopGroupFactory) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.serverSocketChannelClass = serverSocketChannelClass;
|
this.serverSocketChannelClass = serverSocketChannelClass;
|
||||||
this.socketChannelClass = socketChannelClass;
|
this.socketChannelClass = socketChannelClass;
|
||||||
this.datagramChannelClass = datagramChannelClass;
|
this.datagramChannelClass = datagramChannelClass;
|
||||||
|
this.serverSocketChannelFactory = serverSocketChannelFactory;
|
||||||
|
this.socketChannelFactory = socketChannelFactory;
|
||||||
|
this.datagramChannelFactory = datagramChannelFactory;
|
||||||
this.eventLoopGroupFactory = eventLoopGroupFactory;
|
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, new ReflectiveChannelFactory<>(serverSocketChannelClass), serverSocketChannelClass,
|
||||||
|
new ReflectiveChannelFactory<>(socketChannelClass), socketChannelClass,
|
||||||
|
new ReflectiveChannelFactory<>(datagramChannelClass), datagramChannelClass,
|
||||||
|
eventLoopGroupFactory);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
return this.name;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren