com.lambdaworks.redis.protocol
Class ConnectionWatchdog
java.lang.Object
org.jboss.netty.channel.SimpleChannelUpstreamHandler
com.lambdaworks.redis.protocol.ConnectionWatchdog
- All Implemented Interfaces:
- ChannelHandler, ChannelUpstreamHandler, TimerTask
public class ConnectionWatchdog
- extends SimpleChannelUpstreamHandler
- implements TimerTask
A netty ChannelHandler responsible for monitoring the channel and
reconnecting when the connection is lost.
- Author:
- Will Glozer
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ConnectionWatchdog
public ConnectionWatchdog(ClientBootstrap bootstrap,
ChannelGroup channels,
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.
- Parameters:
bootstrap - Configuration for new channels.channels - ChannelGroup to add new channels to.timer - Timer used for delayed reconnect.
setReconnect
public void setReconnect(boolean reconnect)
channelConnected
public void channelConnected(ChannelHandlerContext ctx,
ChannelStateEvent e)
throws Exception
- Overrides:
channelConnected in class SimpleChannelUpstreamHandler
- Throws:
Exception
channelClosed
public void channelClosed(ChannelHandlerContext ctx,
ChannelStateEvent e)
throws Exception
- Overrides:
channelClosed in class SimpleChannelUpstreamHandler
- Throws:
Exception
exceptionCaught
public void exceptionCaught(ChannelHandlerContext ctx,
ExceptionEvent e)
throws Exception
- Overrides:
exceptionCaught in class SimpleChannelUpstreamHandler
- Throws:
Exception
run
public void run(Timeout timeout)
throws Exception
- Reconnect to the remote address that the closed channel was connected to.
This creates a new
ChannelPipeline with the same handler instances
contained in the old channel's pipeline.
- Specified by:
run in interface TimerTask
- Parameters:
timeout - Timer task handle.
- Throws:
Exception - when reconnection fails.
Copyright © 2013. All Rights Reserved.