Made sure all timeout and idle time can be disabled with the non-positive constructor parameters

This commit is contained in:
Trustin Lee 2009-02-11 09:38:24 +00:00
parent 665db38994
commit 84aa72a70f
3 changed files with 11 additions and 19 deletions

View File

@ -66,14 +66,6 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
if (unit == null) {
throw new NullPointerException("unit");
}
if (readerIdleTime < 0) {
throw new IllegalArgumentException(
"readerIdleTime must not be less than 0: " + readerIdleTime);
}
if (writerIdleTime < 0) {
throw new IllegalArgumentException(
"writerIdleTime must not be less than 0: " + writerIdleTime);
}
this.timer = timer;
readerIdleTimeMillis = unit.toMillis(readerIdleTime);
@ -134,8 +126,14 @@ public class IdlenessHandler extends SimpleChannelUpstreamHandler implements Lif
lastReadTime = lastWriteTime = System.currentTimeMillis();
readerIdleTimeoutTask = new ReaderIdleTimeoutTask(ctx);
writerIdleTimeoutTask = new WriterIdleTimeoutTask(ctx);
readerIdleTimeout = timer.newTimeout(readerIdleTimeoutTask, readerIdleTimeMillis, TimeUnit.MILLISECONDS);
writerIdleTimeout = timer.newTimeout(writerIdleTimeoutTask, writerIdleTimeMillis, TimeUnit.MILLISECONDS);
if (readerIdleTimeMillis > 0) {
readerIdleTimeout = timer.newTimeout(
readerIdleTimeoutTask, readerIdleTimeMillis, TimeUnit.MILLISECONDS);
}
if (writerIdleTimeMillis > 0) {
writerIdleTimeout = timer.newTimeout(
writerIdleTimeoutTask, writerIdleTimeMillis, TimeUnit.MILLISECONDS);
}
}
private void destroy() {

View File

@ -60,10 +60,6 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler implements
if (unit == null) {
throw new NullPointerException("unit");
}
if (timeout <= 0) {
throw new IllegalArgumentException(
"timeout must be greater than 0: " + timeout);
}
this.timer = timer;
timeoutMillis = unit.toMillis(timeout);
@ -113,7 +109,9 @@ public class ReadTimeoutHandler extends SimpleChannelUpstreamHandler implements
private void initialize(ChannelHandlerContext ctx) {
lastReadTime = System.currentTimeMillis();
task = new ReadTimeoutTask(ctx);
timeout = timer.newTimeout(task, timeoutMillis, TimeUnit.MILLISECONDS);
if (timeoutMillis > 0) {
timeout = timer.newTimeout(task, timeoutMillis, TimeUnit.MILLISECONDS);
}
}
private void destroy() {

View File

@ -57,10 +57,6 @@ public class WriteTimeoutHandler extends SimpleChannelDownstreamHandler implemen
if (unit == null) {
throw new NullPointerException("unit");
}
if (timeout < 0) {
throw new IllegalArgumentException(
"timeout must not be less than 0: " + timeout);
}
this.timer = timer;
timeoutMillis = unit.toMillis(timeout);