Fixed a bug in the uptime example where uptime is reset even when it
shouldn't be.
This commit is contained in:
parent
aca290096b
commit
45a4b5b7c4
@ -24,6 +24,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
|
|||||||
import org.jboss.netty.channel.ChannelStateEvent;
|
import org.jboss.netty.channel.ChannelStateEvent;
|
||||||
import org.jboss.netty.channel.ExceptionEvent;
|
import org.jboss.netty.channel.ExceptionEvent;
|
||||||
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
|
import org.jboss.netty.handler.timeout.ReadTimeoutException;
|
||||||
import org.jboss.netty.util.Timeout;
|
import org.jboss.netty.util.Timeout;
|
||||||
import org.jboss.netty.util.Timer;
|
import org.jboss.netty.util.Timer;
|
||||||
import org.jboss.netty.util.TimerTask;
|
import org.jboss.netty.util.TimerTask;
|
||||||
@ -39,9 +40,11 @@ import org.jboss.netty.util.TimerTask;
|
|||||||
*/
|
*/
|
||||||
public class UptimeClientHandler extends SimpleChannelUpstreamHandler {
|
public class UptimeClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
// We assume that we are tracking only one server in this example.
|
||||||
|
private static long startTime = -1;
|
||||||
|
|
||||||
final ClientBootstrap bootstrap;
|
final ClientBootstrap bootstrap;
|
||||||
private final Timer timer;
|
private final Timer timer;
|
||||||
private long startTime = -1;
|
|
||||||
|
|
||||||
public UptimeClientHandler(ClientBootstrap bootstrap, Timer timer) {
|
public UptimeClientHandler(ClientBootstrap bootstrap, Timer timer) {
|
||||||
this.bootstrap = bootstrap;
|
this.bootstrap = bootstrap;
|
||||||
@ -85,6 +88,13 @@ public class UptimeClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
startTime = -1;
|
startTime = -1;
|
||||||
println("Failed to connect: " + cause.getMessage());
|
println("Failed to connect: " + cause.getMessage());
|
||||||
}
|
}
|
||||||
|
if (cause instanceof ReadTimeoutException) {
|
||||||
|
// The connection was OK but there was no traffic for last period.
|
||||||
|
println("Disconnecting due to no inbound traffic");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cause.printStackTrace();
|
||||||
|
}
|
||||||
ctx.getChannel().close();
|
ctx.getChannel().close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user