Remove confusing ChannelState/OperationHandlerAdapter.inboundBufferUpdated/flush() implementation

This commit is contained in:
Trustin Lee 2013-02-08 17:17:39 +09:00
parent d385cba41c
commit b4eaedf712
8 changed files with 35 additions and 63 deletions

View File

@ -152,6 +152,11 @@ public class ChunkedWriteHandler
}
}
@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
ctx.fireInboundBufferUpdated();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
doFlush(ctx);

View File

@ -107,14 +107,12 @@ public class WriteTimeoutHandler extends ChannelOperationHandlerAdapter {
@Override
public void flush(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception {
scheduleTimeout(ctx, promise);
super.flush(ctx, promise);
ctx.flush(promise);
}
@Override
public void sendFile(ChannelHandlerContext ctx, FileRegion region, ChannelPromise promise) throws Exception {
scheduleTimeout(ctx, promise);
super.sendFile(ctx, region, promise);
}

View File

@ -91,26 +91,6 @@ public abstract class ChannelDuplexHandler extends ChannelStateHandlerAdapter im
ctx.read();
}
/**
* Calls {@link ChannelHandlerContext#flush(ChannelPromise)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*
* Be aware that if your class also implement {@link ChannelOutboundHandler} it need to {@code @Override} this
* method and provide some proper implementation. Fail to do so, will result in an {@link IllegalStateException}!
*/
@Override
public void flush(ChannelHandlerContext ctx, ChannelPromise future)
throws Exception {
if (this instanceof ChannelOutboundHandler) {
throw new IllegalStateException(
"flush(...) must be overridden by " + getClass().getName() +
", which implements " + ChannelOutboundHandler.class.getSimpleName());
}
ctx.flush(future);
}
/**
* Calls {@link ChannelHandlerContext#sendFile(FileRegion, ChannelPromise)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.

View File

@ -83,4 +83,9 @@ public abstract class ChannelInitializer<C extends Channel> extends ChannelState
}
}
}
@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
ctx.fireInboundBufferUpdated();
}
}

View File

@ -84,26 +84,6 @@ public abstract class ChannelOperationHandlerAdapter extends ChannelHandlerAdapt
ctx.read();
}
/**
* Calls {@link ChannelHandlerContext#flush(ChannelPromise)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*
* Be aware that if your class also implement {@link ChannelOutboundHandler} it need to {@code override} this
* method!
*/
@Override
public void flush(ChannelHandlerContext ctx, ChannelPromise promise)
throws Exception {
if (this instanceof ChannelOutboundHandler) {
throw new IllegalStateException(
"flush(...) must be overridden by " + getClass().getName() +
", which implements " + ChannelOutboundHandler.class.getSimpleName());
}
ctx.flush(promise);
}
/**
* Calls {@link ChannelHandlerContext#sendFile(FileRegion, ChannelPromise)} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.

View File

@ -69,25 +69,6 @@ public abstract class ChannelStateHandlerAdapter extends ChannelHandlerAdapter i
ctx.fireChannelInactive();
}
/**
* Calls {@link ChannelHandlerContext#fireInboundBufferUpdated()} to forward
* to the next {@link ChannelOperationHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*
* Be aware that if your class also implement {@link ChannelInboundHandler} it need to {@code @Override} this
* method and provide some proper implementation. Fail to do so, will result in an {@link IllegalStateException}!
*/
@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
if (this instanceof ChannelInboundHandler) {
throw new IllegalStateException(
"inboundBufferUpdated(...) must be overridden by " + getClass().getName() +
", which implements " + ChannelInboundHandler.class.getSimpleName());
}
ctx.fireInboundBufferUpdated();
}
@Override
public void channelReadSuspended(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadSuspended();

View File

@ -60,11 +60,26 @@ public abstract class AbstractEventLoopTest {
}
private static final class TestChannelHandler extends ChannelDuplexHandler {
@Override
public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.flush(promise);
}
@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
ctx.fireInboundBufferUpdated();
}
}
private static final class TestChannelHandler2 extends ChannelDuplexHandler {
@Override
public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.flush(promise);
}
@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
}
}
protected abstract EventLoopGroup newEventLoopGroup();

View File

@ -328,6 +328,14 @@ public class DefaultChannelPipelineTest {
@Sharable
private static class TestHandler extends ChannelDuplexHandler {
// Dummy
@Override
public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.flush(promise);
}
@Override
public void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception {
ctx.fireInboundBufferUpdated();
}
}
}