Implemented both idleness event roughly (needs some fix)

This commit is contained in:
Trustin Lee 2009-02-12 11:03:10 +00:00
parent ed69d8bc15
commit 2c3e7565fa
2 changed files with 64 additions and 8 deletions

View File

@ -0,0 +1,44 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.handler.timeout;
import org.jboss.netty.channel.Channel;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev: 861 $, $Date: 2009-02-12 19:50:43 +0900 (Thu, 12 Feb 2009) $
*/
public class DefaultReaderAndWriterIdlenessEvent extends DefaultIdlenessEvent
implements ReaderIdlenessEvent,
WriterIdlenessEvent {
public DefaultReaderAndWriterIdlenessEvent(Channel channel) {
super(channel);
}
@Override
public String toString() {
return getChannel().toString() + " - (IDLE: READER & WRITER)";
}
}

View File

@ -149,6 +149,18 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
writerIdleTimeoutTask = null;
}
protected void onReaderIdleness(ChannelHandlerContext ctx) {
ctx.sendUpstream(new DefaultReaderIdlenessEvent(ctx.getChannel()));
}
protected void onWriterIdleness(ChannelHandlerContext ctx) {
ctx.sendUpstream(new DefaultWriterIdlenessEvent(ctx.getChannel()));
}
protected void onReaderAndWriterIdleness(ChannelHandlerContext ctx) {
ctx.sendUpstream(new DefaultReaderAndWriterIdlenessEvent(ctx.getChannel()));
}
private final class ReaderIdleTimeoutTask implements TimerTask {
private final ChannelHandlerContext ctx;
@ -174,6 +186,10 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
readerIdleTimeout =
timer.newTimeout(this, readerIdleTimeMillis, TimeUnit.MILLISECONDS);
onReaderIdleness(ctx);
if (currentTime - lastWriteTime >= writerIdleTimeMillis) {
// FIXME: Suppress double fire
onReaderAndWriterIdleness(ctx);
}
} else {
// Read occurred before the timeout - set a new timeout with shorter delay.
readerIdleTimeout =
@ -183,10 +199,6 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
}
protected void onReaderIdleness(ChannelHandlerContext ctx) {
ctx.sendUpstream(new DefaultReaderIdlenessEvent(ctx.getChannel()));
}
private final class WriterIdleTimeoutTask implements TimerTask {
private final ChannelHandlerContext ctx;
@ -212,6 +224,10 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
writerIdleTimeout =
timer.newTimeout(this, writerIdleTimeMillis, TimeUnit.MILLISECONDS);
onWriterIdleness(ctx);
if (currentTime - lastReadTime >= readerIdleTimeMillis) {
// FIXME: Suppress double fire
onReaderAndWriterIdleness(ctx);
}
} else {
// Write occurred before the timeout - set a new timeout with shorter delay.
writerIdleTimeout =
@ -219,8 +235,4 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
}
}
}
protected void onWriterIdleness(ChannelHandlerContext ctx) {
ctx.sendUpstream(new DefaultWriterIdlenessEvent(ctx.getChannel()));
}
}