@ChannelHandler.Sharable public class ConnectionWatchdog extends ChannelInboundHandlerAdapter implements TimerTask
ChannelHandler
responsible for monitoring the channel and reconnecting when the connection is lost.ChannelHandler.Sharable
Modifier and Type | Field and Description |
---|---|
static long |
LOGGING_QUIET_TIME_MS |
static int |
RETRY_TIMEOUT_MAX |
Constructor and Description |
---|
ConnectionWatchdog(Bootstrap bootstrap,
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. |
ConnectionWatchdog(Bootstrap bootstrap,
Timer timer,
Supplier<SocketAddress> socketAddressSupplier)
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(ChannelHandlerContext ctx) |
void |
channelInactive(ChannelHandlerContext ctx) |
void |
run(Timeout timeout)
Reconnect to the remote address that the closed channel was connected to.
|
void |
setReconnect(boolean reconnect) |
void |
userEventTriggered(ChannelHandlerContext ctx,
Object evt) |
channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
handlerAdded, handlerRemoved, isSharable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
handlerAdded, handlerRemoved
public static final long LOGGING_QUIET_TIME_MS
public static final int RETRY_TIMEOUT_MAX
public ConnectionWatchdog(Bootstrap bootstrap, 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 ConnectionWatchdog(Bootstrap bootstrap, Timer timer, Supplier<SocketAddress> socketAddressSupplier)
ChannelGroup
and establishes a new
Channel
when disconnected, while reconnect is true. The socketAddressSupplier can supply the reconnect address.bootstrap
- Configuration for new channels.timer
- Timer used for delayed reconnect.socketAddressSupplier
- the socket address suplier for gaining an address to reconnect topublic void setReconnect(boolean reconnect)
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
userEventTriggered
in interface ChannelInboundHandler
userEventTriggered
in class ChannelInboundHandlerAdapter
Exception
public void channelActive(ChannelHandlerContext ctx) throws Exception
channelActive
in interface ChannelInboundHandler
channelActive
in class ChannelInboundHandlerAdapter
Exception
public void channelInactive(ChannelHandlerContext ctx) throws Exception
channelInactive
in interface ChannelInboundHandler
channelInactive
in class ChannelInboundHandlerAdapter
Exception
public void run(Timeout timeout) throws Exception
ChannelPipeline
with
the same handler instances contained in the old channel's pipeline.Copyright © 2015. All rights reserved.