public class ConnectionWatchdog
extends org.jboss.netty.channel.SimpleChannelUpstreamHandler
implements org.jboss.netty.util.TimerTask
ChannelHandler responsible for monitoring the channel and
reconnecting when the connection is lost.| Modifier and Type | Field and Description |
|---|---|
private int |
attempts |
private org.jboss.netty.bootstrap.ClientBootstrap |
bootstrap |
private org.jboss.netty.channel.Channel |
channel |
private org.jboss.netty.channel.group.ChannelGroup |
channels |
private boolean |
reconnect |
private org.jboss.netty.util.Timer |
timer |
| Constructor and Description |
|---|
ConnectionWatchdog(org.jboss.netty.bootstrap.ClientBootstrap bootstrap,
org.jboss.netty.channel.group.ChannelGroup channels,
org.jboss.netty.util.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. |
| Modifier and Type | Method and Description |
|---|---|
void |
channelClosed(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e) |
void |
channelConnected(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e) |
void |
exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ExceptionEvent e) |
void |
run(org.jboss.netty.util.Timeout timeout)
Reconnect to the remote address that the closed channel was connected to.
|
void |
setReconnect(boolean reconnect) |
private org.jboss.netty.bootstrap.ClientBootstrap bootstrap
private org.jboss.netty.channel.Channel channel
private org.jboss.netty.channel.group.ChannelGroup channels
private org.jboss.netty.util.Timer timer
private boolean reconnect
private int attempts
public ConnectionWatchdog(org.jboss.netty.bootstrap.ClientBootstrap bootstrap,
org.jboss.netty.channel.group.ChannelGroup channels,
org.jboss.netty.util.Timer timer)
ChannelGroup
and establishes a new Channel when disconnected, while reconnect is true.bootstrap - Configuration for new channels.channels - ChannelGroup to add new channels to.timer - Timer used for delayed reconnect.public void setReconnect(boolean reconnect)
public void channelConnected(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e)
throws java.lang.Exception
channelConnected in class org.jboss.netty.channel.SimpleChannelUpstreamHandlerjava.lang.Exceptionpublic void channelClosed(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ChannelStateEvent e)
throws java.lang.Exception
channelClosed in class org.jboss.netty.channel.SimpleChannelUpstreamHandlerjava.lang.Exceptionpublic void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx,
org.jboss.netty.channel.ExceptionEvent e)
throws java.lang.Exception
exceptionCaught in class org.jboss.netty.channel.SimpleChannelUpstreamHandlerjava.lang.Exceptionpublic void run(org.jboss.netty.util.Timeout timeout)
throws java.lang.Exception
ChannelPipeline with the same handler instances
contained in the old channel's pipeline.run in interface org.jboss.netty.util.TimerTasktimeout - Timer task handle.java.lang.Exception - when reconnection fails.