Class StaleConnectionHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
com.linkedin.alpini.netty4.handlers.StaleConnectionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
public class StaleConnectionHandler
extends io.netty.channel.ChannelDuplexHandler
This handler closes the connection when a ReadTimeoutException occurs.
Example:
public class MyChannelInitializer extendsChannelInitializer
<Channel
> { public void initChannel(Channel
channel) { channel.pipeline().addLast("readTimeoutHandler", newReadTimeoutHandler
(30, TimeUnit.SECONDS); channel.pipeline().addLast("staleConnectionHandler", newStaleConnectionHandler
()); } }
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Constructor Summary
ConstructorDescriptionCreate an EspressoIdleConnectionHandler which will close idle connections (detected by a separate IdleStateHandler added to the pipeline).StaleConnectionHandler
(long minCloseAge, long maxCloseAge, TimeUnit unit) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
channelRead
(io.netty.channel.ChannelHandlerContext ctx, Object msg) void
exceptionCaught
(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
.boolean
void
write
(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, read
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
StaleConnectionHandler
public StaleConnectionHandler()Create an EspressoIdleConnectionHandler which will close idle connections (detected by a separate IdleStateHandler added to the pipeline). -
StaleConnectionHandler
Deprecated.Create an EspressoIdleConnectionHandler which will close idle connections (detected by a separate IdleStateHandler added to the pipeline), and will close non-idle connections after a specified time. Connections will be closed at a random time betweenminCloseAge
andmaxCloseAge
.- Parameters:
minCloseAge
- base age of an active connection before we terminatemaxCloseAge
- random offset, should be large enough to spread out closing time for multiple connectionsunit
- TimeUnit for closeAfterAgeBase and closeAfterAgeRandom
-
-
Method Details
-
isStaleChannel
public boolean isStaleChannel() -
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception CallsChannelHandlerContext.fireExceptionCaught(Throwable)
to forward to the nextChannelHandler
in theChannelPipeline
.Sub-classes may override this method to change behavior.
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelHandler
- Specified by:
exceptionCaught
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
exceptionCaught
in classio.netty.channel.ChannelInboundHandlerAdapter
- Parameters:
ctx
-cause
-- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.channel.ChannelDuplexHandler
- Throws:
Exception
-
channelRead
- Specified by:
channelRead
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelRead
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
Exception
-