* Renamed the callback methods for Read/WriteTimeoutHandler

* More convenient exception handling
This commit is contained in:
Trustin Lee 2009-02-12 15:41:58 +00:00
parent b06e33f5ee
commit b49f8d8353
2 changed files with 22 additions and 10 deletions

View File

@ -22,6 +22,8 @@
*/
package org.jboss.netty.handler.timeout;
import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.ChannelHandlerContext;
@ -122,6 +124,10 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler implements
task = null;
}
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception {
Channels.fireExceptionCaught(ctx, EXCEPTION);
}
private final class ReadTimeoutTask implements TimerTask {
private final ChannelHandlerContext ctx;
@ -145,7 +151,11 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler implements
// Read timed out - set a new timeout and notify the callback.
ReadTimeoutHandler.this.timeout =
timer.newTimeout(this, timeoutMillis, TimeUnit.MILLISECONDS);
onReadTimeout(ctx);
try {
readTimedOut(ctx);
} catch (Throwable t) {
fireExceptionCaught(ctx, t);
}
} else {
// Read occurred before the timeout - set a new timeout with shorter delay.
ReadTimeoutHandler.this.timeout =
@ -153,8 +163,4 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler implements
}
}
}
protected void onReadTimeout(ChannelHandlerContext ctx) {
Channels.fireExceptionCaught(ctx, EXCEPTION);
}
}

View File

@ -22,6 +22,8 @@
*/
package org.jboss.netty.handler.timeout;
import static org.jboss.netty.channel.Channels.*;
import java.util.concurrent.TimeUnit;
import org.jboss.netty.channel.ChannelFuture;
@ -92,6 +94,10 @@ public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler implemen
super.writeRequested(ctx, e);
}
protected void writeTimedOut(ChannelHandlerContext ctx) throws Exception {
Channels.fireExceptionCaught(ctx, EXCEPTION);
}
private final class WriteTimeoutTask implements TimerTask {
private final ChannelHandlerContext ctx;
@ -114,12 +120,12 @@ public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler implemen
// Mark the future as failure
if (future.setFailure(EXCEPTION)) {
// If succeeded to mark as failure, notify the pipeline, too.
onWriteTimeout(ctx);
try {
writeTimedOut(ctx);
} catch (Throwable t) {
fireExceptionCaught(ctx, t);
}
}
}
}
protected void onWriteTimeout(ChannelHandlerContext ctx) {
Channels.fireExceptionCaught(ctx, EXCEPTION);
}
}