下面列出了io.netty.channel.ChannelHandlerContext#fireChannelRegistered ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* When this channel is registered, we will add all the ChannelHandlers passed into our
* constructor to the pipeline.
*/
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
/**
* This check is necessary as a channel may be registered with different event loops during it
* lifetime and we only want to configure it once.
*/
if (handlers != null) {
for (ChannelHandler handler : handlers) {
ctx.pipeline().addBefore(ctx.name(), null, handler);
}
ChannelHandler handler0 = handlers[0];
ChannelHandlerContext handler0Ctx = ctx.pipeline().context(handlers[0]);
handlers = null;
if (handler0Ctx != null) { // The handler may have removed itself immediately
if (handler0 instanceof ChannelInboundHandler) {
((ChannelInboundHandler) handler0).channelRegistered(handler0Ctx);
} else {
handler0Ctx.fireChannelRegistered();
}
}
} else {
super.channelRegistered(ctx);
}
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
ChannelHandler handler = ctx.pipeline().get(NettyPipeline.ChannelMetricsHandler);
if (handler != null) {
recorder = ((ChannelMetricsHandler) handler).recorder();
tlsHandshakeTimeStart = System.nanoTime();
}
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
if (logger.isEnabled(internalLevel)) {
logger.log(internalLevel, format(ctx, "REGISTERED"));
}
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
LOGGER.info("new channel coming! ----> {}", ctx.channel());
ChannelId channelId = ctx.channel().id();
RTUChannelInfo channelInfo = GlobalInfo.CHANNEL_INFO_MAP.getOrDefault(channelId, RTUChannelInfo.build("unknownSN", channelId));
GlobalInfo.CHANNEL_INFO_MAP.put(channelId, channelInfo);
ctx.fireChannelRegistered();
}
/**
* Constructs a {@link CoalescingBufferQueue} for buffering encoded requests until we have an {@link RntbdRequest}
* <p>
* This method then calls {@link ChannelHandlerContext#fireChannelRegistered()} to forward to the next
* {@link ChannelInboundHandler} in the {@link ChannelPipeline}.
* <p>
* Sub-classes may override this method to change behavior.
*
* @param context the {@link ChannelHandlerContext} for which the bind operation is made
*/
@Override
public void channelRegistered(final ChannelHandlerContext context) {
this.traceOperation(context, "channelRegistered");
reportIssueUnless(this.pendingWrites == null, context, "pendingWrites: {}", pendingWrites);
this.pendingWrites = new CoalescingBufferQueue(context.channel());
context.fireChannelRegistered();
}
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
ctx.channel().pipeline().addLast(new WebSocketTextFrameStringAdapter());//适配器
ctx.channel().pipeline().addLast(handler);
//为新加的handler手动触发必要事件
ctx.fireChannelRegistered();
ctx.fireChannelActive();
}
/**
* 包装一个初始化父类channel的handler
* @param handler 业务handler
* @return
*/
private ChannelHandler channelInitFix(final ChannelHandler handler)
{
ChannelHandler fixedHandler=new ShareableChannelInboundHandler() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
Channel ch=ctx.channel();
setChannel(ch);
ctx.pipeline().addLast(handler);
ctx.pipeline().remove(this);//移除当前handler
ctx.fireChannelRegistered();//从当前handler往后抛出事件
}
};
return fixedHandler;
}
/**
* 初始化handler适配包装
* @param init
* @return
*/
protected ChannelHandler initLogHandlerAdapter(ChannelHandler init)
{
ChannelHandler handler=new ShareableChannelInboundHandler() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
Channel ch=ctx.channel();
manageChannel(ch);
LogLevel level=config.getChannelLevel();
if(level!=null)
{//单个链路的日志记录器
ch.pipeline().addLast(new LoggerHandler(level));
}
ch.pipeline().addLast(init);
ctx.pipeline().remove(this);//移除当前handler
ctx.fireChannelRegistered();//从当前handler往后抛出事件
}
};
// ChannelHandler handler=new ChannelInitializer<Channel>() {
// @Override
// protected void initChannel(Channel ch) throws Exception {
// channelGroup.add(ch);
// LogLevel level=config.getLevel();
// if(level!=null)
// {
// ch.pipeline().addLast(new LoggerHandler(config.getLevel()));
// }
// ch.pipeline().addLast(init);
// }
// };
return handler;
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
if (!onServer) {
ctx.pipeline()
.addAfter(NettyPipeline.ChannelMetricsHandler,
NettyPipeline.ConnectMetricsHandler,
new ConnectMetricsHandler(recorder));
}
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
if (ctx.channel().isActive()) {
ctx.channel().attr(ChannelAttrKeys.lastReadTimeMillis).set(System.currentTimeMillis());
}
ctx.fireChannelRegistered();
}
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
Gdx.app.debug(TAG, "channelRegistered");
ctx.fireChannelRegistered();
}
public void channelRegistered(ChannelHandlerContext ctx) {
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext nettyctx) throws Exception {
nettyctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
Gdx.app.debug(TAG, "channelRegistered");
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext nettyctx) throws Exception {
log.debug("channelRegistered().");
nettyctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
maybeInitializeKeepAliveHandler(ctx);
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
provideChannelContext(ctx);
ctx.fireChannelRegistered();
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
if (DEBUG_CALLS) Gdx.app.debug(TAG, "channelRegistered");
ctx.fireChannelRegistered();
}