diff --git a/transport/src/main/java/io/netty/channel/ChannelHandler.java b/transport/src/main/java/io/netty/channel/ChannelHandler.java index b08136519f..3604c5903e 100644 --- a/transport/src/main/java/io/netty/channel/ChannelHandler.java +++ b/transport/src/main/java/io/netty/channel/ChannelHandler.java @@ -209,16 +209,6 @@ public interface ChannelHandler { */ void afterRemove(ChannelHandlerContext ctx) throws Exception; - /** - * Gets called if a {@link Throwable} was thrown. - */ - void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception; - - /** - * Gets called if an user event was triggered. - */ - void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception; - /** * Indicates that the same instance of the annotated {@link ChannelHandler} * can be added to one or more {@link ChannelPipeline}s multiple times diff --git a/transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java index baede4d778..f1fd2070ab 100644 --- a/transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java +++ b/transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java @@ -60,28 +60,4 @@ public abstract class ChannelHandlerAdapter implements ChannelHandler { public void afterRemove(ChannelHandlerContext ctx) throws Exception { // NOOP } - - /** - * Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward - * to the next {@link ChannelHandler} in the {@link ChannelPipeline}. - * - * Sub-classes may override this method to change behavior. - */ - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) - throws Exception { - ctx.fireExceptionCaught(cause); - } - - /** - * Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward - * to the next {@link ChannelHandler} in the {@link ChannelPipeline}. - * - * Sub-classes may override this method to change behavior. - */ - @Override - public void userEventTriggered(ChannelHandlerContext ctx, Object evt) - throws Exception { - ctx.fireUserEventTriggered(evt); - } } diff --git a/transport/src/main/java/io/netty/channel/ChannelStateHandler.java b/transport/src/main/java/io/netty/channel/ChannelStateHandler.java index 9dd41b6ac9..857cc331b6 100755 --- a/transport/src/main/java/io/netty/channel/ChannelStateHandler.java +++ b/transport/src/main/java/io/netty/channel/ChannelStateHandler.java @@ -55,4 +55,14 @@ public interface ChannelStateHandler extends ChannelHandler { * to wait for more data and consume it later. */ void inboundBufferUpdated(ChannelHandlerContext ctx) throws Exception; + + /** + * Gets called if a {@link Throwable} was thrown. + */ + void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception; + + /** + * Gets called if an user event was triggered. + */ + void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception; } diff --git a/transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java b/transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java index d0ea42d077..28e1dc5465 100644 --- a/transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java +++ b/transport/src/main/java/io/netty/channel/ChannelStateHandlerAdapter.java @@ -68,9 +68,38 @@ public abstract class ChannelStateHandlerAdapter extends ChannelHandlerAdapter i public void channelInactive(ChannelHandlerContext ctx) throws Exception { ctx.fireChannelInactive(); } - + /** + * Calls {@link ChannelHandlerContext#fireChannelReadSuspended()} to forward + * to the next {@link ChannelHandler} in the {@link ChannelPipeline}. + * + * Sub-classes may override this method to change behavior. + */ @Override public void channelReadSuspended(ChannelHandlerContext ctx) throws Exception { ctx.fireChannelReadSuspended(); } + + /** + * Calls {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} to forward + * to the next {@link ChannelHandler} in the {@link ChannelPipeline}. + * + * Sub-classes may override this method to change behavior. + */ + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) + throws Exception { + ctx.fireExceptionCaught(cause); + } + + /** + * Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward + * to the next {@link ChannelHandler} in the {@link ChannelPipeline}. + * + * Sub-classes may override this method to change behavior. + */ + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) + throws Exception { + ctx.fireUserEventTriggered(evt); + } } diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java index 4a50f8b3e2..0759ccf019 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelHandlerContext.java @@ -812,7 +812,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements throw new NullPointerException("cause"); } - final DefaultChannelHandlerContext next = this.next; + final DefaultChannelHandlerContext next = findContextInbound(); EventExecutor executor = next.executor(); if (prev != null && executor.inEventLoop()) { next.invokeExceptionCaught(cause); @@ -835,8 +835,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } private void invokeExceptionCaught(Throwable cause) { + ChannelStateHandler handler = (ChannelStateHandler) handler(); try { - handler().exceptionCaught(this, cause); + handler.exceptionCaught(this, cause); } catch (Throwable t) { if (logger.isWarnEnabled()) { logger.warn( @@ -854,7 +855,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements throw new NullPointerException("event"); } - final DefaultChannelHandlerContext next = this.next; + final DefaultChannelHandlerContext next = findContextInbound(); EventExecutor executor = next.executor(); if (executor.inEventLoop()) { next.invokeUserEventTriggered(event); @@ -870,8 +871,10 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements } private void invokeUserEventTriggered(Object event) { + ChannelStateHandler handler = (ChannelStateHandler) handler(); + try { - handler().userEventTriggered(this, event); + handler.userEventTriggered(this, event); } catch (Throwable t) { pipeline.notifyHandlerException(t); } finally { diff --git a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java index 5c89400741..2449a804e2 100755 --- a/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java +++ b/transport/src/main/java/io/netty/channel/DefaultChannelPipeline.java @@ -1266,16 +1266,6 @@ final class DefaultChannelPipeline implements ChannelPipeline { unsafe.beginRead(); } - @Override - public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - ctx.fireExceptionCaught(cause); - } - - @Override - public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { - ctx.fireUserEventTriggered(evt); - } - @Override public final void sendFile( ChannelHandlerContext ctx, FileRegion region, ChannelPromise promise) throws Exception {