Remove the distinction of inbound handlers and outbound handlers

- 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
This commit is contained in:
Trustin Lee 2013-11-22 19:34:27 +09:00
parent 807d96ed6c
commit 110745b0eb
106 changed files with 1101 additions and 1104 deletions

View File

@ -75,13 +75,13 @@
* type. * type.
* <pre> * <pre>
* // The composite type is compatible with the component type. * // 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 * // Therefore, you can even create a composite by mixing a composite and an
* // ordinary buffer. * // 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 * // 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 * // even if the region you want to access spans over multiple components. The
* // unsigned integer being read here is located across body and footer. * // unsigned integer being read here is located across body and footer.
@ -100,7 +100,7 @@
* <pre> * <pre>
* // A new dynamic buffer is created. Internally, the actual buffer is created * // A new dynamic buffer is created. Internally, the actual buffer is created
* // lazily to avoid potentially wasted memory space. * // 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 * // When the first write attempt is made, the internal buffer is created with
* // the specified initial capacity (4). * // the specified initial capacity (4).

View File

@ -18,7 +18,7 @@ package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.CombinedChannelDuplexHandler; import io.netty.channel.ChannelHandlerAppender;
import io.netty.handler.codec.PrematureChannelClosureException; import io.netty.handler.codec.PrematureChannelClosureException;
import java.util.ArrayDeque; import java.util.ArrayDeque;
@ -40,8 +40,7 @@ import java.util.concurrent.atomic.AtomicLong;
* *
* @see HttpServerCodec * @see HttpServerCodec
*/ */
public final class HttpClientCodec public final class HttpClientCodec extends ChannelHandlerAppender {
extends CombinedChannelDuplexHandler<HttpResponseDecoder, HttpRequestEncoder> {
/** A queue that is used for correlating a request and a response. */ /** A queue that is used for correlating a request and a response. */
private final Queue<HttpMethod> queue = new ArrayDeque<HttpMethod>(); private final Queue<HttpMethod> queue = new ArrayDeque<HttpMethod>();
@ -61,14 +60,6 @@ public final class HttpClientCodec
this(4096, 8192, 8192, false); 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. * Creates a new instance with the specified decoder options.
*/ */
@ -90,10 +81,22 @@ public final class HttpClientCodec
public HttpClientCodec( public HttpClientCodec(
int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse, int maxInitialLineLength, int maxHeaderSize, int maxChunkSize, boolean failOnMissingResponse,
boolean validateHeaders) { boolean validateHeaders) {
init(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder()); add(new Decoder(maxInitialLineLength, maxHeaderSize, maxChunkSize, validateHeaders), new Encoder());
this.failOnMissingResponse = failOnMissingResponse; 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 { private final class Encoder extends HttpRequestEncoder {
@Override @Override

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
import static io.netty.handler.codec.http.HttpConstants.*; import static io.netty.handler.codec.http.HttpConstants.*;

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http; package io.netty.handler.codec.http;
import io.netty.channel.CombinedChannelDuplexHandler; import io.netty.channel.ChannelHandlerAppender;
/** /**
@ -24,8 +24,7 @@ import io.netty.channel.CombinedChannelDuplexHandler;
* *
* @see HttpClientCodec * @see HttpClientCodec
*/ */
public final class HttpServerCodec public final class HttpServerCodec extends ChannelHandlerAppender {
extends CombinedChannelDuplexHandler<HttpRequestDecoder, HttpResponseEncoder> {
/** /**
* Creates a new instance with the default decoder options * Creates a new instance with the default decoder options

View File

@ -15,8 +15,8 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpHeaders;
@ -34,7 +34,7 @@ import java.util.List;
* This implementation will establish the websocket connection once the connection to the remote server was complete. * 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 * 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}. * {@link ClientHandshakeStateEvent#HANDSHAKE_ISSUED} or {@link ClientHandshakeStateEvent#HANDSHAKE_COMPLETE}.
*/ */
public class WebSocketClientProtocolHandler extends WebSocketProtocolHandler { public class WebSocketClientProtocolHandler extends WebSocketProtocolHandler {

View File

@ -17,11 +17,11 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse;
class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter { class WebSocketClientProtocolHandshakeHandler extends ChannelHandlerAdapter {
private final WebSocketClientHandshaker handshaker; private final WebSocketClientHandshaker handshaker;
public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) { public WebSocketClientProtocolHandshakeHandler(WebSocketClientHandshaker handshaker) {

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelInboundHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
/** /**
@ -23,5 +23,4 @@ import io.netty.channel.ChannelPipeline;
* *
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}. * This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/ */
public interface WebSocketFrameDecoder extends ChannelInboundHandler { public interface WebSocketFrameDecoder extends ChannelHandler { }
}

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelOutboundHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
/** /**
@ -23,5 +23,5 @@ import io.netty.channel.ChannelPipeline;
* *
* This makes it easier to access the added encoder later in the {@link ChannelPipeline}. * This makes it easier to access the added encoder later in the {@link ChannelPipeline}.
*/ */
public interface WebSocketFrameEncoder extends ChannelOutboundHandler { public interface WebSocketFrameEncoder extends ChannelHandler {
} }

View File

@ -18,9 +18,8 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest;
@ -45,7 +44,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
* to the <tt>io.netty.example.http.websocketx.server.WebSocketServer</tt> example. * to the <tt>io.netty.example.http.websocketx.server.WebSocketServer</tt> example.
* *
* To know once a handshake was done you can intercept the * 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}. * {@link ServerHandshakeStateEvent#HANDSHAKE_COMPLETE}.
*/ */
public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler { public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
@ -122,7 +121,7 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
} }
static ChannelHandler forbiddenHttpRequestResponder() { static ChannelHandler forbiddenHttpRequestResponder() {
return new ChannelInboundHandlerAdapter() { return new ChannelHandlerAdapter() {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof FullHttpRequest) { if (msg instanceof FullHttpRequest) {

View File

@ -17,8 +17,8 @@ package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest;
@ -35,8 +35,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
/** /**
* Handles the HTTP handshake (the HTTP Upgrade request) for {@link WebSocketServerProtocolHandler}. * Handles the HTTP handshake (the HTTP Upgrade request) for {@link WebSocketServerProtocolHandler}.
*/ */
class WebSocketServerProtocolHandshakeHandler class WebSocketServerProtocolHandshakeHandler extends ChannelHandlerAdapter {
extends ChannelInboundHandlerAdapter {
private final String websocketPath; private final String websocketPath;
private final String subprotocols; private final String subprotocols;

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.CharsetUtil;
final class SpdyCodecUtil { final class SpdyCodecUtil {

View File

@ -15,12 +15,12 @@
*/ */
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.CombinedChannelDuplexHandler; import io.netty.channel.ChannelHandlerAppender;
/** /**
* A combination of {@link SpdyFrameDecoder} and {@link SpdyFrameEncoder}. * 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 * Creates a new instance with the specified {@code version} and
* the default decoder and encoder options * the default decoder and encoder options

View File

@ -15,13 +15,12 @@
*/ */
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.CombinedChannelDuplexHandler; import io.netty.channel.ChannelHandlerAppender;
/** /**
* A combination of {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder} * A combination of {@link SpdyHttpDecoder} and {@link SpdyHttpEncoder}
*/ */
public final class SpdyHttpCodec public final class SpdyHttpCodec extends ChannelHandlerAppender {
extends CombinedChannelDuplexHandler<SpdyHttpDecoder, SpdyHttpEncoder> {
/** /**
* Creates a new instance with the specified decoder options. * Creates a new instance with the specified decoder options.
*/ */

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.spdy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpObjectAggregator;
@ -30,7 +29,7 @@ import javax.net.ssl.SSLEngine;
import java.util.List; 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 * 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. * much about the low-level details.
*/ */
@ -125,21 +124,21 @@ public abstract class SpdyOrHttpChooser extends ByteToMessageDecoder {
} }
/** /**
* 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 * when the {@link SelectedProtocol} was {@link SelectedProtocol#HTTP_1_0} or
* {@link SelectedProtocol#HTTP_1_1} * {@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 * when the {@link SelectedProtocol} was {@link SelectedProtocol#SPDY_3} or
* {@link SelectedProtocol#SPDY_3_1}. * {@link SelectedProtocol#SPDY_3_1}.
* *
* By default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but * By default this getMethod will just delecate to {@link #createHttpRequestHandlerForHttp()}, but
* sub-classes may override this to change the behaviour. * sub-classes may override this to change the behaviour.
*/ */
protected ChannelInboundHandler createHttpRequestHandlerForSpdy() { protected ChannelHandler createHttpRequestHandlerForSpdy() {
return createHttpRequestHandlerForHttp(); return createHttpRequestHandlerForHttp();
} }
} }

View File

@ -15,22 +15,21 @@
*/ */
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.internal.EmptyArrays; import io.netty.util.internal.EmptyArrays;
import java.util.concurrent.atomic.AtomicInteger; 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. * Manages streams within a SPDY session.
*/ */
public class SpdySessionHandler public class SpdySessionHandler extends ChannelHandlerAdapter {
extends ChannelDuplexHandler {
private static final SpdyProtocolException PROTOCOL_EXCEPTION = new SpdyProtocolException(); private static final SpdyProtocolException PROTOCOL_EXCEPTION = new SpdyProtocolException();
private static final SpdyProtocolException STREAM_CLOSED = new SpdyProtocolException("Stream closed"); private static final SpdyProtocolException STREAM_CLOSED = new SpdyProtocolException("Stream closed");

View File

@ -16,9 +16,8 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultFullHttpRequest;
@ -143,7 +142,7 @@ public class WebSocketServerProtocolHandlerTest {
return new String(response.content().array()); return new String(response.content().array());
} }
private class MockOutboundHandler extends ChannelOutboundHandlerAdapter { private class MockOutboundHandler extends ChannelHandlerAdapter {
@Override @Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
@ -156,7 +155,7 @@ public class WebSocketServerProtocolHandlerTest {
} }
} }
private static class CustomTextFrameHandler extends ChannelInboundHandlerAdapter { private static class CustomTextFrameHandler extends ChannelHandlerAdapter {
private String content; private String content;
@Override @Override

View File

@ -18,8 +18,8 @@ package io.netty.handler.codec.spdy;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
@ -128,7 +128,7 @@ public class SpdyFrameDecoderTest {
frame.headers().add(headerName.toString(), headerValue.toString()); frame.headers().add(headerName.toString(), headerValue.toString());
} }
private static class CaptureHandler extends ChannelInboundHandlerAdapter { private static class CaptureHandler extends ChannelHandlerAdapter {
public volatile Object message; public volatile Object message;
@Override @Override

View File

@ -15,8 +15,8 @@
*/ */
package io.netty.handler.codec.spdy; package io.netty.handler.codec.spdy;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -330,7 +330,7 @@ public class SpdySessionHandlerTest {
// Echo Handler opens 4 half-closed streams on session connection // Echo Handler opens 4 half-closed streams on session connection
// and then sets the number of concurrent streams to 1 // 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 int closeSignal;
private final boolean server; private final boolean server;

View File

@ -17,7 +17,7 @@ package io.netty.handler.codec.memcache.binary;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.CombinedChannelDuplexHandler; import io.netty.channel.ChannelHandlerAppender;
import io.netty.handler.codec.PrematureChannelClosureException; import io.netty.handler.codec.PrematureChannelClosureException;
import io.netty.handler.codec.memcache.LastMemcacheContent; import io.netty.handler.codec.memcache.LastMemcacheContent;
@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicLong;
* will be passed up the pipeline and not queued up to the chunk size. * will be passed up the pipeline and not queued up to the chunk size.
*/ */
public final class BinaryMemcacheClientCodec public final class BinaryMemcacheClientCodec
extends CombinedChannelDuplexHandler<BinaryMemcacheResponseDecoder, BinaryMemcacheRequestEncoder> { extends ChannelHandlerAppender {
private final boolean failOnMissingResponse; private final boolean failOnMissingResponse;
private final AtomicLong requestResponseCounter = new AtomicLong(); private final AtomicLong requestResponseCounter = new AtomicLong();
@ -65,7 +65,7 @@ public final class BinaryMemcacheClientCodec
*/ */
public BinaryMemcacheClientCodec(int decodeChunkSize, boolean failOnMissingResponse) { public BinaryMemcacheClientCodec(int decodeChunkSize, boolean failOnMissingResponse) {
this.failOnMissingResponse = failOnMissingResponse; this.failOnMissingResponse = failOnMissingResponse;
init(new Decoder(decodeChunkSize), new Encoder()); add(new Decoder(decodeChunkSize), new Encoder());
} }
private final class Encoder extends BinaryMemcacheRequestEncoder { private final class Encoder extends BinaryMemcacheRequestEncoder {
@ -116,5 +116,4 @@ public final class BinaryMemcacheClientCodec
} }
} }
} }
} }

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec.memcache.binary; package io.netty.handler.codec.memcache.binary;
import io.netty.channel.CombinedChannelDuplexHandler; import io.netty.channel.ChannelHandlerAppender;
/** /**
* The full server codec that combines the correct encoder and decoder. * The full server codec that combines the correct encoder and decoder.
@ -24,14 +24,13 @@ import io.netty.channel.CombinedChannelDuplexHandler;
* Internally, it combines the {@link BinaryMemcacheRequestDecoder} and the * Internally, it combines the {@link BinaryMemcacheRequestDecoder} and the
* {@link BinaryMemcacheResponseEncoder} to request decoding and response encoding. * {@link BinaryMemcacheResponseEncoder} to request decoding and response encoding.
*/ */
public class BinaryMemcacheServerCodec public class BinaryMemcacheServerCodec extends ChannelHandlerAppender {
extends CombinedChannelDuplexHandler<BinaryMemcacheRequestDecoder, BinaryMemcacheResponseEncoder> {
public BinaryMemcacheServerCodec() { public BinaryMemcacheServerCodec() {
this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE); this(BinaryMemcacheDecoder.DEFAULT_MAX_CHUNK_SIZE);
} }
public BinaryMemcacheServerCodec(int decodeChunkSize) { public BinaryMemcacheServerCodec(int decodeChunkSize) {
init(new BinaryMemcacheRequestDecoder(decodeChunkSize), new BinaryMemcacheResponseEncoder()); add(new BinaryMemcacheRequestDecoder(decodeChunkSize), new BinaryMemcacheResponseEncoder());
} }
} }

View File

@ -16,7 +16,7 @@
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.internal.TypeParameterMatcher; import io.netty.util.internal.TypeParameterMatcher;
@ -31,7 +31,7 @@ import java.util.List;
* Be aware that sub-classes of {@link ByteToMessageCodec} <strong>MUST NOT</strong> * Be aware that sub-classes of {@link ByteToMessageCodec} <strong>MUST NOT</strong>
* annotated with {@link @Sharable}. * annotated with {@link @Sharable}.
*/ */
public abstract class ByteToMessageCodec<I> extends ChannelDuplexHandler { public abstract class ByteToMessageCodec<I> extends ChannelHandlerAdapter {
private final TypeParameterMatcher outboundMsgMatcher; private final TypeParameterMatcher outboundMsgMatcher;
private final MessageToByteEncoder<I> encoder; private final MessageToByteEncoder<I> encoder;

View File

@ -17,15 +17,16 @@ package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.internal.RecyclableArrayList; import io.netty.util.internal.RecyclableArrayList;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import java.util.List; import java.util.List;
/** /**
* {@link ChannelInboundHandlerAdapter} which decodes bytes in a stream-like fashion from one {@link ByteBuf} to an * A {@link ChannelHandler} which decodes bytes in a stream-like fashion from one {@link ByteBuf} to an
* other Message type. * other Message type.
* *
* For example here is an implementation which reads all readable bytes from * For example here is an implementation which reads all readable bytes from
@ -44,7 +45,7 @@ import java.util.List;
* Be aware that sub-classes of {@link ByteToMessageDecoder} <strong>MUST NOT</strong> * Be aware that sub-classes of {@link ByteToMessageDecoder} <strong>MUST NOT</strong>
* annotated with {@link @Sharable}. * annotated with {@link @Sharable}.
*/ */
public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter { public abstract class ByteToMessageDecoder extends ChannelHandlerAdapter {
ByteBuf cumulation; ByteBuf cumulation;
private boolean singleDecode; private boolean singleDecode;

View File

@ -17,9 +17,9 @@ package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
@ -27,7 +27,7 @@ import io.netty.util.internal.TypeParameterMatcher;
/** /**
* {@link ChannelOutboundHandlerAdapter} which encodes message in a stream-like fashion from one message to an * {@link ChannelHandlerAdapter} which encodes message in a stream-like fashion from one message to an
* {@link ByteBuf}. * {@link ByteBuf}.
* *
* *
@ -43,7 +43,7 @@ import io.netty.util.internal.TypeParameterMatcher;
* } * }
* </pre> * </pre>
*/ */
public abstract class MessageToByteEncoder<I> extends ChannelOutboundHandlerAdapter { public abstract class MessageToByteEncoder<I> extends ChannelHandlerAdapter {
private final TypeParameterMatcher matcher; private final TypeParameterMatcher matcher;
private final boolean preferDirect; private final boolean preferDirect;
@ -89,7 +89,7 @@ public abstract class MessageToByteEncoder<I> extends ChannelOutboundHandlerAdap
/** /**
* Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next * Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
* {@link ChannelOutboundHandler} in the {@link ChannelPipeline}. * {@link ChannelHandler} in the {@link ChannelPipeline}.
*/ */
public boolean acceptOutboundMessage(Object msg) throws Exception { public boolean acceptOutboundMessage(Object msg) throws Exception {
return matcher.match(msg); return matcher.match(msg);

View File

@ -15,7 +15,7 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.ReferenceCounted; import io.netty.util.ReferenceCounted;
@ -52,7 +52,7 @@ import java.util.List;
* are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageCodec} will call * are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageCodec} will call
* {@link ReferenceCounted#release()} on encoded / decoded messages. * {@link ReferenceCounted#release()} on encoded / decoded messages.
*/ */
public abstract class MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN> extends ChannelDuplexHandler { public abstract class MessageToMessageCodec<INBOUND_IN, OUTBOUND_IN> extends ChannelHandlerAdapter {
private final MessageToMessageEncoder<Object> encoder = new MessageToMessageEncoder<Object>() { private final MessageToMessageEncoder<Object> encoder = new MessageToMessageEncoder<Object>() {

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import io.netty.util.ReferenceCounted; import io.netty.util.ReferenceCounted;
@ -27,7 +27,7 @@ import io.netty.util.internal.TypeParameterMatcher;
import java.util.List; import java.util.List;
/** /**
* {@link ChannelInboundHandlerAdapter} which decodes from one message to an other message. * A {@link ChannelHandler} which decodes from one message to an other message.
* *
* *
* For example here is an implementation which decodes a {@link String} to an {@link Integer} which represent * For example here is an implementation which decodes a {@link String} to an {@link Integer} which represent
@ -50,7 +50,7 @@ import java.util.List;
* {@link ReferenceCounted#release()} on decoded messages. * {@link ReferenceCounted#release()} on decoded messages.
* *
*/ */
public abstract class MessageToMessageDecoder<I> extends ChannelInboundHandlerAdapter { public abstract class MessageToMessageDecoder<I> extends ChannelHandlerAdapter {
private final TypeParameterMatcher matcher; private final TypeParameterMatcher matcher;
@ -72,7 +72,7 @@ public abstract class MessageToMessageDecoder<I> extends ChannelInboundHandlerAd
/** /**
* Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next * Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
* {@link ChannelInboundHandler} in the {@link ChannelPipeline}. * {@link ChannelHandler} in the {@link ChannelPipeline}.
*/ */
public boolean acceptInboundMessage(Object msg) throws Exception { public boolean acceptInboundMessage(Object msg) throws Exception {
return matcher.match(msg); return matcher.match(msg);

View File

@ -15,9 +15,9 @@
*/ */
package io.netty.handler.codec; package io.netty.handler.codec;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
@ -29,7 +29,7 @@ import io.netty.util.internal.TypeParameterMatcher;
import java.util.List; import java.util.List;
/** /**
* {@link ChannelOutboundHandlerAdapter} which encodes from one message to an other message * A {@link ChannelHandler} which encodes from one message to an other message
* *
* For example here is an implementation which decodes an {@link Integer} to an {@link String}. * For example here is an implementation which decodes an {@link Integer} to an {@link String}.
* *
@ -49,7 +49,7 @@ import java.util.List;
* are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageEncoder} will call * are of type {@link ReferenceCounted}. This is needed as the {@link MessageToMessageEncoder} will call
* {@link ReferenceCounted#release()} on encoded messages. * {@link ReferenceCounted#release()} on encoded messages.
*/ */
public abstract class MessageToMessageEncoder<I> extends ChannelOutboundHandlerAdapter { public abstract class MessageToMessageEncoder<I> extends ChannelHandlerAdapter {
private final TypeParameterMatcher matcher; private final TypeParameterMatcher matcher;
@ -71,7 +71,7 @@ public abstract class MessageToMessageEncoder<I> extends ChannelOutboundHandlerA
/** /**
* Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next * Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
* {@link ChannelOutboundHandler} in the {@link ChannelPipeline}. * {@link ChannelHandler} in the {@link ChannelPipeline}.
*/ */
public boolean acceptOutboundMessage(Object msg) throws Exception { public boolean acceptOutboundMessage(Object msg) throws Exception {
return matcher.match(msg); return matcher.match(msg);

View File

@ -18,7 +18,6 @@ package io.netty.handler.codec.compression;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import java.nio.ByteOrder;
import java.util.List; import java.util.List;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import java.util.zip.DataFormatException; import java.util.zip.DataFormatException;

View File

@ -17,8 +17,8 @@ package io.netty.handler.codec;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Test; import org.junit.Test;
@ -79,7 +79,7 @@ public class ReplayingDecoderTest {
assertNull(ch.readInbound()); assertNull(ch.readInbound());
} }
private static final class BloatedLineDecoder extends ChannelInboundHandlerAdapter { private static final class BloatedLineDecoder extends ChannelHandlerAdapter {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ctx.pipeline().replace(this, "less-bloated", new LineDecoder()); ctx.pipeline().replace(this, "less-bloated", new LineDecoder());

View File

@ -26,7 +26,6 @@ import java.util.Random;
import static io.netty.buffer.Unpooled.*; import static io.netty.buffer.Unpooled.*;
import static org.hamcrest.core.Is.*; import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsNull.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@SuppressWarnings("ZeroLengthArrayAllocation") @SuppressWarnings("ZeroLengthArrayAllocation")

View File

@ -17,8 +17,8 @@ package io.netty.example.echo;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -28,7 +28,7 @@ import java.util.logging.Logger;
* traffic between the echo client and server by sending the first message to * traffic between the echo client and server by sending the first message to
* the server. * the server.
*/ */
public class EchoClientHandler extends ChannelInboundHandlerAdapter { public class EchoClientHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
EchoClientHandler.class.getName()); EchoClientHandler.class.getName());

View File

@ -16,8 +16,8 @@
package io.netty.example.echo; package io.netty.example.echo;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -26,7 +26,7 @@ import java.util.logging.Logger;
* Handler implementation for the echo server. * Handler implementation for the echo server.
*/ */
@Sharable @Sharable
public class EchoServerHandler extends ChannelInboundHandlerAdapter { public class EchoServerHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
EchoServerHandler.class.getName()); EchoServerHandler.class.getName());

View File

@ -17,8 +17,8 @@ package io.netty.example.http.helloworld;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpRequest;
@ -28,7 +28,7 @@ import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpResponseStatus.*;
import static io.netty.handler.codec.http.HttpVersion.*; import static io.netty.handler.codec.http.HttpVersion.*;
public class HttpHelloWorldServerHandler extends ChannelInboundHandlerAdapter { public class HttpHelloWorldServerHandler extends ChannelHandlerAdapter {
private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' }; private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' };
@Override @Override

View File

@ -15,11 +15,11 @@
*/ */
package io.netty.example.localecho; package io.netty.example.localecho;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
public class LocalEchoServerHandler extends ChannelInboundHandlerAdapter { public class LocalEchoServerHandler extends ChannelHandlerAdapter {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

View File

@ -15,8 +15,8 @@
*/ */
package io.netty.example.objectecho; package io.netty.example.objectecho;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -28,7 +28,7 @@ import java.util.logging.Logger;
* ping-pong traffic between the object echo client and server by sending the * ping-pong traffic between the object echo client and server by sending the
* first message to the server. * first message to the server.
*/ */
public class ObjectEchoClientHandler extends ChannelInboundHandlerAdapter { public class ObjectEchoClientHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
ObjectEchoClientHandler.class.getName()); ObjectEchoClientHandler.class.getName());

View File

@ -15,8 +15,8 @@
*/ */
package io.netty.example.objectecho; package io.netty.example.objectecho;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -25,7 +25,7 @@ import java.util.logging.Logger;
* Handles both client-side and server-side handler depending on which * Handles both client-side and server-side handler depending on which
* constructor was called. * constructor was called.
*/ */
public class ObjectEchoServerHandler extends ChannelInboundHandlerAdapter { public class ObjectEchoServerHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
ObjectEchoServerHandler.class.getName()); ObjectEchoServerHandler.class.getName());

View File

@ -19,10 +19,10 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
public class HexDumpProxyBackendHandler extends ChannelInboundHandlerAdapter { public class HexDumpProxyBackendHandler extends ChannelHandlerAdapter {
private final Channel inboundChannel; private final Channel inboundChannel;

View File

@ -20,11 +20,11 @@ import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
public class HexDumpProxyFrontendHandler extends ChannelInboundHandlerAdapter { public class HexDumpProxyFrontendHandler extends ChannelHandlerAdapter {
private final String remoteHost; private final String remoteHost;
private final int remotePort; private final int remotePort;

View File

@ -17,8 +17,8 @@ package io.netty.example.sctp;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.sctp.SctpMessage; import io.netty.channel.sctp.SctpMessage;
import java.util.logging.Level; import java.util.logging.Level;
@ -29,7 +29,7 @@ import java.util.logging.Logger;
* traffic between the echo client and server by sending the first message to * traffic between the echo client and server by sending the first message to
* the server. * the server.
*/ */
public class SctpEchoClientHandler extends ChannelInboundHandlerAdapter { public class SctpEchoClientHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
SctpEchoClientHandler.class.getName()); SctpEchoClientHandler.class.getName());

View File

@ -16,8 +16,8 @@
package io.netty.example.sctp; package io.netty.example.sctp;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -26,7 +26,7 @@ import java.util.logging.Logger;
* Handler implementation for the SCTP echo server. * Handler implementation for the SCTP echo server.
*/ */
@Sharable @Sharable
public class SctpEchoServerHandler extends ChannelInboundHandlerAdapter { public class SctpEchoServerHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger( private static final Logger logger = Logger.getLogger(
SctpEchoServerHandler.class.getName()); SctpEchoServerHandler.class.getName());

View File

@ -15,12 +15,12 @@
*/ */
package io.netty.example.socksproxy; package io.netty.example.socksproxy;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
public final class DirectClientHandler extends ChannelInboundHandlerAdapter { public final class DirectClientHandler extends ChannelHandlerAdapter {
private static final String name = "DIRECT_CLIENT_HANDLER"; private static final String name = "DIRECT_CLIENT_HANDLER";
public static String getName() { public static String getName() {

View File

@ -17,12 +17,12 @@ package io.netty.example.socksproxy;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
public final class RelayHandler extends ChannelInboundHandlerAdapter { public final class RelayHandler extends ChannelHandlerAdapter {
private static final String name = "RELAY_HANDLER"; private static final String name = "RELAY_HANDLER";
public static String getName() { public static String getName() {

View File

@ -16,8 +16,8 @@
package io.netty.example.udt.echo.bytes; package io.netty.example.udt.echo.bytes;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.channel.udt.nio.NioUdtProvider;
import java.util.logging.Level; import java.util.logging.Level;
@ -27,7 +27,7 @@ import java.util.logging.Logger;
* Handler implementation for the echo server. * Handler implementation for the echo server.
*/ */
@Sharable @Sharable
public class ByteEchoServerHandler extends ChannelInboundHandlerAdapter { public class ByteEchoServerHandler extends ChannelHandlerAdapter {
private static final Logger log = Logger.getLogger(ByteEchoServerHandler.class.getName()); private static final Logger log = Logger.getLogger(ByteEchoServerHandler.class.getName());

View File

@ -16,8 +16,8 @@
package io.netty.example.udt.echo.message; package io.netty.example.udt.echo.message;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.channel.udt.nio.NioUdtProvider;
import java.util.logging.Level; import java.util.logging.Level;
@ -27,7 +27,7 @@ import java.util.logging.Logger;
* Handler implementation for the echo server. * Handler implementation for the echo server.
*/ */
@Sharable @Sharable
public class MsgEchoServerHandler extends ChannelInboundHandlerAdapter { public class MsgEchoServerHandler extends ChannelHandlerAdapter {
private static final Logger log = Logger.getLogger(MsgEchoServerHandler.class.getName()); private static final Logger log = Logger.getLogger(MsgEchoServerHandler.class.getName());

View File

@ -17,9 +17,9 @@ package io.netty.handler.logging;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.internal.logging.InternalLogLevel; import io.netty.util.internal.logging.InternalLogLevel;
@ -33,7 +33,7 @@ import java.net.SocketAddress;
* By default, all events are logged at <tt>DEBUG</tt> level. * By default, all events are logged at <tt>DEBUG</tt> level.
*/ */
@Sharable @Sharable
public class LoggingHandler extends ChannelDuplexHandler { public class LoggingHandler extends ChannelHandlerAdapter {
private static final LogLevel DEFAULT_LEVEL = LogLevel.DEBUG; private static final LogLevel DEFAULT_LEVEL = LogLevel.DEBUG;

View File

@ -15,6 +15,6 @@
*/ */
/** /**
* Logs a {@link io.netty.channel.ChannelEvent} for debugging purpose. * Logs the I/O events for debugging purpose.
*/ */
package io.netty.handler.logging; package io.netty.handler.logging;

View File

@ -22,9 +22,8 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOutboundHandler;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
@ -75,7 +74,7 @@ import java.util.regex.Pattern;
* <p> * <p>
* Beside using the handshake {@link ChannelFuture} to get notified about the completation of the handshake it's * Beside using the handshake {@link ChannelFuture} to get notified about the completation of the handshake it's
* also possible to detect it by implement the * also possible to detect it by implement the
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} * {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)}
* method and check for a {@link SslHandshakeCompletionEvent}. * method and check for a {@link SslHandshakeCompletionEvent}.
* *
* <h3>Handshake</h3> * <h3>Handshake</h3>
@ -155,7 +154,7 @@ import java.util.regex.Pattern;
* For more details see * For more details see
* <a href="https://github.com/netty/netty/issues/832">#832</a> in our issue tracker. * <a href="https://github.com/netty/netty/issues/832">#832</a> in our issue tracker.
*/ */
public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundHandler { public class SslHandler extends ByteToMessageDecoder {
private static final InternalLogger logger = private static final InternalLogger logger =
InternalLoggerFactory.getInstance(SslHandler.class); InternalLoggerFactory.getInstance(SslHandler.class);

View File

@ -19,10 +19,10 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelProgressivePromise; import io.netty.channel.ChannelProgressivePromise;
@ -66,8 +66,7 @@ import java.util.Queue;
* transfer. To resume the transfer when a new chunk is available, you have to * transfer. To resume the transfer when a new chunk is available, you have to
* call {@link #resumeTransfer()}. * call {@link #resumeTransfer()}.
*/ */
public class ChunkedWriteHandler public class ChunkedWriteHandler extends ChannelHandlerAdapter {
extends ChannelDuplexHandler {
private static final InternalLogger logger = private static final InternalLogger logger =
InternalLoggerFactory.getInstance(ChunkedWriteHandler.class); InternalLoggerFactory.getInstance(ChunkedWriteHandler.class);

View File

@ -17,9 +17,9 @@ package io.netty.handler.timeout;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
@ -71,7 +71,7 @@ import java.util.concurrent.TimeUnit;
* } * }
* *
* // Handler should handle the {@link IdleStateEvent} triggered by {@link IdleStateHandler}. * // Handler should handle the {@link IdleStateEvent} triggered by {@link IdleStateHandler}.
* public class MyHandler extends {@link ChannelDuplexHandler} { * public class MyHandler extends {@link ChannelHandlerAdapter} {
* {@code @Override} * {@code @Override}
* public void userEventTriggered({@link ChannelHandlerContext} ctx, {@link Object} evt) throws {@link Exception} { * public void userEventTriggered({@link ChannelHandlerContext} ctx, {@link Object} evt) throws {@link Exception} {
* if (evt instanceof {@link IdleStateEvent}} { * if (evt instanceof {@link IdleStateEvent}} {
@ -94,7 +94,7 @@ import java.util.concurrent.TimeUnit;
* @see ReadTimeoutHandler * @see ReadTimeoutHandler
* @see WriteTimeoutHandler * @see WriteTimeoutHandler
*/ */
public class IdleStateHandler extends ChannelDuplexHandler { public class IdleStateHandler extends ChannelHandlerAdapter {
private final long readerIdleTimeMillis; private final long readerIdleTimeMillis;
private final long writerIdleTimeMillis; private final long writerIdleTimeMillis;

View File

@ -17,9 +17,8 @@ package io.netty.handler.timeout;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@ -41,7 +40,7 @@ import java.util.concurrent.TimeUnit;
* } * }
* *
* // Handler should handle the {@link ReadTimeoutException}. * // Handler should handle the {@link ReadTimeoutException}.
* public class MyHandler extends {@link ChannelDuplexHandler} { * public class MyHandler extends {@link ChannelHandlerAdapter} {
* {@code @Override} * {@code @Override}
* public void exceptionCaught({@link ChannelHandlerContext} ctx, {@link Throwable} cause) * public void exceptionCaught({@link ChannelHandlerContext} ctx, {@link Throwable} cause)
* throws {@link Exception} { * throws {@link Exception} {
@ -61,7 +60,7 @@ import java.util.concurrent.TimeUnit;
* @see WriteTimeoutHandler * @see WriteTimeoutHandler
* @see IdleStateHandler * @see IdleStateHandler
*/ */
public class ReadTimeoutHandler extends ChannelInboundHandlerAdapter { public class ReadTimeoutHandler extends ChannelHandlerAdapter {
private final long timeoutMillis; private final long timeoutMillis;

View File

@ -17,12 +17,11 @@ package io.netty.handler.timeout;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@ -44,7 +43,7 @@ import java.util.concurrent.TimeUnit;
* } * }
* *
* // Handler should handle the {@link WriteTimeoutException}. * // Handler should handle the {@link WriteTimeoutException}.
* public class MyHandler extends {@link ChannelDuplexHandler} { * public class MyHandler extends {@link ChannelHandlerAdapter} {
* {@code @Override} * {@code @Override}
* public void exceptionCaught({@link ChannelHandlerContext} ctx, {@link Throwable} cause) * public void exceptionCaught({@link ChannelHandlerContext} ctx, {@link Throwable} cause)
* throws {@link Exception} { * throws {@link Exception} {
@ -64,7 +63,7 @@ import java.util.concurrent.TimeUnit;
* @see ReadTimeoutHandler * @see ReadTimeoutHandler
* @see IdleStateHandler * @see IdleStateHandler
*/ */
public class WriteTimeoutHandler extends ChannelOutboundHandlerAdapter { public class WriteTimeoutHandler extends ChannelHandlerAdapter {
private final long timeoutMillis; private final long timeoutMillis;

View File

@ -17,7 +17,7 @@ package io.netty.handler.traffic;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.util.Attribute; import io.netty.util.Attribute;
@ -42,7 +42,7 @@ import java.util.concurrent.TimeUnit;
* or start the monitoring, to change the checkInterval directly, or to have access to its values.</li> * or start the monitoring, to change the checkInterval directly, or to have access to its values.</li>
* </ul> * </ul>
*/ */
public abstract class AbstractTrafficShapingHandler extends ChannelDuplexHandler { public abstract class AbstractTrafficShapingHandler extends ChannelHandlerAdapter {
/** /**
* Default delay between two checks: 1s * Default delay between two checks: 1s
*/ */

View File

@ -23,20 +23,21 @@
* *
* <p>Two classes implement this behavior: * <p>Two classes implement this behavior:
* <ul> * <ul>
* <li> <tt>{@link TrafficCounter}</tt>: this class implements the counters needed by the handlers. * <li> <tt>{@link io.netty.handler.traffic.TrafficCounter}</tt>: this class implements the counters needed by the
* It can be accessed to get some extra information like the read or write bytes since last check, the read and write * handlers. It can be accessed to get some extra information like the read or write bytes since last check,
* bandwidth from last check...</li> * the read and write bandwidth from last check...</li>
* *
* <li> <tt>{@link AbstractTrafficShapingHandler}</tt>: this abstract class implements the kernel * <li> <tt>{@link io.netty.handler.traffic.AbstractTrafficShapingHandler}</tt>: this abstract class implements
* of traffic shaping. It could be extended to fit your needs. Two classes are proposed as default * the kernel of traffic shaping. It could be extended to fit your needs. Two classes are proposed as default
* implementations: see {@link ChannelTrafficShapingHandler} and see {@link GlobalTrafficShapingHandler} * implementations: see {@link io.netty.handler.traffic.ChannelTrafficShapingHandler} and
* respectively for Channel traffic shaping and Global traffic shaping.</li> * {@link io.netty.handler.traffic.GlobalTrafficShapingHandler} respectively for per-channel traffic shaping and
* global traffic shaping.</li>
* </ul></p> * </ul></p>
* *
* <p>Both inbound and outbound traffic can be shaped independently. This is done by either passing in * <p>Both inbound and outbound traffic can be shaped independently. This is done by either passing in
* the desired limiting values to the constructors of both the Channel and Global traffic shaping handlers, * the desired limiting values to the constructors of both the Channel and Global traffic shaping handlers,
* or by calling the <tt>configure</tt> method on the {@link AbstractTrafficShapingHandler}. A value of * or by calling the <tt>configure</tt> method on the {@link io.netty.handler.traffic.AbstractTrafficShapingHandler}.
* 0 for either parameter indicates that there should be no limitation. This allows you to monitor the * A value of for either parameter indicates that there should be no limitation. This allows you to monitor the
* incoming and outgoing traffic without shaping.</p> * incoming and outgoing traffic without shaping.</p>
* *
* <p>To activate or deactivate the statistics, you can adjust the delay to a low (suggested not less than 200ms * <p>To activate or deactivate the statistics, you can adjust the delay to a low (suggested not less than 200ms
@ -44,11 +45,13 @@
* or even using <tt>0</tt> which means no computation will be done.</p> * or even using <tt>0</tt> which means no computation will be done.</p>
* *
* <p>If you want to do anything with these statistics, just override the <tt>doAccounting</tt> method.<br> * <p>If you want to do anything with these statistics, just override the <tt>doAccounting</tt> method.<br>
* This interval can be changed either from the method <tt>configure</tt> in {@link AbstractTrafficShapingHandler} * This interval can be changed either from the method <tt>configure</tt>
* or directly using the method <tt>configure</tt> of {@link TrafficCounter}.</p> * in {@link io.netty.handler.traffic.AbstractTrafficShapingHandler} or directly using the method <tt>configure</tt>
* of {@link io.netty.handler.traffic.TrafficCounter}.</p>
* *
* <p>Note that a new {@link ChannelTrafficShapingHandler} must be created for each new channel, * <p>Note that a new {@link io.netty.handler.traffic.ChannelTrafficShapingHandler} must be created
* but only one {@link GlobalTrafficShapingHandler} must be created for all channels.</p> * for each new channel, but only one {@link io.netty.handler.traffic.GlobalTrafficShapingHandler} must be created
* for all channels.</p>
* *
* <p>Note also that you can create different GlobalTrafficShapingHandler if you want to separate classes of * <p>Note also that you can create different GlobalTrafficShapingHandler if you want to separate classes of
* channels (for instance either from business point of view or from bind address point of view).</p> * channels (for instance either from business point of view or from bind address point of view).</p>

View File

@ -18,12 +18,9 @@ package io.netty.handler.logging;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender; import ch.qos.logback.core.Appender;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.embedded.EmbeddedChannel; import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.easymock.EasyMock; import org.easymock.EasyMock;
import org.easymock.IArgumentMatcher; import org.easymock.IArgumentMatcher;
import org.junit.Before; import org.junit.Before;
@ -31,7 +28,6 @@ import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.regex.Pattern;
import static org.easymock.EasyMock.*; import static org.easymock.EasyMock.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -18,8 +18,8 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -93,7 +93,7 @@ public class ServerSocketSuspendTest extends AbstractServerSocketTest {
} }
@ChannelHandler.Sharable @ChannelHandler.Sharable
private static final class AcceptedChannelCounter extends ChannelInboundHandlerAdapter { private static final class AcceptedChannelCounter extends ChannelHandlerAdapter {
final CountDownLatch latch; final CountDownLatch latch;

View File

@ -17,8 +17,8 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.util.internal.SystemPropertyUtil; import io.netty.util.internal.SystemPropertyUtil;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -101,7 +101,7 @@ public class SocketConnectionAttemptTest extends AbstractClientSocketTest {
} }
} }
private static class TestHandler extends ChannelInboundHandlerAdapter { private static class TestHandler extends ChannelHandlerAdapter {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace(); cause.printStackTrace();

View File

@ -20,8 +20,8 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
@ -116,7 +116,7 @@ public class SocketEchoTest extends AbstractSocketTest {
}); });
} else { } else {
sb.childHandler(sh); sb.childHandler(sh);
sb.handler(new ChannelInboundHandlerAdapter() { sb.handler(new ChannelHandlerAdapter() {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace(); cause.printStackTrace();

View File

@ -19,8 +19,8 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.DefaultFileRegion; import io.netty.channel.DefaultFileRegion;
import io.netty.channel.FileRegion; import io.netty.channel.FileRegion;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
@ -70,7 +70,7 @@ public class SocketFileRegionTest extends AbstractSocketTest {
out.write(data); out.write(data);
out.close(); out.close();
ChannelInboundHandler ch = new SimpleChannelInboundHandler<Object>() { ChannelHandler ch = new SimpleChannelInboundHandler<Object>() {
@Override @Override
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
} }

View File

@ -18,8 +18,8 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ClassResolvers;
@ -133,7 +133,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
} }
} }
private static class EchoHandler extends ChannelInboundHandlerAdapter { private static class EchoHandler extends ChannelHandlerAdapter {
volatile Channel channel; volatile Channel channel;
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
volatile int counter; volatile int counter;

View File

@ -20,8 +20,8 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
@ -220,7 +220,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
} }
} }
private static class SpdyEchoTestServerHandler extends ChannelInboundHandlerAdapter { private static class SpdyEchoTestServerHandler extends ChannelHandlerAdapter {
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
@Override @Override

View File

@ -17,8 +17,8 @@ package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import org.junit.Test; import org.junit.Test;
@ -42,8 +42,7 @@ public class WriteBeforeRegisteredTest extends AbstractClientSocketTest {
} }
} }
private static class TestHandler extends ChannelInboundHandlerAdapter { private static class TestHandler extends ChannelHandlerAdapter {
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace(); cause.printStackTrace();

View File

@ -19,8 +19,8 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.FullHttpResponse;
@ -47,7 +47,7 @@ import static io.netty.handler.codec.http.HttpVersion.*;
/** /**
* Handles handshakes and messages * Handles handshakes and messages
*/ */
public class AutobahnServerHandler extends ChannelInboundHandlerAdapter { public class AutobahnServerHandler extends ChannelHandlerAdapter {
private static final Logger logger = Logger.getLogger(AutobahnServerHandler.class.getName()); private static final Logger logger = Logger.getLogger(AutobahnServerHandler.class.getName());
private WebSocketServerHandshaker handshaker; private WebSocketServerHandshaker handshaker;

View File

@ -18,6 +18,7 @@ package io.netty.channel.sctp;
import com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams; import com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelOption;
import io.netty.channel.MessageSizeEstimator; import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator; import io.netty.channel.RecvByteBufAllocator;
@ -33,12 +34,12 @@ import io.netty.channel.RecvByteBufAllocator;
* <tr> * <tr>
* <th>Name</th><th>Associated setter method</th> * <th>Name</th><th>Associated setter method</th>
* </tr><tr> * </tr><tr>
* <td>{@link ChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
* </tr><tr>
* <td>{@link ChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
* </tr><tr>
* <td>{@link SctpChannelOption#SCTP_NODELAY}</td><td>{@link #setSctpNoDelay(boolean)}}</td> * <td>{@link SctpChannelOption#SCTP_NODELAY}</td><td>{@link #setSctpNoDelay(boolean)}}</td>
* </tr><tr> * </tr><tr>
* <td>{@link SctpChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
* </tr><tr>
* <td>{@link SctpChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
* </tr><tr>
* <td>{@link SctpChannelOption#SCTP_INIT_MAXSTREAMS}</td><td>{@link #setInitMaxStreams(InitMaxStreams)}</td> * <td>{@link SctpChannelOption#SCTP_INIT_MAXSTREAMS}</td><td>{@link #setInitMaxStreams(InitMaxStreams)}</td>
* </tr> * </tr>
* </table> * </table>

View File

@ -18,6 +18,7 @@ package io.netty.channel.sctp;
import com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams; import com.sun.nio.sctp.SctpStandardSocketOptions.InitMaxStreams;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelOption;
import io.netty.channel.MessageSizeEstimator; import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator; import io.netty.channel.RecvByteBufAllocator;
@ -34,11 +35,11 @@ import io.netty.channel.RecvByteBufAllocator;
* <tr> * <tr>
* <th>Name</th><th>Associated setter method</th> * <th>Name</th><th>Associated setter method</th>
* </tr><tr> * </tr><tr>
* <td>{@link SctpChannelOption#SO_BACKLOG}</td><td>{@link #setBacklog(int)}</td> * <td>{@link ChannelOption#SO_BACKLOG}</td><td>{@link #setBacklog(int)}</td>
* </tr><tr> * </tr><tr>
* <td>{@link SctpChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td> * <td>{@link ChannelOption#SO_RCVBUF}</td><td>{@link #setReceiveBufferSize(int)}</td>
* </tr><tr> * </tr><tr>
* <td>{@link SctpChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td> * <td>{@link ChannelOption#SO_SNDBUF}</td><td>{@link #setSendBufferSize(int)}</td>
* </tr><tr> * </tr><tr>
* <td>{@link SctpChannelOption#SCTP_INIT_MAXSTREAMS}</td><td>{@link #setInitMaxStreams(InitMaxStreams)}</td> * <td>{@link SctpChannelOption#SCTP_INIT_MAXSTREAMS}</td><td>{@link #setInitMaxStreams(InitMaxStreams)}</td>
* </tr> * </tr>

View File

@ -18,8 +18,8 @@ package io.netty.handler.codec.sctp;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.sctp.SctpMessage; import io.netty.channel.sctp.SctpMessage;
import io.netty.handler.codec.MessageToMessageDecoder; import io.netty.handler.codec.MessageToMessageDecoder;
@ -30,7 +30,7 @@ import java.util.Map;
/** /**
* {@link MessageToMessageDecoder} which will take care of handle fragmented {@link SctpMessage}s, so * {@link MessageToMessageDecoder} which will take care of handle fragmented {@link SctpMessage}s, so
* only <strong>complete</strong> {@link SctpMessage}s will be forwarded to the next * only <strong>complete</strong> {@link SctpMessage}s will be forwarded to the next
* {@link ChannelInboundHandler}. * {@link ChannelHandler}.
*/ */
public class SctpMessageCompletionHandler extends MessageToMessageDecoder<SctpMessage> { public class SctpMessageCompletionHandler extends MessageToMessageDecoder<SctpMessage> {
private final Map<Integer, ByteBuf> fragments = new HashMap<Integer, ByteBuf>(); private final Map<Integer, ByteBuf> fragments = new HashMap<Integer, ByteBuf>();

View File

@ -19,8 +19,8 @@ package io.netty.test.udt.util;
import com.yammer.metrics.core.Meter; import com.yammer.metrics.core.Meter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.channel.udt.nio.NioUdtProvider;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
@ -30,7 +30,7 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
* traffic between the echo client and server by sending the first message to * traffic between the echo client and server by sending the first message to
* the server on activation. * the server on activation.
*/ */
public class EchoByteHandler extends ChannelInboundHandlerAdapter { public class EchoByteHandler extends ChannelHandlerAdapter {
private static final InternalLogger log = InternalLoggerFactory.getInstance(EchoByteHandler.class); private static final InternalLogger log = InternalLoggerFactory.getInstance(EchoByteHandler.class);

View File

@ -19,8 +19,8 @@ package io.netty.test.udt.util;
import com.yammer.metrics.core.Meter; import com.yammer.metrics.core.Meter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.udt.UdtMessage; import io.netty.channel.udt.UdtMessage;
import io.netty.channel.udt.nio.NioUdtProvider; import io.netty.channel.udt.nio.NioUdtProvider;
import io.netty.util.internal.logging.InternalLogger; import io.netty.util.internal.logging.InternalLogger;
@ -31,7 +31,7 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
* between the echo peers by sending the first message to the other peer on * between the echo peers by sending the first message to the other peer on
* activation. * activation.
*/ */
public class EchoMessageHandler extends ChannelInboundHandlerAdapter { public class EchoMessageHandler extends ChannelHandlerAdapter {
private static final InternalLogger log = InternalLoggerFactory.getInstance(EchoMessageHandler.class); private static final InternalLogger log = InternalLoggerFactory.getInstance(EchoMessageHandler.class);

View File

@ -19,8 +19,8 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
@ -254,7 +254,7 @@ public final class ServerBootstrap extends AbstractBootstrap<ServerBootstrap, Se
return new Entry[size]; return new Entry[size];
} }
private static class ServerBootstrapAcceptor extends ChannelInboundHandlerAdapter { private static class ServerBootstrapAcceptor extends ChannelHandlerAdapter {
private final ChannelHandler childHandler; private final ChannelHandler childHandler;
private final Entry<ChannelOption<?>, Object>[] childOptions; private final Entry<ChannelOption<?>, Object>[] childOptions;

View File

@ -235,7 +235,7 @@ public interface Channel extends AttributeMap, ChannelOutboundOps, ChannelProper
void closeForcibly(); void closeForcibly();
/** /**
* Schedules a read operation that fills the inbound buffer of the first {@link ChannelInboundHandler} in the * Schedules a read operation that fills the inbound buffer of the first {@link ChannelHandler} in the
* {@link ChannelPipeline}. If there's already a pending read operation, this method does nothing. * {@link ChannelPipeline}. If there's already a pending read operation, this method does nothing.
*/ */
void beginRead(); void beginRead();

View File

@ -120,7 +120,7 @@ public interface ChannelConfig {
/** /**
* Returns the maximum number of messages to read per read loop. * Returns the maximum number of messages to read per read loop.
* a {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event. * a {@link ChannelHandler#channelRead(ChannelHandlerContext, Object) channelRead()} event.
* If this value is greater than 1, an event loop might attempt to read multiple times to procure multiple messages. * If this value is greater than 1, an event loop might attempt to read multiple times to procure multiple messages.
*/ */
int getMaxMessagesPerRead(); int getMaxMessagesPerRead();

View File

@ -15,94 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import java.net.SocketAddress;
/** /**
* {@link ChannelHandler} implementation which represents a combination out of a {@link ChannelInboundHandler} and * @deprecated Use {@link ChannelHandlerAdapter} instead.
* the {@link ChannelOutboundHandler}.
*
* It is a good starting point if your {@link ChannelHandler} implementation needs to intercept operations and also
* state updates.
*/ */
public class ChannelDuplexHandler extends ChannelInboundHandlerAdapter implements ChannelOutboundHandler { @Deprecated
public class ChannelDuplexHandler extends ChannelHandlerAdapter { }
/**
* Calls {@link ChannelHandlerContext#bind(SocketAddress, ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
ChannelPromise future) throws Exception {
ctx.bind(localAddress, future);
}
/**
* Calls {@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelPromise future) throws Exception {
ctx.connect(remoteAddress, localAddress, future);
}
/**
* Calls {@link ChannelHandlerContext#disconnect(ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise future)
throws Exception {
ctx.disconnect(future);
}
/**
* Calls {@link ChannelHandlerContext#close(ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Exception {
ctx.close(future);
}
/**
* Calls {@link ChannelHandlerContext#read()} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
ctx.read();
}
/**
* Calls {@link ChannelHandlerContext#write(Object, ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.write(msg, promise);
}
/**
* Calls {@link ChannelHandlerContext#flush()} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
}

View File

@ -24,29 +24,16 @@ import java.lang.annotation.Inherited;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import java.net.SocketAddress;
/** /**
* Handles an I/O event or intercepts an I/O operation, and forwards it to its next handler in * Handles an I/O event or intercepts an I/O operation, and forwards it to its next handler in
* its {@link ChannelPipeline}. * its {@link ChannelPipeline}.
* *
* <h3>Sub-types</h3> * <h3>Extend {@link ChannelHandlerAdapter} instead</h3>
* <p> * <p>
* {@link ChannelHandler} itself does not provide many methods, but you usually have to implement one of its subtypes: * Because this interface has many methods to implement, you might want to extend {@link ChannelHandlerAdapter}
* <ul> * instead.
* <li>{@link ChannelInboundHandler} to handle inbound I/O events, and</li>
* <li>{@link ChannelOutboundHandler} to handle outbound I/O operations.</li>
* </ul>
* </p>
* <p>
* Alternatively, the following adapter classes are provided for your convenience:
* <ul>
* <li>{@link ChannelInboundHandlerAdapter} to handle inbound I/O events,</li>
* <li>{@link ChannelOutboundHandlerAdapter} to handle outbound I/O operations, and</li>
* <li>{@link ChannelHandlerAdapter} to handle both inbound and outbound events</li>
* </ul>
* </p>
* <p>
* For more information, please refer to the documentation of each subtype.
* </p> * </p>
* *
* <h3>The context object</h3> * <h3>The context object</h3>
@ -184,6 +171,10 @@ import java.lang.annotation.Target;
*/ */
public interface ChannelHandler { public interface ChannelHandler {
////////////////////////////////
// Handler life cycle methods //
////////////////////////////////
/** /**
* Gets called after the {@link ChannelHandler} was added to the actual context and it's ready to handle events. * Gets called after the {@link ChannelHandler} was added to the actual context and it's ready to handle events.
*/ */
@ -195,11 +186,130 @@ public interface ChannelHandler {
*/ */
void handlerRemoved(ChannelHandlerContext ctx) throws Exception; void handlerRemoved(ChannelHandlerContext ctx) throws Exception;
///////////////////////////////////
// Inbound event handler methods //
///////////////////////////////////
/** /**
* Gets called if a {@link Throwable} was thrown. * Gets called if a {@link Throwable} was thrown.
*/ */
void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception; void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception;
/**
* The {@link Channel} of the {@link ChannelHandlerContext} was registered with its {@link EventLoop}
*/
void channelRegistered(ChannelHandlerContext ctx) throws Exception;
/**
* The {@link Channel} of the {@link ChannelHandlerContext} is now active
*/
void channelActive(ChannelHandlerContext ctx) throws Exception;
/**
* The {@link Channel} of the {@link ChannelHandlerContext} was registered is now inactive and reached its
* end of lifetime.
*/
void channelInactive(ChannelHandlerContext ctx) throws Exception;
/**
* Invoked when the current {@link Channel} has read a message from the peer.
*/
void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception;
/**
* Invoked when the last message read by the current read operation has been consumed by
* {@link #channelRead(ChannelHandlerContext, Object)}. If {@link ChannelOption#AUTO_READ} is off, no further
* attempt to read an inbound data from the current {@link Channel} will be made until
* {@link ChannelHandlerContext#read()} is called.
*/
void channelReadComplete(ChannelHandlerContext ctx) throws Exception;
/**
* Gets called if an user event was triggered.
*/
void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception;
/**
* Gets called once the writable state of a {@link Channel} changed. You can check the state with
* {@link Channel#isWritable()}.
*/
void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception;
////////////////////////////////////
// Outbound event handler methods //
////////////////////////////////////
/**
* Called once a bind operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the bind operation is made
* @param localAddress the {@link java.net.SocketAddress} to which it should bound
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception;
/**
* Called once a connect operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the connect operation is made
* @param remoteAddress the {@link SocketAddress} to which it should connect
* @param localAddress the {@link SocketAddress} which is used as source on connect
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void connect(
ChannelHandlerContext ctx,
SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception;
/**
* Called once a disconnect operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the disconnect operation is made
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
/**
* Called once a close operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the close operation is made
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
/**
* Intercepts {@link ChannelHandlerContext#read()}.
*/
void read(ChannelHandlerContext ctx) throws Exception;
/**
* Called once a write operation is made. The write operation will write the messages through the
* {@link ChannelPipeline}. Those are then ready to be flushed to the actual {@link Channel} once
* {@link Channel#flush()} is called
*
* @param ctx the {@link ChannelHandlerContext} for which the write operation is made
* @param msg the message to write
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception;
/**
* Called once a flush operation is made. The flush operation will try to flush out all previous written messages
* that are pending.
*
* @param ctx the {@link ChannelHandlerContext} for which the flush operation is made
* @throws Exception thrown if an error accour
*/
void flush(ChannelHandlerContext ctx) throws Exception;
/////////////////
// Annotations //
/////////////////
/** /**
* Indicates that the same instance of the annotated {@link ChannelHandler} * Indicates that the same instance of the annotated {@link ChannelHandler}
* can be added to one or more {@link ChannelPipeline}s multiple times * can be added to one or more {@link ChannelPipeline}s multiple times
@ -219,4 +329,41 @@ public interface ChannelHandler {
@interface Sharable { @interface Sharable {
// no value // no value
} }
/**
* 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}
* 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 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 Skip {
// no value
}
} }

View File

@ -16,10 +16,12 @@
package io.netty.channel; package io.netty.channel;
import java.net.SocketAddress;
/** /**
* Skelton implementation of a {@link ChannelHandler}. * Skelton implementation of a {@link ChannelHandler}.
*/ */
public abstract class ChannelHandlerAdapter implements ChannelHandler { public class ChannelHandlerAdapter implements ChannelHandler {
// Not using volatile because it's used only for a sanity check. // Not using volatile because it's used only for a sanity check.
boolean added; boolean added;
@ -35,6 +37,7 @@ public abstract class ChannelHandlerAdapter implements ChannelHandler {
/** /**
* Do nothing by default, sub-classes may override this method. * Do nothing by default, sub-classes may override this method.
*/ */
@Skip
@Override @Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception { public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
// NOOP // NOOP
@ -43,6 +46,7 @@ public abstract class ChannelHandlerAdapter implements ChannelHandler {
/** /**
* Do nothing by default, sub-classes may override this method. * Do nothing by default, sub-classes may override this method.
*/ */
@Skip
@Override @Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
// NOOP // NOOP
@ -54,9 +58,179 @@ public abstract class ChannelHandlerAdapter implements ChannelHandler {
* *
* Sub-classes may override this method to change behavior. * Sub-classes may override this method to change behavior.
*/ */
@Skip
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
throws Exception {
ctx.fireExceptionCaught(cause); ctx.fireExceptionCaught(cause);
} }
/**
* Calls {@link ChannelHandlerContext#fireChannelRegistered()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelRegistered();
}
/**
* Calls {@link ChannelHandlerContext#fireChannelActive()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelActive();
}
/**
* Calls {@link ChannelHandlerContext#fireChannelInactive()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelInactive();
}
/**
* Calls {@link ChannelHandlerContext#fireChannelRead(Object)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ctx.fireChannelRead(msg);
}
/**
* Calls {@link ChannelHandlerContext#fireChannelReadComplete()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
/**
* 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.
*/
@Skip
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
ctx.fireUserEventTriggered(evt);
}
/**
* Calls {@link ChannelHandlerContext#fireChannelWritabilityChanged()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelWritabilityChanged();
}
/**
* Calls {@link ChannelHandlerContext#bind(java.net.SocketAddress, ChannelPromise)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception {
ctx.bind(localAddress, promise);
}
/**
* Calls {@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void connect(
ChannelHandlerContext ctx,
SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception {
ctx.connect(remoteAddress, localAddress, promise);
}
/**
* Calls {@link ChannelHandlerContext#disconnect(ChannelPromise)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.disconnect(promise);
}
/**
* Calls {@link ChannelHandlerContext#close(ChannelPromise)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
ctx.close(promise);
}
/**
* Calls {@link ChannelHandlerContext#read()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
ctx.read();
}
/**
* Calls {@link ChannelHandlerContext#write(Object)} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.write(msg, promise);
}
/**
* Calls {@link ChannelHandlerContext#flush()} to forward
* to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Skip
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
} }

View File

@ -0,0 +1,203 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.channel;
import java.util.ArrayList;
import java.util.List;
/**
* A {@link ChannelHandler} that appends the specified {@link ChannelHandler}s right next to itself.
* By default, it removes itself from the {@link ChannelPipeline} once the specified {@link ChannelHandler}s
* are added. Optionally, you can keep it in the {@link ChannelPipeline} by specifying a {@code boolean}
* parameter at construction time.
*/
public class ChannelHandlerAppender extends ChannelHandlerAdapter {
private static final class Entry {
final String name;
final ChannelHandler handler;
Entry(String name, ChannelHandler handler) {
this.name = name;
this.handler = handler;
}
}
private final boolean selfRemoval;
private final List<Entry> handlers = new ArrayList<Entry>();
private boolean added;
/**
* Creates a new uninitialized instance. A class that extends this handler must invoke
* {@link #add(ChannelHandler...)} before adding this handler into a {@link ChannelPipeline}.
*/
protected ChannelHandlerAppender() {
this(true);
}
/**
* Creates a new uninitialized instance. A class that extends this handler must invoke
* {@link #add(ChannelHandler...)} before adding this handler into a {@link ChannelPipeline}.
*
* @param selfRemoval {@code true} to remove itself from the {@link ChannelPipeline} after appending
* the {@link ChannelHandler}s specified via {@link #add(ChannelHandler...)}.
*/
protected ChannelHandlerAppender(boolean selfRemoval) {
this.selfRemoval = selfRemoval;
}
/**
* Creates a new instance that appends the specified {@link ChannelHandler}s right next to itself.
*/
public ChannelHandlerAppender(Iterable<? extends ChannelHandler> handlers) {
this(true, handlers);
}
/**
* Creates a new instance that appends the specified {@link ChannelHandler}s right next to itself.
*/
public ChannelHandlerAppender(ChannelHandler... handlers) {
this(true, handlers);
}
/**
* Creates a new instance that appends the specified {@link ChannelHandler}s right next to itself.
*
* @param selfRemoval {@code true} to remove itself from the {@link ChannelPipeline} after appending
* the specified {@link ChannelHandler}s
*/
public ChannelHandlerAppender(boolean selfRemoval, Iterable<? extends ChannelHandler> handlers) {
this.selfRemoval = selfRemoval;
add(handlers);
}
/**
* Creates a new instance that appends the specified {@link ChannelHandler}s right next to itself.
*
* @param selfRemoval {@code true} to remove itself from the {@link ChannelPipeline} after appending
* the specified {@link ChannelHandler}s
*/
public ChannelHandlerAppender(boolean selfRemoval, ChannelHandler... handlers) {
this.selfRemoval = selfRemoval;
add(handlers);
}
/**
* Adds the specified handler to the list of the appended handlers.
*
* @param name the name of the appended handler. {@code null} to auto-generate
* @param handler the handler to append
*
* @throws IllegalStateException if {@link ChannelHandlerAppender} has been added to the pipeline already
*/
protected final ChannelHandlerAppender add(String name, ChannelHandler handler) {
if (handler == null) {
throw new NullPointerException("handler");
}
if (added) {
throw new IllegalStateException("added to the pipeline already");
}
handlers.add(new Entry(name, handler));
return this;
}
/**
* Adds the specified handler to the list of the appended handlers with the auto-generated handler name.
*
* @param handler the handler to append
*
* @throws IllegalStateException if {@link ChannelHandlerAppender} has been added to the pipeline already
*/
protected final ChannelHandlerAppender add(ChannelHandler handler) {
return add(null, handler);
}
/**
* Adds the specified handlers to the list of the appended handlers. The handlers' names are auto-generated.
*
* @throws IllegalStateException if {@link ChannelHandlerAppender} has been added to the pipeline already
*/
@SuppressWarnings("unchecked")
protected final ChannelHandlerAppender add(Iterable<? extends ChannelHandler> handlers) {
if (handlers == null) {
throw new NullPointerException("handlers");
}
for (ChannelHandler h: handlers) {
if (h == null) {
break;
}
add(h);
}
return this;
}
/**
* Adds the specified handlers to the list of the appended handlers. The handlers' names are auto-generated.
*
* @throws IllegalStateException if {@link ChannelHandlerAppender} has been added to the pipeline already
*/
protected final ChannelHandlerAppender add(ChannelHandler... handlers) {
if (handlers == null) {
throw new NullPointerException("handlers");
}
for (ChannelHandler h: handlers) {
if (h == null) {
break;
}
add(h);
}
return this;
}
/**
* Returns the {@code index}-th appended handler.
*/
@SuppressWarnings("unchecked")
protected final <T extends ChannelHandler> T handlerAt(int index) {
return (T) handlers.get(index).handler;
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
added = true;
DefaultChannelPipeline pipeline = (DefaultChannelPipeline) ctx.pipeline();
String name = ctx.name();
try {
for (Entry e: handlers) {
String oldName = name;
if (e.name == null) {
name = pipeline.generateName(e.handler);
} else {
name = e.name;
}
pipeline.addAfter(ctx.invoker(), oldName, name, e.handler);
}
} finally {
if (selfRemoval) {
pipeline.remove(this);
}
}
}
}

View File

@ -44,7 +44,7 @@ import java.nio.channels.Channels;
* You can keep the {@link ChannelHandlerContext} for later use, such as * You can keep the {@link ChannelHandlerContext} for later use, such as
* triggering an event outside the handler methods, even from a different thread. * triggering an event outside the handler methods, even from a different thread.
* <pre> * <pre>
* public class MyHandler extends {@link ChannelDuplexHandler} { * public class MyHandler extends {@link ChannelHandlerAdapter} {
* *
* <b>private {@link ChannelHandlerContext} ctx;</b> * <b>private {@link ChannelHandlerContext} ctx;</b>
* *
@ -79,15 +79,14 @@ import java.nio.channels.Channels;
* as how many times it is added to pipelines, regardless if it is added to the * as how many times it is added to pipelines, regardless if it is added to the
* same pipeline multiple times or added to different pipelines multiple times: * same pipeline multiple times or added to different pipelines multiple times:
* <pre> * <pre>
* public class FactorialHandler extends {@link ChannelInboundHandlerAdapter}&lt{@link Integer}&gt { * public class FactorialHandler extends {@link ChannelHandlerAdapter} {
* *
* private final {@link AttributeKey}&lt{@link Integer}&gt counter = * private final {@link AttributeKey}&lt{@link Integer}&gt counter = {@link AttributeKey}.valueOf("counter");
* new {@link AttributeKey}&lt{@link Integer}&gt("counter");
* *
* // This handler will receive a sequence of increasing integers starting * // This handler will receive a sequence of increasing integers starting
* // from 1. * // from 1.
* {@code @Override} * {@code @Override}
* public void channelRead({@link ChannelHandlerContext} ctx, {@link Integer} integer) { * public void channelRead({@link ChannelHandlerContext} ctx, Object msg) {
* {@link Attribute}&lt{@link Integer}&gt attr = ctx.getAttr(counter); * {@link Attribute}&lt{@link Integer}&gt attr = ctx.getAttr(counter);
* Integer a = ctx.getAttr(counter).get(); * Integer a = ctx.getAttr(counter).get();
* *
@ -95,7 +94,7 @@ import java.nio.channels.Channels;
* a = 1; * a = 1;
* } * }
* *
* attr.set(a * integer)); * attr.set(a * (Integer) msg);
* } * }
* } * }
* *
@ -134,6 +133,14 @@ public interface ChannelHandlerContext
*/ */
EventExecutor executor(); EventExecutor executor();
/**
* Returns the {@link ChannelHandlerInvoker} which is used to trigger an event for the associated
* {@link ChannelHandler}. Note that the methods in {@link ChannelHandlerInvoker} are not intended to be called
* by a user. Use this method only to obtain the reference to the {@link ChannelHandlerInvoker}
* (and not calling its methods) unless you know what you are doing.
*/
ChannelHandlerInvoker invoker();
/** /**
* The unique name of the {@link ChannelHandlerContext}.The name was used when then {@link ChannelHandler} * The unique name of the {@link ChannelHandlerContext}.The name was used when then {@link ChannelHandler}
* was added to the {@link ChannelPipeline}. This name can also be used to access the registered * was added to the {@link ChannelPipeline}. This name can also be used to access the registered

View File

@ -21,9 +21,9 @@ import io.netty.util.concurrent.EventExecutor;
import java.net.SocketAddress; import java.net.SocketAddress;
/** /**
* Invokes the event handler methods of {@link ChannelInboundHandler} and {@link ChannelOutboundHandler}. * Invokes the event handler methods of {@link ChannelHandler}.
* A user can specify a {@link ChannelHandlerInvoker} to implement a custom thread model unsupported by the default * A user can specify a {@link ChannelHandlerInvoker} to implement a custom thread model unsupported by the default
* implementation. * implementation. Note that the methods in this interface are not intended to be called by a user.
*/ */
public interface ChannelHandlerInvoker { public interface ChannelHandlerInvoker {
@ -33,21 +33,21 @@ public interface ChannelHandlerInvoker {
EventExecutor executor(); EventExecutor executor();
/** /**
* Invokes {@link ChannelInboundHandler#channelRegistered(ChannelHandlerContext)}. This method is not for a user * Invokes {@link ChannelHandler#channelRegistered(ChannelHandlerContext)}. This method is not for a user
* but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
void invokeChannelRegistered(ChannelHandlerContext ctx); void invokeChannelRegistered(ChannelHandlerContext ctx);
/** /**
* Invokes {@link ChannelInboundHandler#channelActive(ChannelHandlerContext)}. This method is not for a user * Invokes {@link ChannelHandler#channelActive(ChannelHandlerContext)}. This method is not for a user
* but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
void invokeChannelActive(ChannelHandlerContext ctx); void invokeChannelActive(ChannelHandlerContext ctx);
/** /**
* Invokes {@link ChannelInboundHandler#channelInactive(ChannelHandlerContext)}. This method is not for a user * Invokes {@link ChannelHandler#channelInactive(ChannelHandlerContext)}. This method is not for a user
* but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
@ -61,35 +61,35 @@ public interface ChannelHandlerInvoker {
void invokeExceptionCaught(ChannelHandlerContext ctx, Throwable cause); void invokeExceptionCaught(ChannelHandlerContext ctx, Throwable cause);
/** /**
* Invokes {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)}. This method is not for * Invokes {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)}. This method is not for
* a user but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * a user but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
void invokeUserEventTriggered(ChannelHandlerContext ctx, Object event); void invokeUserEventTriggered(ChannelHandlerContext ctx, Object event);
/** /**
* Invokes {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)}. This method is not for a user * Invokes {@link ChannelHandler#channelRead(ChannelHandlerContext, Object)}. This method is not for a user
* but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
void invokeChannelRead(ChannelHandlerContext ctx, Object msg); void invokeChannelRead(ChannelHandlerContext ctx, Object msg);
/** /**
* Invokes {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext)}. This method is not for a user * Invokes {@link ChannelHandler#channelReadComplete(ChannelHandlerContext)}. This method is not for a user
* but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
void invokeChannelReadComplete(ChannelHandlerContext ctx); void invokeChannelReadComplete(ChannelHandlerContext ctx);
/** /**
* Invokes {@link ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext)}. This method is not for * Invokes {@link ChannelHandler#channelWritabilityChanged(ChannelHandlerContext)}. This method is not for
* a user but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in * a user but for the internal {@link ChannelHandlerContext} implementation. To trigger an event, use the methods in
* {@link ChannelHandlerContext} instead. * {@link ChannelHandlerContext} instead.
*/ */
void invokeChannelWritabilityChanged(ChannelHandlerContext ctx); void invokeChannelWritabilityChanged(ChannelHandlerContext ctx);
/** /**
* Invokes {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)}. * Invokes {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */
@ -97,7 +97,7 @@ public interface ChannelHandlerInvoker {
/** /**
* Invokes * Invokes
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}. * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */
@ -105,43 +105,35 @@ public interface ChannelHandlerInvoker {
ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise); ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
/** /**
* Invokes {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)}. * Invokes {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */
void invokeDisconnect(ChannelHandlerContext ctx, ChannelPromise promise); void invokeDisconnect(ChannelHandlerContext ctx, ChannelPromise promise);
/** /**
* Invokes {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)}. * Invokes {@link ChannelHandler#close(ChannelHandlerContext, ChannelPromise)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */
void invokeClose(ChannelHandlerContext ctx, ChannelPromise promise); void invokeClose(ChannelHandlerContext ctx, ChannelPromise promise);
/** /**
* Invokes {@link ChannelOutboundHandler#read(ChannelHandlerContext)}. * Invokes {@link ChannelHandler#read(ChannelHandlerContext)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */
void invokeRead(ChannelHandlerContext ctx); void invokeRead(ChannelHandlerContext ctx);
/** /**
* Invokes {@link ChannelOutboundHandler#write(ChannelHandlerContext, Object, ChannelPromise)}. * Invokes {@link ChannelHandler#write(ChannelHandlerContext, Object, ChannelPromise)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */
void invokeWrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise); void invokeWrite(ChannelHandlerContext ctx, Object msg, ChannelPromise promise);
/** /**
* Invokes {@link ChannelOutboundHandler#write(ChannelHandlerContext, Object, ChannelPromise)} and * Invokes {@link ChannelHandler#flush(ChannelHandlerContext)}.
* {@link ChannelOutboundHandler#flush(ChannelHandlerContext)} sequentially.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/
void invokeWriteAndFlush(ChannelHandlerContext ctx, Object msg, ChannelPromise promise);
/**
* Invokes {@link ChannelOutboundHandler#flush(ChannelHandlerContext)}.
* This method is not for a user but for the internal {@link ChannelHandlerContext} implementation. * This method is not for a user but for the internal {@link ChannelHandlerContext} implementation.
* To trigger an event, use the methods in {@link ChannelHandlerContext} instead. * To trigger an event, use the methods in {@link ChannelHandlerContext} instead.
*/ */

View File

@ -27,7 +27,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeChannelRegisteredNow(ChannelHandlerContext ctx) { public static void invokeChannelRegisteredNow(ChannelHandlerContext ctx) {
try { try {
((ChannelInboundHandler) ctx.handler()).channelRegistered(ctx); ctx.handler().channelRegistered(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -35,7 +35,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeChannelActiveNow(final ChannelHandlerContext ctx) { public static void invokeChannelActiveNow(final ChannelHandlerContext ctx) {
try { try {
((ChannelInboundHandler) ctx.handler()).channelActive(ctx); ctx.handler().channelActive(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -43,7 +43,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeChannelInactiveNow(final ChannelHandlerContext ctx) { public static void invokeChannelInactiveNow(final ChannelHandlerContext ctx) {
try { try {
((ChannelInboundHandler) ctx.handler()).channelInactive(ctx); ctx.handler().channelInactive(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -63,7 +63,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeUserEventTriggeredNow(final ChannelHandlerContext ctx, final Object event) { public static void invokeUserEventTriggeredNow(final ChannelHandlerContext ctx, final Object event) {
try { try {
((ChannelInboundHandler) ctx.handler()).userEventTriggered(ctx, event); ctx.handler().userEventTriggered(ctx, event);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -71,7 +71,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeChannelReadNow(final ChannelHandlerContext ctx, final Object msg) { public static void invokeChannelReadNow(final ChannelHandlerContext ctx, final Object msg) {
try { try {
((ChannelInboundHandler) ctx.handler()).channelRead(ctx, msg); ctx.handler().channelRead(ctx, msg);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -79,7 +79,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeChannelReadCompleteNow(final ChannelHandlerContext ctx) { public static void invokeChannelReadCompleteNow(final ChannelHandlerContext ctx) {
try { try {
((ChannelInboundHandler) ctx.handler()).channelReadComplete(ctx); ctx.handler().channelReadComplete(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -87,7 +87,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeChannelWritabilityChangedNow(final ChannelHandlerContext ctx) { public static void invokeChannelWritabilityChangedNow(final ChannelHandlerContext ctx) {
try { try {
((ChannelInboundHandler) ctx.handler()).channelWritabilityChanged(ctx); ctx.handler().channelWritabilityChanged(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -96,7 +96,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeBindNow( public static void invokeBindNow(
final ChannelHandlerContext ctx, final SocketAddress localAddress, final ChannelPromise promise) { final ChannelHandlerContext ctx, final SocketAddress localAddress, final ChannelPromise promise) {
try { try {
((ChannelOutboundHandler) ctx.handler()).bind(ctx, localAddress, promise); ctx.handler().bind(ctx, localAddress, promise);
} catch (Throwable t) { } catch (Throwable t) {
notifyOutboundHandlerException(t, promise); notifyOutboundHandlerException(t, promise);
} }
@ -105,7 +105,7 @@ public final class ChannelHandlerInvokerUtil {
final ChannelHandlerContext ctx, final ChannelHandlerContext ctx,
final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) { final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) {
try { try {
((ChannelOutboundHandler) ctx.handler()).connect(ctx, remoteAddress, localAddress, promise); ctx.handler().connect(ctx, remoteAddress, localAddress, promise);
} catch (Throwable t) { } catch (Throwable t) {
notifyOutboundHandlerException(t, promise); notifyOutboundHandlerException(t, promise);
} }
@ -113,7 +113,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeDisconnectNow(final ChannelHandlerContext ctx, final ChannelPromise promise) { public static void invokeDisconnectNow(final ChannelHandlerContext ctx, final ChannelPromise promise) {
try { try {
((ChannelOutboundHandler) ctx.handler()).disconnect(ctx, promise); ctx.handler().disconnect(ctx, promise);
} catch (Throwable t) { } catch (Throwable t) {
notifyOutboundHandlerException(t, promise); notifyOutboundHandlerException(t, promise);
} }
@ -121,7 +121,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeCloseNow(final ChannelHandlerContext ctx, final ChannelPromise promise) { public static void invokeCloseNow(final ChannelHandlerContext ctx, final ChannelPromise promise) {
try { try {
((ChannelOutboundHandler) ctx.handler()).close(ctx, promise); ctx.handler().close(ctx, promise);
} catch (Throwable t) { } catch (Throwable t) {
notifyOutboundHandlerException(t, promise); notifyOutboundHandlerException(t, promise);
} }
@ -129,7 +129,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeReadNow(final ChannelHandlerContext ctx) { public static void invokeReadNow(final ChannelHandlerContext ctx) {
try { try {
((ChannelOutboundHandler) ctx.handler()).read(ctx); ctx.handler().read(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }
@ -137,7 +137,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeWriteNow(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) { public static void invokeWriteNow(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
try { try {
((ChannelOutboundHandler) ctx.handler()).write(ctx, msg, promise); ctx.handler().write(ctx, msg, promise);
} catch (Throwable t) { } catch (Throwable t) {
notifyOutboundHandlerException(t, promise); notifyOutboundHandlerException(t, promise);
} }
@ -145,7 +145,7 @@ public final class ChannelHandlerInvokerUtil {
public static void invokeFlushNow(final ChannelHandlerContext ctx) { public static void invokeFlushNow(final ChannelHandlerContext ctx) {
try { try {
((ChannelOutboundHandler) ctx.handler()).flush(ctx); ctx.handler().flush(ctx);
} catch (Throwable t) { } catch (Throwable t) {
notifyHandlerException(ctx, t); notifyHandlerException(ctx, t);
} }

View File

@ -1,63 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.channel;
/**
* {@link ChannelHandler} which adds callbacks for state changes. This allows the user to hook in to state changes
* easily.
*/
public interface ChannelInboundHandler extends ChannelHandler {
/**
* The {@link Channel} of the {@link ChannelHandlerContext} was registered with its {@link EventLoop}
*/
void channelRegistered(ChannelHandlerContext ctx) throws Exception;
/**
* The {@link Channel} of the {@link ChannelHandlerContext} is now active
*/
void channelActive(ChannelHandlerContext ctx) throws Exception;
/**
* The {@link Channel} of the {@link ChannelHandlerContext} was registered is now inactive and reached its
* end of lifetime.
*/
void channelInactive(ChannelHandlerContext ctx) throws Exception;
/**
* Invoked when the current {@link Channel} has read a message from the peer.
*/
void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception;
/**
* Invoked when the last message read by the current read operation has been consumed by
* {@link #channelRead(ChannelHandlerContext, Object)}. If {@link ChannelOption#AUTO_READ} is off, no further
* attempt to read an inbound data from the current {@link Channel} will be made until
* {@link ChannelHandlerContext#read()} is called.
*/
void channelReadComplete(ChannelHandlerContext ctx) throws Exception;
/**
* Gets called if an user event was triggered.
*/
void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception;
/**
* Gets called once the writable state of a {@link Channel} changed. You can check the state with
* {@link Channel#isWritable()}.
*/
void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception;
}

View File

@ -16,95 +16,7 @@
package io.netty.channel; package io.netty.channel;
/** /**
* Abstract base class for {@link ChannelInboundHandler} implementations that provides * @deprecated Use {@link ChannelHandlerAdapter} instead.
* implementations of all of their methods.
*
* <p>
* This implementation just forward the operation to the next {@link ChannelHandler} in the
* {@link ChannelPipeline}. Sub-classes may override a method implementation to change this.
* </p>
* <p>
* Be aware that messages are not released after the {@link #channelRead(ChannelHandlerContext, Object)}
* method returns automatically. If you are looking for a {@link ChannelInboundHandler} implementation that
* releases the received messages automatically, please see {@link SimpleChannelInboundHandler}.
* </p>
*/ */
public class ChannelInboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelInboundHandler { @Deprecated
public class ChannelInboundHandlerAdapter extends ChannelHandlerAdapter { }
/**
* Calls {@link ChannelHandlerContext#fireChannelRegistered()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelRegistered();
}
/**
* Calls {@link ChannelHandlerContext#fireChannelActive()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelActive();
}
/**
* Calls {@link ChannelHandlerContext#fireChannelInactive()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelInactive();
}
/**
* Calls {@link ChannelHandlerContext#fireChannelRead(Object)} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
ctx.fireChannelRead(msg);
}
/**
* Calls {@link ChannelHandlerContext#fireChannelReadComplete()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelReadComplete();
}
/**
* Calls {@link ChannelHandlerContext#fireUserEventTriggered(Object)} to forward
* to the next {@link ChannelInboundHandler} 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);
}
/**
* Calls {@link ChannelHandlerContext#fireChannelWritabilityChanged()} to forward
* to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelWritabilityChanged();
}
}

View File

@ -24,8 +24,8 @@ interface ChannelInboundOps {
/** /**
* A {@link Channel} was registered to its {@link EventLoop}. * A {@link Channel} was registered to its {@link EventLoop}.
* *
* This will result in having the {@link ChannelInboundHandler#channelRegistered(ChannelHandlerContext)} method * This will result in having the {@link ChannelHandler#channelRegistered(ChannelHandlerContext)} method
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelInboundOps fireChannelRegistered(); ChannelInboundOps fireChannelRegistered();
@ -33,8 +33,8 @@ interface ChannelInboundOps {
/** /**
* A {@link Channel} is active now, which means it is connected. * A {@link Channel} is active now, which means it is connected.
* *
* This will result in having the {@link ChannelInboundHandler#channelActive(ChannelHandlerContext)} method * This will result in having the {@link ChannelHandler#channelActive(ChannelHandlerContext)} method
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelInboundOps fireChannelActive(); ChannelInboundOps fireChannelActive();
@ -42,8 +42,8 @@ interface ChannelInboundOps {
/** /**
* A {@link Channel} is inactive now, which means it is closed. * A {@link Channel} is inactive now, which means it is closed.
* *
* This will result in having the {@link ChannelInboundHandler#channelInactive(ChannelHandlerContext)} method * This will result in having the {@link ChannelHandler#channelInactive(ChannelHandlerContext)} method
* called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelInboundOps fireChannelInactive(); ChannelInboundOps fireChannelInactive();
@ -51,8 +51,8 @@ interface ChannelInboundOps {
/** /**
* A {@link Channel} received an {@link Throwable} in one of its inbound operations. * A {@link Channel} received an {@link Throwable} in one of its inbound operations.
* *
* This will result in having the {@link ChannelInboundHandler#exceptionCaught(ChannelHandlerContext, Throwable)} * This will result in having the {@link ChannelHandler#exceptionCaught(ChannelHandlerContext, Throwable)}
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelInboundOps fireExceptionCaught(Throwable cause); ChannelInboundOps fireExceptionCaught(Throwable cause);
@ -60,8 +60,8 @@ interface ChannelInboundOps {
/** /**
* A {@link Channel} received an user defined event. * A {@link Channel} received an user defined event.
* *
* This will result in having the {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} * This will result in having the {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)}
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelInboundOps fireUserEventTriggered(Object event); ChannelInboundOps fireUserEventTriggered(Object event);
@ -69,8 +69,8 @@ interface ChannelInboundOps {
/** /**
* A {@link Channel} received a message. * A {@link Channel} received a message.
* *
* This will result in having the {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} * This will result in having the {@link ChannelHandler#channelRead(ChannelHandlerContext, Object)}
* method called of the next {@link ChannelInboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelInboundOps fireChannelRead(Object msg); ChannelInboundOps fireChannelRead(Object msg);
@ -78,8 +78,8 @@ interface ChannelInboundOps {
ChannelInboundOps fireChannelReadComplete(); ChannelInboundOps fireChannelReadComplete();
/** /**
* Triggers an {@link ChannelInboundHandler#channelWritabilityChanged(ChannelHandlerContext)} * Triggers an {@link ChannelHandler#channelWritabilityChanged(ChannelHandlerContext)}
* event to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. * event to the next {@link ChannelHandler} in the {@link ChannelPipeline}.
*/ */
ChannelInboundOps fireChannelWritabilityChanged(); ChannelInboundOps fireChannelWritabilityChanged();
} }

View File

@ -22,7 +22,7 @@ import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory; import io.netty.util.internal.logging.InternalLoggerFactory;
/** /**
* A special {@link ChannelInboundHandler} which offers an easy way to initialize a {@link Channel} once it was * A special {@link ChannelHandler} which offers an easy way to initialize a {@link Channel} once it was
* registered to its {@link EventLoop}. * registered to its {@link EventLoop}.
* *
* Implementations are most often used in the context of {@link Bootstrap#handler(ChannelHandler)} , * Implementations are most often used in the context of {@link Bootstrap#handler(ChannelHandler)} ,
@ -47,7 +47,7 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
* @param <C> A sub-type of {@link Channel} * @param <C> A sub-type of {@link Channel}
*/ */
@Sharable @Sharable
public abstract class ChannelInitializer<C extends Channel> extends ChannelInboundHandlerAdapter { public abstract class ChannelInitializer<C extends Channel> extends ChannelHandlerAdapter {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ChannelInitializer.class); private static final InternalLogger logger = InternalLoggerFactory.getInstance(ChannelInitializer.class);

View File

@ -1,90 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.channel;
import java.net.SocketAddress;
/**
* {@link ChannelHandler} which will get notified for IO-outbound-operations.
*/
public interface ChannelOutboundHandler extends ChannelHandler {
/**
* Called once a bind operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the bind operation is made
* @param localAddress the {@link SocketAddress} to which it should bound
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void bind(ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) throws Exception;
/**
* Called once a connect operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the connect operation is made
* @param remoteAddress the {@link SocketAddress} to which it should connect
* @param localAddress the {@link SocketAddress} which is used as source on connect
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void connect(
ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelPromise promise) throws Exception;
/**
* Called once a disconnect operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the disconnect operation is made
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
/**
* Called once a close operation is made.
*
* @param ctx the {@link ChannelHandlerContext} for which the close operation is made
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception;
/**
* Intercepts {@link ChannelHandlerContext#read()}.
*/
void read(ChannelHandlerContext ctx) throws Exception;
/**
* Called once a write operation is made. The write operation will write the messages through the
* {@link ChannelPipeline}. Those are then ready to be flushed to the actual {@link Channel} once
* {@link Channel#flush()} is called
*
* @param ctx the {@link ChannelHandlerContext} for which the write operation is made
* @param msg the message to write
* @param promise the {@link ChannelPromise} to notify once the operation completes
* @throws Exception thrown if an error accour
*/
void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception;
/**
* Called once a flush operation is made. The flush operation will try to flush out all previous written messages
* that are pending.
*
* @param ctx the {@link ChannelHandlerContext} for which the flush operation is made
* @throws Exception thrown if an error accour
*/
void flush(ChannelHandlerContext ctx) throws Exception;
}

View File

@ -15,92 +15,8 @@
*/ */
package io.netty.channel; package io.netty.channel;
import java.net.SocketAddress;
/** /**
* Skelton implementation of a {@link ChannelOutboundHandler}. This implementation just forwards each method call via * @deprecated Use {@link ChannelHandlerAdapter} instead.
* the {@link ChannelHandlerContext}.
*/ */
public class ChannelOutboundHandlerAdapter extends ChannelHandlerAdapter implements ChannelOutboundHandler { @Deprecated
public class ChannelOutboundHandlerAdapter extends ChannelHandlerAdapter { }
/**
* Calls {@link ChannelHandlerContext#bind(SocketAddress, ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void bind(ChannelHandlerContext ctx, SocketAddress localAddress,
ChannelPromise promise) throws Exception {
ctx.bind(localAddress, promise);
}
/**
* Calls {@link ChannelHandlerContext#connect(SocketAddress, SocketAddress, ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress,
SocketAddress localAddress, ChannelPromise promise) throws Exception {
ctx.connect(remoteAddress, localAddress, promise);
}
/**
* Calls {@link ChannelHandlerContext#disconnect(ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise)
throws Exception {
ctx.disconnect(promise);
}
/**
* Calls {@link ChannelHandlerContext#close(ChannelPromise)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise)
throws Exception {
ctx.close(promise);
}
/**
* Calls {@link ChannelHandlerContext#read()} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
ctx.read();
}
/**
* Calls {@link ChannelHandlerContext#write(Object)} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.write(msg, promise);
}
/**
* Calls {@link ChannelHandlerContext#flush()} to forward
* to the next {@link ChannelOutboundHandler} in the {@link ChannelPipeline}.
*
* Sub-classes may override this method to change behavior.
*/
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
}

View File

@ -28,8 +28,8 @@ interface ChannelOutboundOps {
* completes, either because the operation was successful or because of an error. * completes, either because the operation was successful or because of an error.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method * {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture bind(SocketAddress localAddress); ChannelFuture bind(SocketAddress localAddress);
@ -43,8 +43,8 @@ interface ChannelOutboundOps {
* will be used. * will be used.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)} * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture connect(SocketAddress remoteAddress); ChannelFuture connect(SocketAddress remoteAddress);
@ -55,8 +55,8 @@ interface ChannelOutboundOps {
* an error. * an error.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)} * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress); ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress);
@ -66,8 +66,8 @@ interface ChannelOutboundOps {
* either because the operation was successful or because of an error. * either because the operation was successful or because of an error.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)} * {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture disconnect(); ChannelFuture disconnect();
@ -80,8 +80,8 @@ interface ChannelOutboundOps {
* After it is closed it is not possible to reuse it again. * After it is closed it is not possible to reuse it again.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)} * {@link ChannelHandler#close(ChannelHandlerContext, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture close(); ChannelFuture close();
@ -93,8 +93,8 @@ interface ChannelOutboundOps {
* The given {@link ChannelPromise} will be notified. * The given {@link ChannelPromise} will be notified.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method * {@link ChannelHandler#bind(ChannelHandlerContext, SocketAddress, ChannelPromise)} method
* called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise); ChannelFuture bind(SocketAddress localAddress, ChannelPromise promise);
@ -111,8 +111,8 @@ interface ChannelOutboundOps {
* will be used. * will be used.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)} * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise); ChannelFuture connect(SocketAddress remoteAddress, ChannelPromise promise);
@ -125,8 +125,8 @@ interface ChannelOutboundOps {
* The given {@link ChannelPromise} will be notified and also returned. * The given {@link ChannelPromise} will be notified and also returned.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)} * {@link ChannelHandler#connect(ChannelHandlerContext, SocketAddress, SocketAddress, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise); ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise);
@ -138,8 +138,8 @@ interface ChannelOutboundOps {
* The given {@link ChannelPromise} will be notified. * The given {@link ChannelPromise} will be notified.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#disconnect(ChannelHandlerContext, ChannelPromise)} * {@link ChannelHandler#disconnect(ChannelHandlerContext, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture disconnect(ChannelPromise promise); ChannelFuture disconnect(ChannelPromise promise);
@ -153,22 +153,22 @@ interface ChannelOutboundOps {
* The given {@link ChannelPromise} will be notified. * The given {@link ChannelPromise} will be notified.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#close(ChannelHandlerContext, ChannelPromise)} * {@link ChannelHandler#close(ChannelHandlerContext, ChannelPromise)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelFuture close(ChannelPromise promise); ChannelFuture close(ChannelPromise promise);
/** /**
* Request to Read data from the {@link Channel} into the first inbound buffer, triggers an * Request to Read data from the {@link Channel} into the first inbound buffer, triggers an
* {@link ChannelInboundHandler#channelRead(ChannelHandlerContext, Object)} event if data was * {@link ChannelHandler#channelRead(ChannelHandlerContext, Object)} event if data was
* read, and triggers a * read, and triggers a
* {@link ChannelInboundHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the * {@link ChannelHandler#channelReadComplete(ChannelHandlerContext) channelReadComplete} event so the
* handler can decide to continue reading. If there's a pending read operation already, this method does nothing. * handler can decide to continue reading. If there's a pending read operation already, this method does nothing.
* <p> * <p>
* This will result in having the * This will result in having the
* {@link ChannelOutboundHandler#read(ChannelHandlerContext)} * {@link ChannelHandler#read(ChannelHandlerContext)}
* method called of the next {@link ChannelOutboundHandler} contained in the {@link ChannelPipeline} of the * method called of the next {@link ChannelHandler} contained in the {@link ChannelPipeline} of the
* {@link Channel}. * {@link Channel}.
*/ */
ChannelOutboundOps read(); ChannelOutboundOps read();

View File

@ -42,11 +42,11 @@ import java.util.NoSuchElementException;
* <h3>How an event flows in a pipeline</h3> * <h3>How an event flows in a pipeline</h3>
* *
* The following diagram describes how I/O events are processed by {@link ChannelHandler}s in a {@link ChannelPipeline} * The following diagram describes how I/O events are processed by {@link ChannelHandler}s in a {@link ChannelPipeline}
* typically. An I/O event is handled by either a {@link ChannelInboundHandler} or a {@link ChannelOutboundHandler} * typically. An I/O event is handled by a {@link ChannelHandler} and is forwarded by the {@link ChannelHandler} which
* and be forwarded to its closest handler by calling the event propagation methods defined in * handled the event to the {@link ChannelHandler} which is placed right next to it. A {@link ChannelHandler} can also
* {@link ChannelHandlerContext}, such as {@link ChannelHandlerContext#fireChannelRead(Object)} and * trigger an arbitrary I/O event if necessary. To forward or trigger an event, a {@link ChannelHandler} calls the
* {@link ChannelHandlerContext#write(Object)}. * event propagation methods defined in {@link ChannelHandlerContext}, such as
* * {@link ChannelHandlerContext#fireChannelRead(Object)} and {@link ChannelHandlerContext#write(Object)}.
* <pre> * <pre>
* I/O Request * I/O Request
* via {@link Channel} or * via {@link Channel} or
@ -55,28 +55,28 @@ import java.util.NoSuchElementException;
* +---------------------------------------------------+---------------+ * +---------------------------------------------------+---------------+
* | ChannelPipeline | | * | ChannelPipeline | |
* | \|/ | * | \|/ |
* | +---------------------+ +-----------+----------+ | * | +----------------------------------------------+----------+ |
* | | Inbound Handler N | | Outbound Handler 1 | | * | | ChannelHandler N | |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | /|\ | | * | /|\ | |
* | | \|/ | * | | \|/ |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | | Inbound Handler N-1 | | Outbound Handler 2 | | * | | ChannelHandler N-1 | |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | /|\ . | * | /|\ . |
* | . . | * | . . |
* | ChannelHandlerContext.fireIN_EVT() ChannelHandlerContext.OUT_EVT()| * | ChannelHandlerContext.fireIN_EVT() ChannelHandlerContext.OUT_EVT()|
* | [ method call] [method call] | * | [method call] [method call] |
* | . . | * | . . |
* | . \|/ | * | . \|/ |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | | Inbound Handler 2 | | Outbound Handler M-1 | | * | | ChannelHandler 2 | |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | /|\ | | * | /|\ | |
* | | \|/ | * | | \|/ |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | | Inbound Handler 1 | | Outbound Handler M | | * | | ChannelHandler 1 | |
* | +----------+----------+ +-----------+----------+ | * | +----------+-----------------------------------+----------+ |
* | /|\ | | * | /|\ | |
* +---------------+-----------------------------------+---------------+ * +---------------+-----------------------------------+---------------+
* | \|/ * | \|/
@ -87,45 +87,23 @@ import java.util.NoSuchElementException;
* | Netty Internal I/O Threads (Transport Implementation) | * | Netty Internal I/O Threads (Transport Implementation) |
* +-------------------------------------------------------------------+ * +-------------------------------------------------------------------+
* </pre> * </pre>
* An inbound event is handled by the inbound handlers in the bottom-up direction as shown on the left side of the * An inbound event is handled by the {@link ChannelHandler}s in the bottom-up direction as shown on the left side of
* diagram. An inbound handler usually handles the inbound data generated by the I/O thread on the bottom of the * the diagram. An inbound event is usually triggered by the I/O thread on the bottom of the diagram so that the
* diagram. The inbound data is often read from a remote peer via the actual input operation such as * {@link ChannelHandler}s are notified when the state of a {@link Channel} changes (e.g. newly established connections
* {@link SocketChannel#read(ByteBuffer)}. If an inbound event goes beyond the top inbound handler, it is discarded * and closed connections) or the inbound data was read from a remote peer. If an inbound event goes beyond the
* silently, or logged if it needs your attention. * {@link ChannelHandler} at the top of the diagram, it is discarded and logged, depending on your loglevel.
*
* <p> * <p>
* An outbound event is handled by the outbound handler in the top-down direction as shown on the right side of the * An outbound event is handled by the {@link ChannelHandler}s in the top-down direction as shown on the right side of
* diagram. An outbound handler usually generates or transforms the outbound traffic such as write requests. * the diagram. An outbound event is usually triggered by your code that requests an outbound I/O operation, such as
* If an outbound event goes beyond the bottom outbound handler, it is handled by an I/O thread associated with the * a write request and a connection attempt. If an outbound event goes beyond the {@link ChannelHandler} at the
* {@link Channel}. The I/O thread often performs the actual output operation such as * bottom of the diagram, it is handled by an I/O thread associated with the {@link Channel}. The I/O thread often
* {@link SocketChannel#write(ByteBuffer)}. * performs the actual output operation such as {@link SocketChannel#write(ByteBuffer)}.
* <p> * <p>
* For example, let us assume that we created the following pipeline:
* <pre>
* {@link ChannelPipeline} p = ...;
* p.addLast("1", new InboundHandlerA());
* p.addLast("2", new InboundHandlerB());
* p.addLast("3", new OutboundHandlerA());
* p.addLast("4", new OutboundHandlerB());
* p.addLast("5", new InboundOutboundHandlerX());
* </pre>
* In the example above, the class whose name starts with {@code Inbound} means it is an inbound handler.
* The class whose name starts with {@code Outbound} means it is a outbound handler.
* <p>
* In the given example configuration, the handler evaluation order is 1, 2, 3, 4, 5 when an event goes inbound.
* When an event goes outbound, the order is 5, 4, 3, 2, 1. On top of this principle, {@link ChannelPipeline} skips
* the evaluation of certain handlers to shorten the stack depth:
* <ul>
* <li>3 and 4 don't implement {@link ChannelInboundHandler}, and therefore the actual evaluation order of an inbound
* event will be: 1, 2, and 5.</li>
* <li>1 and 2 don't implement {@link ChannelOutboundHandler}, and therefore the actual evaluation order of a
* outbound event will be: 5, 4, and 3.</li>
* <li>If 5 implements both {@link ChannelInboundHandler} and {@link ChannelOutboundHandler}, the evaluation order of
* an inbound and a outbound event could be 125 and 543 respectively.</li>
* </ul>
* *
* <h3>Forwarding an event to the next handler</h3> * <h3>Forwarding an event to the next handler</h3>
* *
* As you might noticed in the diagram shows, a handler has to invoke the event propagation methods in * As explained briefly above, a {@link ChannelHandler} has to invoke the event propagation methods in
* {@link ChannelHandlerContext} to forward an event to its next handler. Those methods include: * {@link ChannelHandlerContext} to forward an event to its next handler. Those methods include:
* <ul> * <ul>
* <li>Inbound event propagation methods: * <li>Inbound event propagation methods:
@ -156,7 +134,7 @@ import java.util.NoSuchElementException;
* and the following example shows how the event propagation is usually done: * and the following example shows how the event propagation is usually done:
* *
* <pre> * <pre>
* public class MyInboundHandler extends {@link ChannelInboundHandlerAdapter} { * public class MyInboundHandler extends {@link ChannelHandlerAdapter} {
* {@code @Override} * {@code @Override}
* public void channelActive({@link ChannelHandlerContext} ctx) { * public void channelActive({@link ChannelHandlerContext} ctx) {
* System.out.println("Connected!"); * System.out.println("Connected!");
@ -164,7 +142,7 @@ import java.util.NoSuchElementException;
* } * }
* } * }
* *
* public clas MyOutboundHandler extends {@link ChannelOutboundHandlerAdapter} { * public clas MyOutboundHandler extends {@link ChannelHandlerAdapter} {
* {@code @Override} * {@code @Override}
* public void close({@link ChannelHandlerContext} ctx, {@link ChannelPromise} promise) { * public void close({@link ChannelHandlerContext} ctx, {@link ChannelPromise} promise) {
* System.out.println("Closing .."); * System.out.println("Closing ..");

View File

@ -1,195 +0,0 @@
/*
* Copyright 2012 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.channel;
import java.net.SocketAddress;
/**
* Combines a {@link ChannelInboundHandler} and a {@link ChannelOutboundHandler} into one {@link ChannelHandler}.
*
*/
public class CombinedChannelDuplexHandler<I extends ChannelInboundHandler, O extends ChannelOutboundHandler>
extends ChannelDuplexHandler {
private I inboundHandler;
private O outboundHandler;
/**
* Creates a new uninitialized instance. A class that extends this handler must invoke
* {@link #init(ChannelInboundHandler, ChannelOutboundHandler)} before adding this handler into a
* {@link ChannelPipeline}.
*/
protected CombinedChannelDuplexHandler() { }
/**
* Creates a new instance that combines the specified two handlers into one.
*/
public CombinedChannelDuplexHandler(I inboundHandler, O outboundHandler) {
init(inboundHandler, outboundHandler);
}
/**
* Initialized this handler with the specified handlers.
*
* @throws IllegalStateException if this handler was not constructed via the default constructor or
* if this handler does not implement all required handler interfaces
* @throws IllegalArgumentException if the specified handlers cannot be combined into one due to a conflict
* in the type hierarchy
*/
protected final void init(I inboundHandler, O outboundHandler) {
validate(inboundHandler, outboundHandler);
this.inboundHandler = inboundHandler;
this.outboundHandler = outboundHandler;
}
@SuppressWarnings("InstanceofIncompatibleInterface")
private void validate(I inboundHandler, O outboundHandler) {
if (this.inboundHandler != null) {
throw new IllegalStateException(
"init() can not be invoked if " + CombinedChannelDuplexHandler.class.getSimpleName() +
" was constructed with non-default constructor.");
}
if (inboundHandler == null) {
throw new NullPointerException("inboundHandler");
}
if (outboundHandler == null) {
throw new NullPointerException("outboundHandler");
}
if (inboundHandler instanceof ChannelOutboundHandler) {
throw new IllegalArgumentException(
"inboundHandler must not implement " +
ChannelOutboundHandler.class.getSimpleName() + " to get combined.");
}
if (outboundHandler instanceof ChannelInboundHandler) {
throw new IllegalArgumentException(
"outboundHandler must not implement " +
ChannelInboundHandler.class.getSimpleName() + " to get combined.");
}
}
protected final I inboundHandler() {
return inboundHandler;
}
protected final O outboundHandler() {
return outboundHandler;
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
if (inboundHandler == null) {
throw new IllegalStateException(
"init() must be invoked before being added to a " + ChannelPipeline.class.getSimpleName() +
" if " + CombinedChannelDuplexHandler.class.getSimpleName() +
" was constructed with the default constructor.");
}
try {
inboundHandler.handlerAdded(ctx);
} finally {
outboundHandler.handlerAdded(ctx);
}
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
try {
inboundHandler.handlerRemoved(ctx);
} finally {
outboundHandler.handlerRemoved(ctx);
}
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
inboundHandler.channelRegistered(ctx);
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
inboundHandler.channelActive(ctx);
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
inboundHandler.channelInactive(ctx);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
inboundHandler.exceptionCaught(ctx, cause);
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
inboundHandler.userEventTriggered(ctx, evt);
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
inboundHandler.channelRead(ctx, msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
inboundHandler.channelReadComplete(ctx);
}
@Override
public void bind(
ChannelHandlerContext ctx,
SocketAddress localAddress, ChannelPromise promise) throws Exception {
outboundHandler.bind(ctx, localAddress, promise);
}
@Override
public void connect(
ChannelHandlerContext ctx,
SocketAddress remoteAddress, SocketAddress localAddress,
ChannelPromise promise) throws Exception {
outboundHandler.connect(ctx, remoteAddress, localAddress, promise);
}
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
outboundHandler.disconnect(ctx, promise);
}
@Override
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
outboundHandler.close(ctx, promise);
}
@Override
public void read(ChannelHandlerContext ctx) throws Exception {
outboundHandler.read(ctx);
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
outboundHandler.write(ctx, msg, promise);
}
@Override
public void flush(ChannelHandlerContext ctx) throws Exception {
outboundHandler.flush(ctx);
}
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
inboundHandler.channelWritabilityChanged(ctx);
}
}

View File

@ -16,13 +16,160 @@
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandler.Skip;
import io.netty.util.DefaultAttributeMap; import io.netty.util.DefaultAttributeMap;
import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.EventExecutor;
import io.netty.util.internal.PlatformDependent;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.WeakHashMap;
final class DefaultChannelHandlerContext extends DefaultAttributeMap implements ChannelHandlerContext { final class DefaultChannelHandlerContext extends DefaultAttributeMap implements ChannelHandlerContext {
// This class keeps an integer member field 'skipFlags' whose each bit tells if the corresponding handler method
// is annotated with @Skip. 'skipFlags' is retrieved in runtime via the reflection API and is cached.
// The following constants signify which bit of 'skipFlags' corresponds to which handler method:
static final int MASK_HANDLER_ADDED = 1;
static final int MASK_HANDLER_REMOVED = 1 << 1;
private static final int MASK_EXCEPTION_CAUGHT = 1 << 2;
private static final int MASK_CHANNEL_REGISTERED = 1 << 3;
private static final int MASK_CHANNEL_ACTIVE = 1 << 4;
private static final int MASK_CHANNEL_INACTIVE = 1 << 5;
private static final int MASK_CHANNEL_READ = 1 << 6;
private static final int MASK_CHANNEL_READ_COMPLETE = 1 << 7;
private static final int MASK_CHANNEL_WRITABILITY_CHANGED = 1 << 8;
private static final int MASK_USER_EVENT_TRIGGERED = 1 << 9;
private static final int MASK_BIND = 1 << 10;
private static final int MASK_CONNECT = 1 << 11;
private static final int MASK_DISCONNECT = 1 << 12;
private static final int MASK_CLOSE = 1 << 13;
private static final int MASK_READ = 1 << 14;
private static final int MASK_WRITE = 1 << 15;
private static final int MASK_FLUSH = 1 << 16;
/**
* Cache the result of the costly generation of {@link #skipFlags} in the partitioned synchronized
* {@link WeakHashMap}.
*/
@SuppressWarnings("unchecked")
private static final WeakHashMap<Class<?>, Integer>[] skipFlagsCache =
new WeakHashMap[Runtime.getRuntime().availableProcessors()];
static {
for (int i = 0; i < skipFlagsCache.length; i ++) {
skipFlagsCache[i] = new WeakHashMap<Class<?>, Integer>();
}
}
/**
* Returns an integer bitset that tells which handler methods were annotated with {@link Skip}.
* It gets the value from {@link #skipFlagsCache} if an handler of the same type were queried before.
* Otherwise, it delegates to {@link #skipFlags0(Class)} to get it.
*/
private static int skipFlags(ChannelHandler handler) {
WeakHashMap<Class<?>, Integer> cache =
skipFlagsCache[(int) (Thread.currentThread().getId() % skipFlagsCache.length)];
Class<? extends ChannelHandler> handlerType = handler.getClass();
int flagsVal;
synchronized (cache) {
Integer flags = cache.get(handlerType);
if (flags != null) {
flagsVal = flags;
} else {
flagsVal = skipFlags0(handlerType);
cache.put(handlerType, Integer.valueOf(flagsVal));
}
}
return flagsVal;
}
/**
* Determines the {@link #skipFlags} of the specified {@code handlerType} using the reflection API.
*/
private static int skipFlags0(Class<? extends ChannelHandler> handlerType) {
int flags = 0;
try {
if (handlerType.getMethod(
"handlerAdded", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_HANDLER_ADDED;
}
if (handlerType.getMethod(
"handlerRemoved", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_HANDLER_REMOVED;
}
if (handlerType.getMethod(
"exceptionCaught", ChannelHandlerContext.class, Throwable.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_EXCEPTION_CAUGHT;
}
if (handlerType.getMethod(
"channelRegistered", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CHANNEL_REGISTERED;
}
if (handlerType.getMethod(
"channelActive", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CHANNEL_ACTIVE;
}
if (handlerType.getMethod(
"channelInactive", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CHANNEL_INACTIVE;
}
if (handlerType.getMethod(
"channelRead", ChannelHandlerContext.class, Object.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CHANNEL_READ;
}
if (handlerType.getMethod(
"channelReadComplete", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CHANNEL_READ_COMPLETE;
}
if (handlerType.getMethod(
"channelWritabilityChanged", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CHANNEL_WRITABILITY_CHANGED;
}
if (handlerType.getMethod(
"userEventTriggered", ChannelHandlerContext.class, Object.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_USER_EVENT_TRIGGERED;
}
if (handlerType.getMethod(
"bind", ChannelHandlerContext.class,
SocketAddress.class, ChannelPromise.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_BIND;
}
if (handlerType.getMethod(
"connect", ChannelHandlerContext.class, SocketAddress.class, SocketAddress.class,
ChannelPromise.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CONNECT;
}
if (handlerType.getMethod(
"disconnect", ChannelHandlerContext.class, ChannelPromise.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_DISCONNECT;
}
if (handlerType.getMethod(
"close", ChannelHandlerContext.class, ChannelPromise.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_CLOSE;
}
if (handlerType.getMethod(
"read", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_READ;
}
if (handlerType.getMethod(
"write", ChannelHandlerContext.class,
Object.class, ChannelPromise.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_WRITE;
}
if (handlerType.getMethod(
"flush", ChannelHandlerContext.class).isAnnotationPresent(Skip.class)) {
flags |= MASK_FLUSH;
}
} catch (Exception e) {
// Should never reach here.
PlatformDependent.throwException(e);
}
return flags;
}
volatile DefaultChannelHandlerContext next; volatile DefaultChannelHandlerContext next;
volatile DefaultChannelHandlerContext prev; volatile DefaultChannelHandlerContext prev;
@ -32,6 +179,8 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
private final ChannelHandler handler; private final ChannelHandler handler;
private boolean removed; private boolean removed;
final int skipFlags;
// Will be set to null if no child executor should be used, otherwise it will be set to the // Will be set to null if no child executor should be used, otherwise it will be set to the
// child executor. // child executor.
final ChannelHandlerInvoker invoker; final ChannelHandlerInvoker invoker;
@ -58,6 +207,8 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
this.name = name; this.name = name;
this.handler = handler; this.handler = handler;
skipFlags = skipFlags(handler);
if (invoker == null) { if (invoker == null) {
this.invoker = channel.unsafe().invoker(); this.invoker = channel.unsafe().invoker();
} else { } else {
@ -110,6 +261,11 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
return invoker.executor(); return invoker.executor();
} }
@Override
public ChannelHandlerInvoker invoker() {
return invoker;
}
@Override @Override
public ChannelHandler handler() { public ChannelHandler handler() {
return handler; return handler;
@ -122,56 +278,56 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
@Override @Override
public ChannelHandlerContext fireChannelRegistered() { public ChannelHandlerContext fireChannelRegistered() {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_REGISTERED);
next.invoker.invokeChannelRegistered(next); next.invoker.invokeChannelRegistered(next);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireChannelActive() { public ChannelHandlerContext fireChannelActive() {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_ACTIVE);
next.invoker.invokeChannelActive(next); next.invoker.invokeChannelActive(next);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireChannelInactive() { public ChannelHandlerContext fireChannelInactive() {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_INACTIVE);
next.invoker.invokeChannelInactive(next); next.invoker.invokeChannelInactive(next);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireExceptionCaught(Throwable cause) { public ChannelHandlerContext fireExceptionCaught(Throwable cause) {
DefaultChannelHandlerContext next = this.next; DefaultChannelHandlerContext next = findContextInbound(MASK_EXCEPTION_CAUGHT);
next.invoker.invokeExceptionCaught(next, cause); next.invoker.invokeExceptionCaught(next, cause);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireUserEventTriggered(Object event) { public ChannelHandlerContext fireUserEventTriggered(Object event) {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_USER_EVENT_TRIGGERED);
next.invoker.invokeUserEventTriggered(next, event); next.invoker.invokeUserEventTriggered(next, event);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireChannelRead(Object msg) { public ChannelHandlerContext fireChannelRead(Object msg) {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_READ);
next.invoker.invokeChannelRead(next, msg); next.invoker.invokeChannelRead(next, msg);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireChannelReadComplete() { public ChannelHandlerContext fireChannelReadComplete() {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_READ_COMPLETE);
next.invoker.invokeChannelReadComplete(next); next.invoker.invokeChannelReadComplete(next);
return this; return this;
} }
@Override @Override
public ChannelHandlerContext fireChannelWritabilityChanged() { public ChannelHandlerContext fireChannelWritabilityChanged() {
DefaultChannelHandlerContext next = findContextInbound(); DefaultChannelHandlerContext next = findContextInbound(MASK_CHANNEL_WRITABILITY_CHANGED);
next.invoker.invokeChannelWritabilityChanged(next); next.invoker.invokeChannelWritabilityChanged(next);
return this; return this;
} }
@ -203,7 +359,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
@Override @Override
public ChannelFuture bind(final SocketAddress localAddress, final ChannelPromise promise) { public ChannelFuture bind(final SocketAddress localAddress, final ChannelPromise promise) {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_BIND);
next.invoker.invokeBind(next, localAddress, promise); next.invoker.invokeBind(next, localAddress, promise);
return promise; return promise;
} }
@ -215,7 +371,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
@Override @Override
public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) { public ChannelFuture connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_CONNECT);
next.invoker.invokeConnect(next, remoteAddress, localAddress, promise); next.invoker.invokeConnect(next, remoteAddress, localAddress, promise);
return promise; return promise;
} }
@ -226,21 +382,21 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
return close(promise); return close(promise);
} }
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_DISCONNECT);
next.invoker.invokeDisconnect(next, promise); next.invoker.invokeDisconnect(next, promise);
return promise; return promise;
} }
@Override @Override
public ChannelFuture close(ChannelPromise promise) { public ChannelFuture close(ChannelPromise promise) {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_CLOSE);
next.invoker.invokeClose(next, promise); next.invoker.invokeClose(next, promise);
return promise; return promise;
} }
@Override @Override
public ChannelHandlerContext read() { public ChannelHandlerContext read() {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_READ);
next.invoker.invokeRead(next); next.invoker.invokeRead(next);
return this; return this;
} }
@ -252,22 +408,25 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
@Override @Override
public ChannelFuture write(Object msg, ChannelPromise promise) { public ChannelFuture write(Object msg, ChannelPromise promise) {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_WRITE);
next.invoker.invokeWrite(next, msg, promise); next.invoker.invokeWrite(next, msg, promise);
return promise; return promise;
} }
@Override @Override
public ChannelHandlerContext flush() { public ChannelHandlerContext flush() {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next = findContextOutbound(MASK_FLUSH);
next.invoker.invokeFlush(next); next.invoker.invokeFlush(next);
return this; return this;
} }
@Override @Override
public ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) { public ChannelFuture writeAndFlush(Object msg, ChannelPromise promise) {
DefaultChannelHandlerContext next = findContextOutbound(); DefaultChannelHandlerContext next;
next.invoker.invokeWriteAndFlush(next, msg, promise); next = findContextOutbound(MASK_WRITE);
next.invoker.invokeWrite(next, msg, promise);
next = findContextOutbound(MASK_FLUSH);
next.invoker.invokeFlush(next);
return promise; return promise;
} }
@ -300,19 +459,19 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
return new FailedChannelFuture(channel(), executor(), cause); return new FailedChannelFuture(channel(), executor(), cause);
} }
private DefaultChannelHandlerContext findContextInbound() { private DefaultChannelHandlerContext findContextInbound(int mask) {
DefaultChannelHandlerContext ctx = this; DefaultChannelHandlerContext ctx = this;
do { do {
ctx = ctx.next; ctx = ctx.next;
} while (!(ctx.handler instanceof ChannelInboundHandler)); } while ((ctx.skipFlags & mask) != 0);
return ctx; return ctx;
} }
private DefaultChannelHandlerContext findContextOutbound() { private DefaultChannelHandlerContext findContextOutbound(int mask) {
DefaultChannelHandlerContext ctx = this; DefaultChannelHandlerContext ctx = this;
do { do {
ctx = ctx.prev; ctx = ctx.prev;
} while (!(ctx.handler instanceof ChannelOutboundHandler)); } while ((ctx.skipFlags & mask) != 0);
return ctx; return ctx;
} }

View File

@ -283,16 +283,9 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
} }
validatePromise(ctx, promise, true); validatePromise(ctx, promise, true);
invokeWrite(ctx, msg, false, promise);
}
private void invokeWrite(ChannelHandlerContext ctx, Object msg, boolean flush, ChannelPromise promise) {
if (executor.inEventLoop()) { if (executor.inEventLoop()) {
invokeWriteNow(ctx, msg, promise); invokeWriteNow(ctx, msg, promise);
if (flush) {
invokeFlushNow(ctx);
}
} else { } else {
AbstractChannel channel = (AbstractChannel) ctx.channel(); AbstractChannel channel = (AbstractChannel) ctx.channel();
int size = channel.estimatorHandle().size(msg); int size = channel.estimatorHandle().size(msg);
@ -303,7 +296,7 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
buffer.incrementPendingOutboundBytes(size); buffer.incrementPendingOutboundBytes(size);
} }
} }
safeExecuteOutbound(WriteTask.newInstance(ctx, msg, size, flush, promise), promise, msg); safeExecuteOutbound(WriteTask.newInstance(ctx, msg, size, promise), promise, msg);
} }
} }
@ -326,17 +319,6 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
} }
} }
@Override
public void invokeWriteAndFlush(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
if (msg == null) {
throw new NullPointerException("msg");
}
validatePromise(ctx, promise, true);
invokeWrite(ctx, msg, true, promise);
}
private static void validatePromise(ChannelHandlerContext ctx, ChannelPromise promise, boolean allowVoidPromise) { private static void validatePromise(ChannelHandlerContext ctx, ChannelPromise promise, boolean allowVoidPromise) {
if (ctx == null) { if (ctx == null) {
throw new NullPointerException("ctx"); throw new NullPointerException("ctx");
@ -406,7 +388,6 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
private Object msg; private Object msg;
private ChannelPromise promise; private ChannelPromise promise;
private int size; private int size;
private boolean flush;
private static final Recycler<WriteTask> RECYCLER = new Recycler<WriteTask>() { private static final Recycler<WriteTask> RECYCLER = new Recycler<WriteTask>() {
@Override @Override
@ -416,13 +397,12 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
}; };
private static WriteTask newInstance( private static WriteTask newInstance(
ChannelHandlerContext ctx, Object msg, int size, boolean flush, ChannelPromise promise) { ChannelHandlerContext ctx, Object msg, int size, ChannelPromise promise) {
WriteTask task = RECYCLER.get(); WriteTask task = RECYCLER.get();
task.ctx = ctx; task.ctx = ctx;
task.msg = msg; task.msg = msg;
task.promise = promise; task.promise = promise;
task.size = size; task.size = size;
task.flush = flush;
return task; return task;
} }
@ -443,9 +423,6 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
} }
} }
invokeWriteNow(ctx, msg, promise); invokeWriteNow(ctx, msg, promise);
if (flush) {
invokeFlushNow(ctx);
}
} finally { } finally {
// Set to null so the GC can collect them directly // Set to null so the GC can collect them directly
ctx = null; ctx = null;

View File

@ -324,7 +324,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
return invoker; return invoker;
} }
private String generateName(ChannelHandler handler) { String generateName(ChannelHandler handler) {
WeakHashMap<Class<?>, String> cache = nameCaches[(int) (Thread.currentThread().getId() % nameCaches.length)]; WeakHashMap<Class<?>, String> cache = nameCaches[(int) (Thread.currentThread().getId() % nameCaches.length)];
Class<?> handlerType = handler.getClass(); Class<?> handlerType = handler.getClass();
String name; String name;
@ -529,7 +529,11 @@ final class DefaultChannelPipeline implements ChannelPipeline {
} }
} }
private void callHandlerAdded(final ChannelHandlerContext ctx) { private void callHandlerAdded(final DefaultChannelHandlerContext ctx) {
if ((ctx.skipFlags & DefaultChannelHandlerContext.MASK_HANDLER_ADDED) != 0) {
return;
}
if (ctx.channel().isRegistered() && !ctx.executor().inEventLoop()) { if (ctx.channel().isRegistered() && !ctx.executor().inEventLoop()) {
ctx.executor().execute(new Runnable() { ctx.executor().execute(new Runnable() {
@Override @Override
@ -542,13 +546,13 @@ final class DefaultChannelPipeline implements ChannelPipeline {
callHandlerAdded0(ctx); callHandlerAdded0(ctx);
} }
private void callHandlerAdded0(final ChannelHandlerContext ctx) { private void callHandlerAdded0(final DefaultChannelHandlerContext ctx) {
try { try {
ctx.handler().handlerAdded(ctx); ctx.handler().handlerAdded(ctx);
} catch (Throwable t) { } catch (Throwable t) {
boolean removed = false; boolean removed = false;
try { try {
remove((DefaultChannelHandlerContext) ctx); remove(ctx);
removed = true; removed = true;
} catch (Throwable t2) { } catch (Throwable t2) {
if (logger.isWarnEnabled()) { if (logger.isWarnEnabled()) {
@ -569,6 +573,10 @@ final class DefaultChannelPipeline implements ChannelPipeline {
} }
private void callHandlerRemoved(final DefaultChannelHandlerContext ctx) { private void callHandlerRemoved(final DefaultChannelHandlerContext ctx) {
if ((ctx.skipFlags & DefaultChannelHandlerContext.MASK_HANDLER_REMOVED) != 0) {
return;
}
if (ctx.channel().isRegistered() && !ctx.executor().inEventLoop()) { if (ctx.channel().isRegistered() && !ctx.executor().inEventLoop()) {
ctx.executor().execute(new Runnable() { ctx.executor().execute(new Runnable() {
@Override @Override
@ -970,7 +978,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
} }
// A special catch-all handler that handles both bytes and messages. // A special catch-all handler that handles both bytes and messages.
static final class TailHandler implements ChannelInboundHandler { static final class TailHandler extends ChannelHandlerAdapter {
@Override @Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception { } public void channelRegistered(ChannelHandlerContext ctx) throws Exception { }
@ -984,12 +992,6 @@ final class DefaultChannelPipeline implements ChannelPipeline {
@Override @Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { } public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { }
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception { }
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { }
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { } public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { }
@ -1015,7 +1017,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { } public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { }
} }
static final class HeadHandler implements ChannelOutboundHandler { static final class HeadHandler extends ChannelHandlerAdapter {
protected final Unsafe unsafe; protected final Unsafe unsafe;
@ -1023,16 +1025,6 @@ final class DefaultChannelPipeline implements ChannelPipeline {
this.unsafe = unsafe; this.unsafe = unsafe;
} }
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
// NOOP
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
// NOOP
}
@Override @Override
public void bind( public void bind(
ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise) ChannelHandlerContext ctx, SocketAddress localAddress, ChannelPromise promise)
@ -1072,10 +1064,5 @@ final class DefaultChannelPipeline implements ChannelPipeline {
public void flush(ChannelHandlerContext ctx) throws Exception { public void flush(ChannelHandlerContext ctx) throws Exception {
unsafe.flush(); unsafe.flush();
} }
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.fireExceptionCaught(cause);
}
} }
} }

View File

@ -19,7 +19,7 @@ import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.TypeParameterMatcher; import io.netty.util.internal.TypeParameterMatcher;
/** /**
* {@link ChannelInboundHandlerAdapter} which allows to explicit only handle a specific type of messages. * {@link ChannelHandler} which allows to explicit only handle a specific type of messages.
* *
* For example here is an implementation which only handle {@link String} messages. * For example here is an implementation which only handle {@link String} messages.
* *
@ -43,7 +43,7 @@ import io.netty.util.internal.TypeParameterMatcher;
* {@link #messageReceived(ChannelHandlerContext, Object)}. * {@link #messageReceived(ChannelHandlerContext, Object)}.
* </p> * </p>
*/ */
public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandlerAdapter { public abstract class SimpleChannelInboundHandler<I> extends ChannelHandlerAdapter {
private final TypeParameterMatcher matcher; private final TypeParameterMatcher matcher;
private final boolean autoRelease; private final boolean autoRelease;
@ -87,7 +87,7 @@ public abstract class SimpleChannelInboundHandler<I> extends ChannelInboundHandl
/** /**
* Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next * Returns {@code true} if the given message should be handled. If {@code false} it will be passed to the next
* {@link ChannelInboundHandler} in the {@link ChannelPipeline}. * {@link ChannelHandler} in the {@link ChannelPipeline}.
*/ */
public boolean acceptInboundMessage(Object msg) throws Exception { public boolean acceptInboundMessage(Object msg) throws Exception {
return matcher.match(msg); return matcher.match(msg);

View File

@ -20,8 +20,8 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer; import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
@ -345,7 +345,7 @@ public class EmbeddedChannel extends AbstractChannel {
} }
} }
private final class LastInboundHandler extends ChannelInboundHandlerAdapter { private final class LastInboundHandler extends ChannelHandlerAdapter {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
inboundMessages.add(msg); inboundMessages.add(msg);

View File

@ -184,11 +184,6 @@ final class EmbeddedEventLoop extends AbstractEventLoop implements ChannelHandle
invokeWriteNow(ctx, msg, promise); invokeWriteNow(ctx, msg, promise);
} }
@Override
public void invokeWriteAndFlush(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
invokeWriteAndFlushNow(ctx, msg, promise);
}
@Override @Override
public void invokeFlush(ChannelHandlerContext ctx) { public void invokeFlush(ChannelHandlerContext ctx) {
invokeFlushNow(ctx); invokeFlushNow(ctx);

View File

@ -15,7 +15,7 @@
*/ */
/** /**
* A virtual {@link Channel} that helps wrapping a series of handlers to * A virtual {@link io.netty.channel.Channel} that helps wrapping a series of handlers to
* unit test the handlers or use them in non-I/O context. * unit test the handlers or use them in non-I/O context.
*/ */
package io.netty.channel.embedded; package io.netty.channel.embedded;

View File

@ -20,9 +20,9 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder; import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId; import io.netty.channel.ChannelId;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.GlobalEventExecutor;
@ -82,7 +82,7 @@ import java.util.Set;
* b.releaseExternalResources(); * b.releaseExternalResources();
* } * }
* *
* public class MyHandler extends {@link ChannelInboundHandlerAdapter} { * public class MyHandler extends {@link ChannelHandlerAdapter} {
* {@code @Override} * {@code @Override}
* public void channelActive({@link ChannelHandlerContext} ctx) { * public void channelActive({@link ChannelHandlerContext} ctx) {
* // closed on shutdown. * // closed on shutdown.

View File

@ -15,12 +15,12 @@
*/ */
package io.netty.channel.socket; package io.netty.channel.socket;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
/** /**
* Special event which will be fired and passed to the * Special event which will be fired and passed to the
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} methods once the input of * {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)} methods once the input of
* a {@link SocketChannel} was shutdown and the {@link SocketChannelConfig#isAllowHalfClosure()} method returns * a {@link SocketChannel} was shutdown and the {@link SocketChannelConfig#isAllowHalfClosure()} method returns
* {@code true}. * {@code true}.
*/ */

View File

@ -17,8 +17,8 @@ package io.netty.channel.socket;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelConfig; import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.MessageSizeEstimator; import io.netty.channel.MessageSizeEstimator;
import io.netty.channel.RecvByteBufAllocator; import io.netty.channel.RecvByteBufAllocator;
@ -151,7 +151,7 @@ public interface SocketChannelConfig extends ChannelConfig {
* Sets whether the channel should not close itself when its remote peer shuts down output to * Sets whether the channel should not close itself when its remote peer shuts down output to
* make the connection half-closed. If {@code true} the connection is not closed when the * make the connection half-closed. If {@code true} the connection is not closed when the
* remote peer shuts down output. Instead, * remote peer shuts down output. Instead,
* {@link ChannelInboundHandler#userEventTriggered(ChannelHandlerContext, Object)} * {@link ChannelHandler#userEventTriggered(ChannelHandlerContext, Object)}
* is invoked with a {@link ChannelInputShutdownEvent} object. If {@code false}, the connection * is invoked with a {@link ChannelInputShutdownEvent} object. If {@code false}, the connection
* is closed automatically. * is closed automatically.
*/ */

View File

@ -16,9 +16,9 @@
package io.netty.bootstrap; package io.netty.bootstrap;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelInboundHandler; import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalAddress;
@ -37,7 +37,7 @@ public class BootstrapTest {
EventLoopGroup groupB = new DefaultEventLoopGroup(1); EventLoopGroup groupB = new DefaultEventLoopGroup(1);
try { try {
ChannelInboundHandler dummyHandler = new DummyHandler(); ChannelHandler dummyHandler = new DummyHandler();
final Bootstrap bootstrapA = new Bootstrap(); final Bootstrap bootstrapA = new Bootstrap();
bootstrapA.group(groupA); bootstrapA.group(groupA);
@ -85,7 +85,7 @@ public class BootstrapTest {
EventLoopGroup groupB = new DefaultEventLoopGroup(1); EventLoopGroup groupB = new DefaultEventLoopGroup(1);
try { try {
ChannelInboundHandler dummyHandler = new DummyHandler(); ChannelHandler dummyHandler = new DummyHandler();
final Bootstrap bootstrapA = new Bootstrap(); final Bootstrap bootstrapA = new Bootstrap();
bootstrapA.group(groupA); bootstrapA.group(groupA);
@ -128,5 +128,5 @@ public class BootstrapTest {
} }
@Sharable @Sharable
private static final class DummyHandler extends ChannelInboundHandlerAdapter { } private static final class DummyHandler extends ChannelHandlerAdapter { }
} }

View File

@ -56,7 +56,7 @@ public class DefaultChannelPipelineTest {
final AtomicReference<Channel> peerRef = new AtomicReference<Channel>(); final AtomicReference<Channel> peerRef = new AtomicReference<Channel>();
ServerBootstrap sb = new ServerBootstrap(); ServerBootstrap sb = new ServerBootstrap();
sb.group(group).channel(LocalServerChannel.class); sb.group(group).channel(LocalServerChannel.class);
sb.childHandler(new ChannelInboundHandlerAdapter() { sb.childHandler(new ChannelHandlerAdapter() {
@Override @Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception { public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
peerRef.set(ctx.channel()); peerRef.set(ctx.channel());
@ -116,7 +116,7 @@ public class DefaultChannelPipelineTest {
assertTrue(handler.called); assertTrue(handler.called);
} }
private static final class StringInboundHandler extends ChannelInboundHandlerAdapter { private static final class StringInboundHandler extends ChannelHandlerAdapter {
boolean called; boolean called;
@Override @Override
@ -194,7 +194,7 @@ public class DefaultChannelPipelineTest {
pipeline.addLast(new ChannelInitializer<Channel>() { pipeline.addLast(new ChannelInitializer<Channel>() {
@Override @Override
protected void initChannel(Channel ch) throws Exception { protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { ch.pipeline().addLast(new ChannelHandlerAdapter() {
@Override @Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception { public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
latch.countDown(); latch.countDown();
@ -473,9 +473,9 @@ public class DefaultChannelPipelineTest {
} }
@Sharable @Sharable
private static class TestHandler extends ChannelDuplexHandler { } private static class TestHandler extends ChannelHandlerAdapter { }
private static class BufferedTestHandler extends ChannelDuplexHandler { private static class BufferedTestHandler extends ChannelHandlerAdapter {
final Queue<Object> inboundBuffer = new ArrayDeque<Object>(); final Queue<Object> inboundBuffer = new ArrayDeque<Object>();
final Queue<Object> outboundBuffer = new ArrayDeque<Object>(); final Queue<Object> outboundBuffer = new ArrayDeque<Object>();

View File

@ -19,10 +19,12 @@ import java.net.SocketAddress;
import java.util.Collections; import java.util.Collections;
import java.util.EnumSet; import java.util.EnumSet;
final class LoggingHandler implements ChannelInboundHandler, ChannelOutboundHandler { final class LoggingHandler implements ChannelHandler {
static enum Event { WRITE, FLUSH, BIND, CONNECT, DISCONNECT, CLOSE, READ, WRITABILITY, HANDLER_ADDED, enum Event {
HANDLER_REMOVED, EXCEPTION, READ_COMPLETE, REGISTERED, ACTIVE, INACTIVE, USER }; WRITE, FLUSH, BIND, CONNECT, DISCONNECT, CLOSE, READ, WRITABILITY, HANDLER_ADDED,
HANDLER_REMOVED, EXCEPTION, READ_COMPLETE, REGISTERED, ACTIVE, INACTIVE, USER
}
private StringBuilder log = new StringBuilder(); private StringBuilder log = new StringBuilder();

View File

@ -15,19 +15,17 @@
*/ */
package io.netty.channel; package io.netty.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.LoggingHandler.Event; import io.netty.channel.LoggingHandler.Event;
import io.netty.channel.local.LocalAddress; import io.netty.channel.local.LocalAddress;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import org.junit.Test;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
import org.junit.Test; import static org.junit.Assert.*;
public class ReentrantChannelTest extends BaseChannelTest { public class ReentrantChannelTest extends BaseChannelTest {
@ -78,7 +76,7 @@ public class ReentrantChannelTest extends BaseChannelTest {
clientChannel.config().setWriteBufferLowWaterMark(512); clientChannel.config().setWriteBufferLowWaterMark(512);
clientChannel.config().setWriteBufferHighWaterMark(1024); clientChannel.config().setWriteBufferHighWaterMark(1024);
clientChannel.pipeline().addLast(new ChannelInboundHandlerAdapter() { clientChannel.pipeline().addLast(new ChannelHandlerAdapter() {
@Override @Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception { public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
if (!ctx.channel().isWritable()) { if (!ctx.channel().isWritable()) {
@ -116,7 +114,7 @@ public class ReentrantChannelTest extends BaseChannelTest {
Channel clientChannel = cb.connect(addr).sync().channel(); Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() { clientChannel.pipeline().addLast(new ChannelHandlerAdapter() {
int writeCount; int writeCount;
int flushCount; int flushCount;
@ -173,7 +171,7 @@ public class ReentrantChannelTest extends BaseChannelTest {
Channel clientChannel = cb.connect(addr).sync().channel(); Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() { clientChannel.pipeline().addLast(new ChannelHandlerAdapter() {
@Override @Override
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
@ -211,7 +209,7 @@ public class ReentrantChannelTest extends BaseChannelTest {
Channel clientChannel = cb.connect(addr).sync().channel(); Channel clientChannel = cb.connect(addr).sync().channel();
clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() { clientChannel.pipeline().addLast(new ChannelHandlerAdapter() {
@Override @Override
public void flush(ChannelHandlerContext ctx) throws Exception { public void flush(ChannelHandlerContext ctx) throws Exception {

View File

@ -17,8 +17,8 @@ package io.netty.channel.group;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
@ -37,7 +37,7 @@ public class DefaultChannnelGroupTest {
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup); b.group(bossGroup, workerGroup);
b.childHandler(new ChannelInboundHandlerAdapter() { b.childHandler(new ChannelHandlerAdapter() {
@Override @Override
public void channelActive(ChannelHandlerContext ctx) { public void channelActive(ChannelHandlerContext ctx) {
allChannels.add(ctx.channel()); allChannels.add(ctx.channel());

Some files were not shown because too many files have changed in this diff Show More