@ChannelHandler.Sharable
public class ConnectionWatchdog
extends io.netty.channel.ChannelInboundHandlerAdapter
ChannelHandler responsible for monitoring the channel and reconnecting when the connection is lost.| Constructor and Description |
|---|
ConnectionWatchdog(Delay reconnectDelay,
ClientOptions clientOptions,
io.netty.bootstrap.Bootstrap bootstrap,
io.netty.util.Timer timer,
io.netty.util.concurrent.EventExecutorGroup reconnectWorkers,
Mono<SocketAddress> socketAddressSupplier,
ReconnectionListener reconnectionListener,
ConnectionFacade connectionFacade,
EventBus eventBus,
Endpoint endpoint)
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) |
boolean |
isListenOnChannelInactive() |
boolean |
isReconnectSuspended() |
void |
run(int attempt)
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)
Enable event listener for disconnected events.
|
void |
setReconnectSuspended(boolean reconnectSuspended)
Suspend reconnection temporarily.
|
channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredensureNotSharable, handlerAdded, handlerRemoved, isSharablepublic ConnectionWatchdog(Delay reconnectDelay, ClientOptions clientOptions, io.netty.bootstrap.Bootstrap bootstrap, io.netty.util.Timer timer, io.netty.util.concurrent.EventExecutorGroup reconnectWorkers, Mono<SocketAddress> socketAddressSupplier, ReconnectionListener reconnectionListener, ConnectionFacade connectionFacade, EventBus eventBus, Endpoint endpoint)
ChannelGroup and establishes a new
Channel when disconnected, while reconnect is true. The socketAddressSupplier can supply the reconnect address.reconnectDelay - reconnect delay, must not be nullclientOptions - 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 nullreconnectionListener - the reconnection listener, must not be nullconnectionFacade - the connection facade, must not be nulleventBus - Event bus to emit reconnect events.endpoint - must not be nullpublic void channelActive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelActive in interface io.netty.channel.ChannelInboundHandlerchannelActive in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
channelInactive in interface io.netty.channel.ChannelInboundHandlerchannelInactive in class io.netty.channel.ChannelInboundHandlerAdapterExceptionpublic void scheduleReconnect()
public void run(int attempt)
throws Exception
ChannelPipeline with
the same handler instances contained in the old channel's pipeline.attempt - attempt counterException - when reconnection fails.public void setListenOnChannelInactive(boolean listenOnChannelInactive)
listenOnChannelInactive - true to listen for disconnected events.public boolean isListenOnChannelInactive()
public void setReconnectSuspended(boolean reconnectSuspended)
reconnectSuspended - true to suspend reconnectionpublic boolean isReconnectSuspended()
Copyright © 2024 lettuce.io. All rights reserved.