C - A sub-type of Channel@ChannelHandler.Sharable public abstract class ChannelInitializer<C extends Channel> extends ChannelHandlerAdapter
ChannelHandler which offers an easy way to initialize a Channel once it was
registered to its EventLoop.
Implementations are most often used in the context of AbstractBootstrap.handler(ChannelHandler) ,
AbstractBootstrap.handler(ChannelHandler) and ServerBootstrap.childHandler(ChannelHandler) to
setup the ChannelPipeline of a Channel.
public class MyChannelInitializer extendsBe aware that this class is marked asChannelInitializer{ public void initChannel(Channelchannel) { channel.pipeline().addLast("myHandler", new MyHandler()); } }ServerBootstrapbootstrap = ...; ... bootstrap.childHandler(new MyChannelInitializer()); ...
ChannelHandler.Sharable and so the implementation must be safe to be re-used.ChannelHandler.Sharable, ChannelHandler.Skip| Constructor and Description |
|---|
ChannelInitializer() |
| Modifier and Type | Method and Description |
|---|---|
void |
channelRegistered(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelRegistered() to forward
to the next ChannelHandler in the ChannelPipeline. |
protected abstract void |
initChannel(C ch)
This method will be called once the
Channel was registered. |
bind, channelActive, channelInactive, channelRead, channelReadComplete, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, handlerRemoved, isSharable, read, userEventTriggered, writeprotected abstract void initChannel(C ch) throws Exception
Channel was registered. After the method returns this instance
will be removed from the ChannelPipeline of the Channel.public final void channelRegistered(ChannelHandlerContext ctx) throws Exception
ChannelHandlerAdapterChannelHandlerContext.fireChannelRegistered() to forward
to the next ChannelHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelRegistered in interface ChannelHandlerchannelRegistered in class ChannelHandlerAdapterExceptionCopyright © 2008–2015 The Netty Project. All rights reserved.