com.lambdaworks.redis.protocol
Class ConnectionWatchdog

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelUpstreamHandler
      extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
 
Constructor Summary
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.
 
Method Summary
 void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e)
           
 void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
           
 void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
           
 void run(Timeout timeout)
          Reconnect to the remote address that the closed channel was connected to.
 void setReconnect(boolean reconnect)
           
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, handleUpstream, messageReceived, writeComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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.
Method Detail

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.