Package crow.game.codec.netty
Class ReadWriteLoggingHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
crow.game.codec.netty.ReadWriteLoggingHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
public class ReadWriteLoggingHandler
extends io.netty.channel.ChannelDuplexHandler
This is a simplification of the code found in nettys LoggingHandler that juts dumps read and
writes and is used to dump the POJOs AFTER the frame and packet codecs are done. Below is an
example of the pipeline, which uses the given logger and filters out ping and pong messages since
they tend to be noisy.
ch.pipeline()
.addLast(
new LoggingHandler(LogLevel.DEBUG),
new FrameCodec(context),
new PacketCodec(context),
new ReadWriteLoggingHandler(
slf4jLogger, Pattern.compile("ha0\\.proto\\.Ping|ha0\\.proto\\.Pong")));
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionReadWriteLoggingHandler(org.slf4j.Logger logger) ReadWriteLoggingHandler(org.slf4j.Logger logger, Pattern filter) -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
ReadWriteLoggingHandler
-
ReadWriteLoggingHandler
public ReadWriteLoggingHandler(org.slf4j.Logger logger)
-
-
Method Details
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-