geforkt von Mirrors/Velocity
Minor Netty cleanup
Dieser Commit ist enthalten in:
Ursprung
85e5fb4827
Commit
6d5bacb262
@ -265,15 +265,11 @@ public class VelocityServer implements ProxyServer {
|
||||
logger.info("Loaded {} plugins", pluginManager.getPlugins().size());
|
||||
}
|
||||
|
||||
public EventLoopGroup getWorkerGroup() {
|
||||
return this.cm.getWorkerGroup();
|
||||
}
|
||||
|
||||
public Bootstrap initializeGenericBootstrap() {
|
||||
public Bootstrap createBootstrap() {
|
||||
return this.cm.createWorker();
|
||||
}
|
||||
|
||||
public Bootstrap initializeGenericBootstrap(EventLoopGroup group) {
|
||||
public Bootstrap createBootstrap(EventLoopGroup group) {
|
||||
return this.cm.createWorker(group);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
@ -77,7 +76,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
CompletableFuture<Impl> result = new CompletableFuture<>();
|
||||
// Note: we use the event loop for the connection the player is on. This reduces context
|
||||
// switches.
|
||||
server.initializeGenericBootstrap(proxyPlayer.getMinecraftConnection().eventLoop())
|
||||
server.createBootstrap(proxyPlayer.getMinecraftConnection().eventLoop())
|
||||
.handler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
|
@ -18,6 +18,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class ConnectionManager {
|
||||
|
||||
@ -113,23 +114,23 @@ public final class ConnectionManager {
|
||||
}
|
||||
|
||||
public Bootstrap createWorker() {
|
||||
return this.createWorker(this.workerGroup);
|
||||
return this.createWorker(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TCP {@link Bootstrap} using Velocity's event loops.
|
||||
*
|
||||
* @param group the event loop group to use
|
||||
* @param group the event loop group to use. Use {@code null} for the default worker group.
|
||||
*
|
||||
* @return a new {@link Bootstrap}
|
||||
*/
|
||||
public Bootstrap createWorker(EventLoopGroup group) {
|
||||
public Bootstrap createWorker(@Nullable EventLoopGroup group) {
|
||||
return new Bootstrap()
|
||||
.channel(this.transportType.socketChannelClass)
|
||||
.group(group)
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
|
||||
this.server.getConfiguration().getConnectTimeout())
|
||||
.group(group == null ? this.workerGroup : group)
|
||||
.resolver(this.resolverGroup);
|
||||
}
|
||||
|
||||
@ -164,10 +165,6 @@ public final class ConnectionManager {
|
||||
return bossGroup;
|
||||
}
|
||||
|
||||
public EventLoopGroup getWorkerGroup() {
|
||||
return workerGroup;
|
||||
}
|
||||
|
||||
public ServerChannelInitializerHolder getServerChannelInitializer() {
|
||||
return this.serverChannelInitializer;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpClientCodec;
|
||||
import io.netty.handler.codec.http.HttpContentCompressor;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import io.netty.handler.codec.http.HttpRequest;
|
||||
@ -22,6 +21,7 @@ import java.net.URL;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class NettyHttpClient {
|
||||
|
||||
@ -38,7 +38,7 @@ public class NettyHttpClient {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
private ChannelFuture establishConnection(URL url, EventLoop loop) {
|
||||
private ChannelFuture establishConnection(URL url, @Nullable EventLoop loop) {
|
||||
String host = url.getHost();
|
||||
int port = url.getPort();
|
||||
boolean ssl = url.getProtocol().equals("https");
|
||||
@ -47,7 +47,7 @@ public class NettyHttpClient {
|
||||
}
|
||||
|
||||
InetSocketAddress address = InetSocketAddress.createUnresolved(host, port);
|
||||
return server.initializeGenericBootstrap(loop)
|
||||
return server.createBootstrap(loop)
|
||||
.handler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
@ -74,7 +74,7 @@ public class NettyHttpClient {
|
||||
* @param loop the event loop to use
|
||||
* @return a future representing the response
|
||||
*/
|
||||
public CompletableFuture<SimpleHttpResponse> get(URL url, EventLoop loop) {
|
||||
public CompletableFuture<SimpleHttpResponse> get(URL url, @Nullable EventLoop loop) {
|
||||
CompletableFuture<SimpleHttpResponse> reply = new CompletableFuture<>();
|
||||
establishConnection(url, loop)
|
||||
.addListener((ChannelFutureListener) future -> {
|
||||
@ -109,18 +109,18 @@ public class NettyHttpClient {
|
||||
*/
|
||||
public CompletableFuture<SimpleHttpResponse> post(URL url, ByteBuf body,
|
||||
Consumer<HttpRequest> decorator) {
|
||||
return post(url, server.getWorkerGroup().next(), body, decorator);
|
||||
return post(url, null, body, decorator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts an HTTP POST request to the specified URL.
|
||||
* @param url the URL to fetch
|
||||
* @param loop the event loop to use
|
||||
* @param body the body to post
|
||||
* @param body the body to post - the HTTP client takes ownership of the buffer
|
||||
* @param decorator a consumer that can modify the request as required
|
||||
* @return a future representing the response
|
||||
*/
|
||||
public CompletableFuture<SimpleHttpResponse> post(URL url, EventLoop loop, ByteBuf body,
|
||||
public CompletableFuture<SimpleHttpResponse> post(URL url, @Nullable EventLoop loop, ByteBuf body,
|
||||
Consumer<HttpRequest> decorator) {
|
||||
CompletableFuture<SimpleHttpResponse> reply = new CompletableFuture<>();
|
||||
establishConnection(url, loop)
|
||||
|
@ -19,7 +19,6 @@ import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder;
|
||||
@ -63,7 +62,7 @@ public class VelocityRegisteredServer implements RegisteredServer {
|
||||
throw new IllegalStateException("No Velocity proxy instance available");
|
||||
}
|
||||
CompletableFuture<ServerPing> pingFuture = new CompletableFuture<>();
|
||||
server.initializeGenericBootstrap()
|
||||
server.createBootstrap()
|
||||
.handler(new ChannelInitializer<Channel>() {
|
||||
@Override
|
||||
protected void initChannel(Channel ch) throws Exception {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren