Skip to content

Commit

Permalink
Remove the distinction of inbound handlers and outbound handlers
Browse files Browse the repository at this point in the history
- Fixes #1808
- Move all methods in ChannelInboundHandler and ChannelOutboundHandler up to ChannelHandler
- Remove ChannelInboundHandler and ChannelOutboundHandler
- Deprecate ChannelInboundHandlerAdapter, ChannelOutboundHandlerAdapter, and ChannelDuplexHandler
- Replace CombinedChannelDuplexHandler with ChannelHandlerAppender
  because it's not possible to combine two handlers into one easily now
- Introduce 'Skip' annotation to pass events through efficiently
- Remove all references to the deprecated types and update Javadoc
  • Loading branch information
trustin committed Nov 27, 2013
1 parent 807d96e commit 110745b
Show file tree
Hide file tree
Showing 106 changed files with 1,101 additions and 1,104 deletions.
8 changes: 4 additions & 4 deletions buffer/src/main/java/io/netty/buffer/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@
* type.
* <pre>
* // The composite type is compatible with the component type.
* {@link ByteBuf} message = {@link Unpooled}.wrappedBuffer(header, body);
* {@link io.netty.buffer.ByteBuf} message = {@link io.netty.buffer.Unpooled}.wrappedBuffer(header, body);
*
* // Therefore, you can even create a composite by mixing a composite and an
* // ordinary buffer.
* {@link ByteBuf} messageWithFooter = {@link Unpooled}.wrappedBuffer(message, footer);
* {@link io.netty.buffer.ByteBuf} messageWithFooter = {@link io.netty.buffer.Unpooled}.wrappedBuffer(message, footer);
*
* // Because the composite is still a {@link ByteBuf}, you can access its content
* // Because the composite is still a {@link io.netty.buffer.ByteBuf}, you can access its content
* // easily, and the accessor method will behave just like it's a single buffer
* // even if the region you want to access spans over multiple components. The
* // unsigned integer being read here is located across body and footer.
Expand All @@ -100,7 +100,7 @@
* <pre>
* // A new dynamic buffer is created. Internally, the actual buffer is created
* // lazily to avoid potentially wasted memory space.
* {@link ByteBuf} b = {@link Unpooled}.buffer(4);
* {@link io.netty.buffer.ByteBuf} b = {@link io.netty.buffer.Unpooled}.buffer(4);
*
* // When the first write attempt is made, the internal buffer is created with
* // the specified initial capacity (4).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.CombinedChannelDuplexHandler;
import io.netty.channel.ChannelHandlerAppender;
import io.netty.handler.codec.PrematureChannelClosureException;

import java.util.ArrayDeque;
Expand All @@ -40,8 +40,7 @@
*
* @see HttpServerCodec
*/
public final class HttpClientCodec
extends CombinedChannelDuplexHandler<HttpResponseDecoder, HttpRequestEncoder> {
public final class HttpClientCodec extends ChannelHandlerAppender {

/** A queue that is used for correlating a request and a response. */
private final Queue<HttpMethod> queue = new ArrayDeque<HttpMethod>();
Expand All @@ -61,14 +60,6 @@ public HttpClientCodec() {
this(4096, 8192, 8192, false);
}

public void setSingleDecode(boolean singleDecode) {
inboundHandler().setSingleDecode(singleDecode);
}

public boolean isSingleDecode() {
return inboundHandler().isSingleDecode();
}

/**
* Creates a new instance with the specified decoder options.
*/
Expand All @@ -90,10 +81,22 @@ public HttpClientCodec(
public HttpClientCodec(
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
boolean validateHeaders) {
init(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder());
add(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder());
this.failOnMissingResponse = failOnMissingResponse;
}

private Decoder decoder() {
return handlerAt(0);
}

public void setSingleDecode(boolean singleDecode) {
decoder().setSingleDecode(singleDecode);
}

public boolean isSingleDecode() {
return decoder().isSingleDecode();
}

private final class Encoder extends HttpRequestEncoder {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.netty.handler.codec.http;

import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;

import static io.netty.handler.codec.http.HttpConstants.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.netty.handler.codec.http;

import io.netty.channel.CombinedChannelDuplexHandler;
import io.netty.channel.ChannelHandlerAppender;


/**
Expand All @@ -24,8 +24,7 @@
*
* @see HttpClientCodec
*/
public final class HttpServerCodec
extends CombinedChannelDuplexHandler<HttpRequestDecoder, HttpResponseEncoder> {
public final class HttpServerCodec extends ChannelHandlerAppender {

/**
* Creates a new instance with the default decoder options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.netty.handler.codec.http.websocketx;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpHeaders;

Expand All @@ -34,7 +34,7 @@
* This implementation will establish the websocket connection once the connection to the remote server was complete.
*
* To know once a handshake was done you can intercept the
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
* {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
* {@link ClientHandshakeStateEvent#HANDSHAKE_ISSUED} or {@link ClientHandshakeStateEvent#HANDSHAKE_COMPLETE}.
*/
public class WebSocketClientProtocolHandler extends WebSocketProtocolHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpResponse;

class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {
class WebSocketClientProtocolHandshakeHandler extends ChannelHandlerAdapter {
private final WebSocketClientHandshaker handshaker;

public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/
package io.netty.handler.codec.http.websocketx;

import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;

/**
* Marker interface which all WebSocketFrame decoders need to implement.
*
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/
public interface WebSocketFrameDecoder extends ChannelInboundHandler {
}
public interface WebSocketFrameDecoder extends ChannelHandler { }
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package io.netty.handler.codec.http.websocketx;

import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline;

/**
* Marker interface which all WebSocketFrame encoders need to implement.
*
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/
public interface WebSocketFrameEncoder extends ChannelOutboundHandler {
public interface WebSocketFrameEncoder extends ChannelHandler {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
Expand All @@ -45,7 +44,7 @@
* to the <tt>io.netty.example.http.websocketx.server.WebSocketServer</tt> example.
*
* To know once a handshake was done you can intercept the
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
* {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
* {@link ServerHandshakeStateEvent#HANDSHAKE_COMPLETE}.
*/
public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
Expand Down Expand Up @@ -122,7 +121,7 @@ static void setHandshaker(ChannelHandlerContext ctx, WebSocketServerHandshaker h
}

static ChannelHandler forbiddenHttpRequestResponder() {
return new ChannelInboundHandlerAdapter() {
return new ChannelHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof FullHttpRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
Expand All @@ -35,8 +35,7 @@
/**
* Handles the HTTP handshake (the HTTP Upgrade request) for {@link WebSocketServerProtocolHandler}.
*/
class WebSocketServerProtocolHandshakeHandler
extends ChannelInboundHandlerAdapter {
class WebSocketServerProtocolHandshakeHandler extends ChannelHandlerAdapter {

private final String websocketPath;
private final String subprotocols;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package io.netty.handler.codec.spdy;

import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;

final class SpdyCodecUtil {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package io.netty.handler.codec.spdy;

import io.netty.channel.CombinedChannelDuplexHandler;
import io.netty.channel.ChannelHandlerAppender;

/**
* A combination of {@link SpdyFrameDecoder} and {@link SpdyFrameEncoder}.
*/
public final class SpdyFrameCodec extends CombinedChannelDuplexHandler<SpdyFrameDecoder, SpdyFrameEncoder> {
public final class SpdyFrameCodec extends ChannelHandlerAppender {
/**
* Creates a new instance with the specified {@code version} and
* the default decoder and encoder options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
*/
package io.netty.handler.codec.spdy;

import io.netty.channel.CombinedChannelDuplexHandler;
import io.netty.channel.ChannelHandlerAppender;

/**
* A combination of {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}
*/
public final class SpdyHttpCodec
extends CombinedChannelDuplexHandler<SpdyHttpDecoder, SpdyHttpEncoder> {
public final class SpdyHttpCodec extends ChannelHandlerAppender {
/**
* Creates a new instance with the specified decoder options.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.http.HttpObjectAggregator;
Expand All @@ -30,7 +29,7 @@
import java.util.List;

/**
* {@link ChannelInboundHandler} which is responsible to setup the {@link ChannelPipeline} either for
* {@link ChannelHandler} which is responsible to setup the {@link ChannelPipeline} either for
* HTTP or SPDY. This offers an easy way for users to support both at the same time while not care to
* much about the low-level details.
*/
Expand Down Expand Up @@ -125,21 +124,21 @@ protected void addHttpHandlers(ChannelHandlerContext ctx) {
}

/**
* Create the {@link ChannelInboundHandler} that is responsible for handling the http requests
* Create the {@link ChannelHandler} that is responsible for handling the http requests
* when the {@link SelectedProtocol} was {@link SelectedProtocol#HTTP_1_0} or
* {@link SelectedProtocol#HTTP_1_1}
*/
protected abstract ChannelInboundHandler createHttpRequestHandlerForHttp();
protected abstract ChannelHandler createHttpRequestHandlerForHttp();

/**
* Create the {@link ChannelInboundHandler} that is responsible for handling the http responses
* Create the {@link ChannelHandler} that is responsible for handling the http responses
* when the {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_3} or
* {@link SelectedProtocol#SPDY_3_1}.
*
* By default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but
* sub-classes may override this to change the behaviour.
*/
protected ChannelInboundHandler createHttpRequestHandlerForSpdy() {
protected ChannelHandler createHttpRequestHandlerForSpdy() {
return createHttpRequestHandlerForHttp();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
*/
package io.netty.handler.codec.spdy;

import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.util.internal.EmptyArrays;

import java.util.concurrent.atomic.AtomicInteger;

import static io.netty.handler.codec.spdy.SpdyCodecUtil.SPDY_SESSION_STREAM_ID;
import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;

/**
* Manages streams within a SPDY session.
*/
public class SpdySessionHandler
extends ChannelDuplexHandler {
public class SpdySessionHandler extends ChannelHandlerAdapter {

private static final SpdyProtocolException PROTOCOL_EXCEPTION = new SpdyProtocolException();
private static final SpdyProtocolException STREAM_CLOSED = new SpdyProtocolException("Stream closed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package io.netty.handler.codec.http.websocketx;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest;
Expand Down Expand Up @@ -143,7 +142,7 @@ private static String getResponseMessage(FullHttpResponse response) {
return new String(response.content().array());
}

private class MockOutboundHandler extends ChannelOutboundHandlerAdapter {
private class MockOutboundHandler extends ChannelHandlerAdapter {

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
Expand All @@ -156,7 +155,7 @@ public void flush(ChannelHandlerContext ctx) throws Exception {
}
}

private static class CustomTextFrameHandler extends ChannelInboundHandlerAdapter {
private static class CustomTextFrameHandler extends ChannelHandlerAdapter {
private String content;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
Expand Down Expand Up @@ -128,7 +128,7 @@ private static void addHeader(SpdyHeadersFrame frame, int headerNameSize, int he
frame.headers().add(headerName.toString(), headerValue.toString());
}

private static class CaptureHandler extends ChannelInboundHandlerAdapter {
private static class CaptureHandler extends ChannelHandlerAdapter {
public volatile Object message;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.netty.handler.codec.spdy;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
Expand Down Expand Up @@ -330,7 +330,7 @@ public void testSpdyServerSessionHandlerGoAway() {

// Echo Handler opens 4 half-closed streams on session connection
// and then sets the number of concurrent streams to 1
private static class EchoHandler extends ChannelInboundHandlerAdapter {
private static class EchoHandler extends ChannelHandlerAdapter {
private final int closeSignal;
private final boolean server;

Expand Down

3 comments on commit 110745b

@normanmaurer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trustin can you make sure you also remove the private interfaces like we did in 4.0 ?

@trustin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@trustin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Please sign in to comment.