@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,
EventExecutorGroup reconnectWorkers,
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(ClientOptions clientOptions,
Bootstrap bootstrap,
Timer timer,
EventExecutorGroup reconnectWorkers,
com.google.common.base.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 |
setReconnect(boolean reconnect)
Deprecated.
|
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, EventExecutorGroup reconnectWorkers, Timer timer)
ChannelGroup
and establishes a new
Channel
when disconnected, while reconnect is true.clientOptions
- client options for the current connectionbootstrap
- Configuration for new channels.reconnectWorkers
- executor group for reconnect tasks.timer
- Timer used for delayed reconnect.public ConnectionWatchdog(ClientOptions clientOptions, Bootstrap bootstrap, Timer timer, EventExecutorGroup reconnectWorkers, com.google.common.base.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 connectionbootstrap
- Configuration for new channels.timer
- Timer used for delayed reconnect.reconnectWorkers
- executor group for reconnect tasks.socketAddressSupplier
- the socket address suplier for gaining an address to reconnect topublic 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.@Deprecated public void setReconnect(boolean reconnect)
setListenOnChannelInactive(boolean)
reconnect
- true if reconnect is activepublic void setListenOnChannelInactive(boolean listenOnChannelInactive)
public boolean isListenOnChannelInactive()
public boolean isReconnectSuspended()
public void setReconnectSuspended(boolean reconnectSuspended)
Copyright © 2016. All rights reserved.