Move methods from ChannelHandler to ChannelStateHandler like proposed in [#1107]

This commit is contained in:
Norman Maurer 2013-03-01 11:45:48 +01:00
parent 3ac78b030a
commit 1603d9792d
6 changed files with 47 additions and 49 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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 {