Skip to content

Commit 110745b

Browse files
committed
Remove the distinction of inbound handlers and outbound handlers
- Fixes netty#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
1 parent 807d96e commit 110745b

106 files changed

Lines changed: 1101 additions & 1104 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

buffer/src/main/java/io/netty/buffer/package-info.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@
7575
* type.
7676
* <pre>
7777
* // The composite type is compatible with the component type.
78-
* {@link ByteBuf} message = {@link Unpooled}.wrappedBuffer(header, body);
78+
* {@link io.netty.buffer.ByteBuf} message = {@link io.netty.buffer.Unpooled}.wrappedBuffer(header, body);
7979
*
8080
* // Therefore, you can even create a composite by mixing a composite and an
8181
* // ordinary buffer.
82-
* {@link ByteBuf} messageWithFooter = {@link Unpooled}.wrappedBuffer(message, footer);
82+
* {@link io.netty.buffer.ByteBuf} messageWithFooter = {@link io.netty.buffer.Unpooled}.wrappedBuffer(message, footer);
8383
*
84-
* // Because the composite is still a {@link ByteBuf}, you can access its content
84+
* // Because the composite is still a {@link io.netty.buffer.ByteBuf}, you can access its content
8585
* // easily, and the accessor method will behave just like it's a single buffer
8686
* // even if the region you want to access spans over multiple components. The
8787
* // unsigned integer being read here is located across body and footer.
@@ -100,7 +100,7 @@
100100
* <pre>
101101
* // A new dynamic buffer is created. Internally, the actual buffer is created
102102
* // lazily to avoid potentially wasted memory space.
103-
* {@link ByteBuf} b = {@link Unpooled}.buffer(4);
103+
* {@link io.netty.buffer.ByteBuf} b = {@link io.netty.buffer.Unpooled}.buffer(4);
104104
*
105105
* // When the first write attempt is made, the internal buffer is created with
106106
* // the specified initial capacity (4).

codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.channel.Channel;
2020
import io.netty.channel.ChannelHandlerContext;
21-
import io.netty.channel.CombinedChannelDuplexHandler;
21+
import io.netty.channel.ChannelHandlerAppender;
2222
import io.netty.handler.codec.PrematureChannelClosureException;
2323

