UnconfiguredPipelineHandler.java
net.minecraft.network.UnconfiguredPipelineHandler
信息
- 全限定名:net.minecraft.network.UnconfiguredPipelineHandler
- 类型:public class
- 包:net.minecraft.network
- 源码路径:src/main/java/net/minecraft/network/UnconfiguredPipelineHandler.java
- 起始行号:L15
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
-
net.minecraft.network.UnconfiguredPipelineHandler.Inbound- 类型:
class - 修饰符:
public static - 源码定位:
L35 - 说明:
TODO
- 类型:
-
net.minecraft.network.UnconfiguredPipelineHandler.InboundConfigurationTask- 类型:
interface - 修饰符:
public - 源码定位:
L63 - 说明:
TODO
- 类型:
-
net.minecraft.network.UnconfiguredPipelineHandler.Outbound- 类型:
class - 修饰符:
public static - 源码定位:
L74 - 说明:
TODO
- 类型:
-
net.minecraft.network.UnconfiguredPipelineHandler.OutboundConfigurationTask- 类型:
interface - 修饰符:
public - 源码定位:
L97 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static <T extends PacketListener> UnconfiguredPipelineHandler.InboundConfigurationTask setupInboundProtocol(ProtocolInfo<T> protocolInfo) @ L16
- 方法名:setupInboundProtocol
- 源码定位:L16
- 返回类型:
UnconfiguredPipelineHandler.InboundConfigurationTask - 修饰符:public static
参数:
- protocolInfo: ProtocolInfo
说明:
TODO
private static UnconfiguredPipelineHandler.InboundConfigurationTask setupInboundHandler(ChannelInboundHandler newHandler) @ L20
- 方法名:setupInboundHandler
- 源码定位:L20
- 返回类型:UnconfiguredPipelineHandler.InboundConfigurationTask
- 修饰符:private static
参数:
- newHandler: ChannelInboundHandler
说明:
TODO
public static <T extends PacketListener> UnconfiguredPipelineHandler.OutboundConfigurationTask setupOutboundProtocol(ProtocolInfo<T> codecData) @ L27
- 方法名:setupOutboundProtocol
- 源码定位:L27
- 返回类型:
UnconfiguredPipelineHandler.OutboundConfigurationTask - 修饰符:public static
参数:
- codecData: ProtocolInfo
说明:
TODO
private static UnconfiguredPipelineHandler.OutboundConfigurationTask setupOutboundHandler(ChannelOutboundHandler newHandler) @ L31
- 方法名:setupOutboundHandler
- 源码定位:L31
- 返回类型:UnconfiguredPipelineHandler.OutboundConfigurationTask
- 修饰符:private static
参数:
- newHandler: ChannelOutboundHandler
说明:
TODO
代码
public class UnconfiguredPipelineHandler {
public static <T extends PacketListener> UnconfiguredPipelineHandler.InboundConfigurationTask setupInboundProtocol(ProtocolInfo<T> protocolInfo) {
return setupInboundHandler(new PacketDecoder<>(protocolInfo));
}
private static UnconfiguredPipelineHandler.InboundConfigurationTask setupInboundHandler(ChannelInboundHandler newHandler) {
return ctx -> {
ctx.pipeline().replace(ctx.name(), "decoder", newHandler);
ctx.channel().config().setAutoRead(true);
};
}
public static <T extends PacketListener> UnconfiguredPipelineHandler.OutboundConfigurationTask setupOutboundProtocol(ProtocolInfo<T> codecData) {
return setupOutboundHandler(new PacketEncoder<>(codecData));
}
private static UnconfiguredPipelineHandler.OutboundConfigurationTask setupOutboundHandler(ChannelOutboundHandler newHandler) {
return ctx -> ctx.pipeline().replace(ctx.name(), "encoder", newHandler);
}
public static class Inbound extends ChannelDuplexHandler {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (!(msg instanceof ByteBuf) && !(msg instanceof Packet)) {
ctx.fireChannelRead(msg);
} else {
ReferenceCountUtil.release(msg);
throw new DecoderException("Pipeline has no inbound protocol configured, can't process packet " + msg);
}
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof UnconfiguredPipelineHandler.InboundConfigurationTask configurationTask) {
try {
configurationTask.run(ctx);
} finally {
ReferenceCountUtil.release(msg);
}
promise.setSuccess();
} else {
ctx.write(msg, promise);
}
}
}
@FunctionalInterface
public interface InboundConfigurationTask {
void run(ChannelHandlerContext ctx);
default UnconfiguredPipelineHandler.InboundConfigurationTask andThen(UnconfiguredPipelineHandler.InboundConfigurationTask otherTask) {
return ctx -> {
this.run(ctx);
otherTask.run(ctx);
};
}
}
public static class Outbound extends ChannelOutboundHandlerAdapter {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof Packet) {
ReferenceCountUtil.release(msg);
throw new EncoderException("Pipeline has no outbound protocol configured, can't process packet " + msg);
} else {
if (msg instanceof UnconfiguredPipelineHandler.OutboundConfigurationTask configurationTask) {
try {
configurationTask.run(ctx);
} finally {
ReferenceCountUtil.release(msg);
}
promise.setSuccess();
} else {
ctx.write(msg, promise);
}
}
}
}
@FunctionalInterface
public interface OutboundConfigurationTask {
void run(ChannelHandlerContext ctx);
default UnconfiguredPipelineHandler.OutboundConfigurationTask andThen(UnconfiguredPipelineHandler.OutboundConfigurationTask otherTask) {
return ctx -> {
this.run(ctx);
otherTask.run(ctx);
};
}
}
}引用的其他类
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置: