@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(ClientOptions clientOptions,
Bootstrap bootstrap,
Timer timer,
EventExecutorGroup reconnectWorkers,
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) |
boolean |
isListenOnChannelInactive() |
boolean |
isReconnectSuspended() |
void |
run(Timeout timeout)
Reconnect to the remote address that the closed channel was connected to.
|
void |
scheduleReconnect()
Schedule reconnect if channel is not available/not active.
|
void |
setListenOnChannelInactive(boolean listenOnChannelInactive) |
void |
setReconnectSuspended(boolean reconnectSuspended) |
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(ClientOptions clientOptions, Bootstrap bootstrap, Timer timer, EventExecutorGroup reconnectWorkers, Supplier<SocketAddress> socketAddressSupplier)
ChannelGroup
and establishes a new
Channel
when disconnected, while reconnect is true. The socketAddressSupplier can supply the reconnect address.clientOptions
- client options for the current connection, must not be nullbootstrap
- Configuration for new channels, must not be nulltimer
- Timer used for delayed reconnect, must not be nullreconnectWorkers
- executor group for reconnect tasks, must not be nullsocketAddressSupplier
- the socket address supplier to obtain an address for reconnection, may be nullpublic 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 scheduleReconnect()
public void run(Timeout timeout) throws Exception
ChannelPipeline
with
the same handler instances contained in the old channel's pipeline.public void setListenOnChannelInactive(boolean listenOnChannelInactive)
public boolean isListenOnChannelInactive()
public boolean isReconnectSuspended()
public void setReconnectSuspended(boolean reconnectSuspended)
Copyright © 2016. All rights reserved.