2424
import java.util.ArrayDeque;
@@ -40,8 +40,7 @@
4040
*
4141
* @see HttpServerCodec
4242
*/
43-
public final class HttpClientCodec
44-
extends CombinedChannelDuplexHandler<HttpResponseDecoder, HttpRequestEncoder> {
43+
public final class HttpClientCodec extends ChannelHandlerAppender {
4544

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

64-
public void setSingleDecode(boolean singleDecode) {
65-
inboundHandler().setSingleDecode(singleDecode);
66-
}
67-
68-
public boolean isSingleDecode() {
69-
return inboundHandler().isSingleDecode();
70-
}
71-
7263
/**
7364
* Creates a new instance with the specified decoder options.
7465
*/
@@ -90,10 +81,22 @@ public HttpClientCodec(
9081
public HttpClientCodec(
9182
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
9283
boolean validateHeaders) {
93-
init(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder());
84+
add(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder());
9485
this.failOnMissingResponse = failOnMissingResponse;
9586
}
9687

88+
private Decoder decoder() {
89+
return handlerAt(0);
90+
}
91+
92+
public void setSingleDecode(boolean singleDecode) {
93+
decoder().setSingleDecode(singleDecode);
94+
}
95+
96+
public boolean isSingleDecode() {
97+
return decoder().isSingleDecode();
98+
}
99+
97100
private final class Encoder extends HttpRequestEncoder {
98101

99102
@Override

codec-http/src/main/java/io/netty/handler/codec/http/HttpResponseEncoder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package io.netty.handler.codec.http;
1717

1818
import io.netty.buffer.ByteBuf;
19-
import io.netty.util.CharsetUtil;
2019

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

codec-http/src/main/java/io/netty/handler/codec/http/HttpServerCodec.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.netty.handler.codec.http;
1717

18-
import io.netty.channel.CombinedChannelDuplexHandler;
18+
import io.netty.channel.ChannelHandlerAppender;
1919

2020

2121
/**
@@ -24,8 +24,7 @@
2424
*
2525
* @see HttpClientCodec
2626
*/
27-
public final class HttpServerCodec
28-
extends CombinedChannelDuplexHandler<HttpRequestDecoder, HttpResponseEncoder> {
27+
public final class HttpServerCodec extends ChannelHandlerAppender {
2928

3029
/**
3130
* Creates a new instance with the default decoder options

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package io.netty.handler.codec.http.websocketx;
1717

18+
import io.netty.channel.ChannelHandler;
1819
import io.netty.channel.ChannelHandlerContext;
19-
import io.netty.channel.ChannelInboundHandler;
2020
import io.netty.channel.ChannelPipeline;
2121
import io.netty.handler.codec.http.HttpHeaders;
2222

@@ -34,7 +34,7 @@
3434
* This implementation will establish the websocket connection once the connection to the remote server was complete.
3535
*
3636
* To know once a handshake was done you can intercept the
37-
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
37+
* {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
3838
* {@link ClientHandshakeStateEvent#HANDSHAKE_ISSUED} or {@link ClientHandshakeStateEvent#HANDSHAKE_COMPLETE}.
3939
*/
4040
public class WebSocketClientProtocolHandler extends WebSocketProtocolHandler {

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientProtocolHandshakeHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
import io.netty.channel.ChannelFuture;
1919
import io.netty.channel.ChannelFutureListener;
20+
import io.netty.channel.ChannelHandlerAdapter;
2021
import io.netty.channel.ChannelHandlerContext;
21-
import io.netty.channel.ChannelInboundHandlerAdapter;
2222
import io.netty.handler.codec.http.FullHttpResponse;
2323

24-
class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {
24+
class WebSocketClientProtocolHandshakeHandler extends ChannelHandlerAdapter {
2525
private final WebSocketClientHandshaker handshaker;
2626

2727
public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) {

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrameDecoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
*/
1616
package io.netty.handler.codec.http.websocketx;
1717

18-
import io.netty.channel.ChannelInboundHandler;
18+
import io.netty.channel.ChannelHandler;
1919
import io.netty.channel.ChannelPipeline;
2020

2121
/**
2222
* Marker interface which all WebSocketFrame decoders need to implement.
2323
*
2424
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
2525
*/
26-
public interface WebSocketFrameDecoder extends ChannelInboundHandler {
27-
}
26+
public interface WebSocketFrameDecoder extends ChannelHandler { }

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketFrameEncoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
*/
1616
package io.netty.handler.codec.http.websocketx;
1717

18-
import io.netty.channel.ChannelOutboundHandler;
18+
import io.netty.channel.ChannelHandler;
1919
import io.netty.channel.ChannelPipeline;
2020

2121
/**
2222
* Marker interface which all WebSocketFrame encoders need to implement.
2323
*
2424
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
2525
*/
26-
public interface WebSocketFrameEncoder extends ChannelOutboundHandler {
26+
public interface WebSocketFrameEncoder extends ChannelHandler {
2727
}

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
import io.netty.buffer.Unpooled;
1919
import io.netty.channel.ChannelFutureListener;
2020
import io.netty.channel.ChannelHandler;
21+
import io.netty.channel.ChannelHandlerAdapter;
2122
import io.netty.channel.ChannelHandlerContext;
22-
import io.netty.channel.ChannelInboundHandler;
23-
import io.netty.channel.ChannelInboundHandlerAdapter;
2423
import io.netty.channel.ChannelPipeline;
2524
import io.netty.handler.codec.http.DefaultFullHttpResponse;
2625
import io.netty.handler.codec.http.FullHttpRequest;
@@ -45,7 +44,7 @@
4544
* to the <tt>io.netty.example.http.websocketx.server.WebSocketServer</tt> example.
4645
*
4746
* To know once a handshake was done you can intercept the
48-
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
47+
* {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} and check if the event was of type
4948
* {@link ServerHandshakeStateEvent#HANDSHAKE_COMPLETE}.
5049
*/
5150
public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
@@ -122,7 +121,7 @@ static void setHandshaker(ChannelHandlerContext ctx, WebSocketServerHandshaker h
122121
}
123122

124123
static ChannelHandler forbiddenHttpRequestResponder() {
125-
return new ChannelInboundHandlerAdapter() {
124+
return new ChannelHandlerAdapter() {
126125
@Override
127126
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
128127
if (msg instanceof FullHttpRequest) {

codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandshakeHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import io.netty.channel.ChannelFuture;
1919
import io.netty.channel.ChannelFutureListener;
20+
import io.netty.channel.ChannelHandlerAdapter;
2021
import io.netty.channel.ChannelHandlerContext;
21-
import io.netty.channel.ChannelInboundHandlerAdapter;
2222
import io.netty.channel.ChannelPipeline;
2323
import io.netty.handler.codec.http.DefaultFullHttpResponse;
2424
import io.netty.handler.codec.http.FullHttpRequest;
@@ -35,8 +35,7 @@
3535
/**
3636
* Handles the HTTP handshake (the HTTP Upgrade request) for {@link WebSocketServerProtocolHandler}.
3737
*/
38-
class WebSocketServerProtocolHandshakeHandler
39-
extends ChannelInboundHandlerAdapter {
38+
class WebSocketServerProtocolHandshakeHandler extends ChannelHandlerAdapter {
4039

4140
private final String websocketPath;
4241
private final String subprotocols;

0 commit comments

Comments
 (0)