mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-21 10:18:36 -05:00
Allow server to define packet handler executor factory
This commit is contained in:
parent
d6d2a33b54
commit
e6acb395fb
2 changed files with 11 additions and 3 deletions
|
@ -19,17 +19,24 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TcpServer extends AbstractServer {
|
||||
private static final TransportHelper.TransportType TRANSPORT_TYPE = TransportHelper.determineTransportMethod();
|
||||
private static final Logger log = LoggerFactory.getLogger(TcpServer.class);
|
||||
|
||||
private final Supplier<Executor> packetHandlerExecutorFactory;
|
||||
private EventLoopGroup group;
|
||||
private Channel channel;
|
||||
|
||||
public TcpServer(String host, int port, Supplier<? extends PacketProtocol> protocol) {
|
||||
this(host, port, protocol, DefaultPacketHandlerExecutor::createExecutor);
|
||||
}
|
||||
|
||||
public TcpServer(String host, int port, Supplier<? extends PacketProtocol> protocol, Supplier<Executor> packetHandlerExecutorFactory) {
|
||||
super(host, port, protocol);
|
||||
this.packetHandlerExecutorFactory = packetHandlerExecutorFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +64,7 @@ public class TcpServer extends AbstractServer {
|
|||
InetSocketAddress address = (InetSocketAddress) channel.remoteAddress();
|
||||
PacketProtocol protocol = createPacketProtocol();
|
||||
|
||||
TcpSession session = new TcpServerSession(address.getHostName(), address.getPort(), protocol, TcpServer.this);
|
||||
TcpSession session = new TcpServerSession(address.getHostName(), address.getPort(), protocol, TcpServer.this, packetHandlerExecutorFactory.get());
|
||||
session.getPacketProtocol().newServerSession(TcpServer.this, session);
|
||||
|
||||
ChannelPipeline pipeline = channel.pipeline();
|
||||
|
|
|
@ -7,13 +7,14 @@ import org.geysermc.mcprotocollib.network.packet.PacketProtocol;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
public class TcpServerSession extends TcpSession {
|
||||
private final TcpServer server;
|
||||
private final PacketCodecHelper codecHelper;
|
||||
|
||||
public TcpServerSession(String host, int port, PacketProtocol protocol, TcpServer server) {
|
||||
super(host, port, protocol, DefaultPacketHandlerExecutor.createExecutor());
|
||||
public TcpServerSession(String host, int port, PacketProtocol protocol, TcpServer server, Executor packetHandlerExecutor) {
|
||||
super(host, port, protocol, packetHandlerExecutor);
|
||||
this.server = server;
|
||||
this.codecHelper = protocol.createHelper();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue