@ChannelHandler.Sharable
public class ConnectionWatchdog
extends io.netty.channel.ChannelInboundHandlerAdapter
implements io.netty.util.TimerTask
ChannelHandler
responsible for monitoring the channel and
reconnecting when the connection is lost.Constructor and Description |
---|
ConnectionWatchdog(io.netty.bootstrap.Bootstrap bootstrap,
io.netty.channel.group.ChannelGroup channels,
io.netty.util.Timer timer)
Create a new watchdog that adds to new connections to the supplied
ChannelGroup
and establishes a new Channel when disconnected, while reconnect is true. |
Modifier and Type | Method and Description |
---|---|
void |
channelActive(io.netty.channel.ChannelHandlerContext ctx) |
void |
channelInactive(io.netty.channel.ChannelHandlerContext ctx) |
void |
exceptionCaught(io.netty.channel.ChannelHandlerContext ctx,
Throwable cause) |
void |
run(io.netty.util.Timeout timeout)
Reconnect to the remote address that the closed channel was connected to.
|
void |
setReconnect(boolean reconnect) |
channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered
handlerAdded, handlerRemoved, isSharable
public ConnectionWatchdog(io.netty.bootstrap.Bootstrap bootstrap, io.netty.channel.group.ChannelGroup channels, io.netty.util.Timer timer)
ChannelGroup
and establishes a new Channel
when disconnected, while reconnect is true.bootstrap
- Configuration for new channels.timer
- Timer used for delayed reconnect.public void setReconnect(boolean reconnect)
public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelActive
in interface io.netty.channel.ChannelInboundHandler
channelActive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
channelInactive
in interface io.netty.channel.ChannelInboundHandler
channelInactive
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
exceptionCaught
in interface io.netty.channel.ChannelHandler
exceptionCaught
in interface io.netty.channel.ChannelInboundHandler
exceptionCaught
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void run(io.netty.util.Timeout timeout) throws Exception
ChannelPipeline
with the same handler instances
contained in the old channel's pipeline.run
in interface io.netty.util.TimerTask
timeout
- Timer task handle.Exception
- when reconnection fails.Copyright © 2014. All rights reserved.