Skip to content

Commit

Permalink
Rename Passthrough to Skip / Skip the invocation of handlerAdded/Remo…
Browse files Browse the repository at this point in the history
…ved when annotated with Skip
  • Loading branch information
trustin committed Nov 22, 2013
1 parent 127a071 commit 7d8fd75
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 86 deletions.
32 changes: 22 additions & 10 deletions transport/src/main/java/io/netty/channel/ChannelHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,27 +331,39 @@ void connect(
}

/**
* Indicates that the annotated event handler methods in {@link ChannelHandler} will not be invoked while
* they traverses through the {@link ChannelPipeline}. This annotation is only useful when your handler method
* implementation simply passes the event through to the next handler, like the following:
* Indicates that the annotated event handler method in {@link ChannelHandler} will not be invoked by
* {@link ChannelPipeline}. This annotation is only useful when your handler method implementation
* only passes the event through to the next handler, like the following:
*
* <pre>
* {@code @Skip}
* {@code @Override}
* {@code @Passthrough}
* public void channelActive(ChannelHandlerContext ctx) {
* ctx.fireChannelActive(); // pass through to the next handler
* }</pre>
* public void channelActive({@link ChannelHandlerContext} ctx) {
* ctx.fireChannelActive(); // do nothing but passing through to the next handler
* }
* </pre>
*
* {@link #handlerAdded(ChannelHandlerContext)} and {@link #handlerRemoved(ChannelHandlerContext)} are not able to
* pass the event through to the next handler, so they must do nothing when annotated.
*
* <pre>
* {@code @Skip}
* {@code @Override}
* public void handlerAdded({@link ChannelHandlerContext} ctx) {
* // do nothing
* }
* </pre>
*
* <p>
* Note that this annotation is not {@linkplain Inherited inherited}. If you override a method annotated with
* {@link Passthrough}, it will not be skipped anymore. Similarly, you can override a method not annotated with
* {@link Passthrough} and simply pass the event through to the next handler, which reverses the behavior of the
* {@link Skip}, it will not be skipped anymore. Similarly, you can override a method not annotated with
* {@link Skip} and simply pass the event through to the next handler, which reverses the behavior of the
* supertype.
* </p>
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface Passthrough {
@interface Skip {
// no value
}
}
34 changes: 17 additions & 17 deletions transport/src/main/java/io/netty/channel/ChannelHandlerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public boolean isSharable() {
/**
* Do nothing by default, sub-classes may override this method.
*/
@Skip
@Override
@Passthrough
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
// NOOP
}

/**
* Do nothing by default, sub-classes may override this method.
*/
@Skip
@Override
@Passthrough
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
// NOOP
}
Expand All @@ -58,8 +58,8 @@ public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.fireExceptionCaught(cause);
}
Expand All @@ -70,8 +70,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelRegistered();
}
Expand All @@ -82,8 +82,8 @@ public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelActive();
}
Expand All @@ -94,8 +94,8 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelInactive();
}
Expand All @@ -106,8 +106,8 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ctx.fireChannelRead(msg);
}
Expand All @@ -118,8 +118,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
Expand All @@ -130,8 +130,8 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
ctx.fireUserEventTriggered(evt);
}
Expand All @@ -142,8 +142,8 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelWritabilityChanged();
}
Expand All @@ -154,8 +154,8 @@ public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exceptio
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception {
ctx.bind(localAddress, promise);
}
Expand All @@ -166,8 +166,8 @@ public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelP
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void connect(
ChannelHandlerContext ctx,
SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
Expand All @@ -180,8 +180,8 @@ public void connect(
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.disconnect(promise);
}
Expand All @@ -192,8 +192,8 @@ public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.close(promise);
}
Expand All @@ -204,8 +204,8 @@ public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exce
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void read(ChannelHandlerContext ctx) throws Exception {
ctx.read();
}
Expand All @@ -216,8 +216,8 @@ public void read(ChannelHandlerContext ctx) throws Exception {
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.write(msg, promise);
}
Expand All @@ -228,8 +228,8 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
@Passthrough
public void flush(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
Expand Down

0 comments on commit 7d8fd75

Please sign in to comment.