Class TcpChaosHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
ChannelDuplexHandler that injects raw TCP-layer faults
before HTTP decoding, based on the TcpChaosProfile
registered in TcpChaosRegistry for the connection's remote host.
Fault types mirror Toxiproxy's named toxics: latency, down, bandwidth, slow_close, timeout, reset_peer, slicer, limit_data.
Latency and bandwidth model a slow link: inbound reads join one FIFO queue per
connection and are delivered in arrival order, each after the bytes ahead of it have been
sent at the configured bandwidth and then the configured latency has elapsed. While more than
PAUSE_READS_ABOVE_QUEUED_BYTES are queued the connection stops reading (a
ChannelReadPause hold), resuming at RESUME_READS_AT_QUEUED_BYTES, so a fast
sender is held back by TCP flow control, as behind a real slow link, instead of queueing without
limit. Queued buffers are released when the connection closes.
This handler is not sharable (@ChannelHandler.Sharable
is intentionally absent) because it maintains per-connection state.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) voidclose(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx) Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, connect, deregister, disconnect, flush, read, writeMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, 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
-
Constructor Details
-
TcpChaosHandler
public TcpChaosHandler()
-
-
Method Details
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelInactive
- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter
-
close
public void close(io.netty.channel.ChannelHandlerContext ctx, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
closein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
closein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-