Java Code Examples for io.netty.channel.ChannelHandlerContext#fireChannelRegistered()

The following examples show how to use io.netty.channel.ChannelHandlerContext#fireChannelRegistered() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtocolNegotiators.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
  }
}
 
Example 2
Source File: HeartbeatChannelHandler.java    From sailfish with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
	if (ctx.channel().isActive()) {
		ctx.channel().attr(ChannelAttrKeys.lastReadTimeMillis).set(System.currentTimeMillis());
	}
	ctx.fireChannelRegistered();
}
 
Example 3
Source File: ChannelMetricsHandler.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
	if (!onServer) {
		ctx.pipeline()
		   .addAfter(NettyPipeline.ChannelMetricsHandler,
		             NettyPipeline.ConnectMetricsHandler,
		             new ConnectMetricsHandler(recorder));
	}

	ctx.fireChannelRegistered();
}
 
Example 4
Source File: NettyServer.java    From util4j with Apache License 2.0 5 votes vote down vote up
/**
	 * 初始化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;
	}
 
Example 5
Source File: NettyClient.java    From util4j with Apache License 2.0 5 votes vote down vote up
/**
 * 包装一个初始化父类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;
}
 
Example 6
Source File: WebSocketServerTextAdapterHandler.java    From util4j with Apache License 2.0 5 votes vote down vote up
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
	ctx.channel().pipeline().addLast(new WebSocketTextFrameStringAdapter());//适配器
	ctx.channel().pipeline().addLast(handler);
	//为新加的handler手动触发必要事件
	ctx.fireChannelRegistered();
	ctx.fireChannelActive();
}
 
Example 7
Source File: RntbdRequestManager.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
/**
 * 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();
}
 
Example 8
Source File: ChannelManagerHandler.java    From iot-dc with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 9
Source File: LoggingHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    if (logger.isEnabled(internalLevel)) {
        logger.log(internalLevel, format(ctx, "REGISTERED"));
    }
    ctx.fireChannelRegistered();
}
 
Example 10
Source File: SslProvider.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 11
Source File: FilterLogginglHandler.java    From netty-http-server with Apache License 2.0 4 votes vote down vote up
public void channelRegistered(ChannelHandlerContext ctx) {
    ctx.fireChannelRegistered();
}
 
Example 12
Source File: Netty4ChannelHandlerAdapter.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext nettyctx) throws Exception {
    nettyctx.fireChannelRegistered();
}
 
Example 13
Source File: ReliableChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
  Gdx.app.debug(TAG, "channelRegistered");
  ctx.fireChannelRegistered();
}
 
Example 14
Source File: TrafficLoggingHandler.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    ctx.fireChannelRegistered();
}
 
Example 15
Source File: NettyChannelHandlerAdapter.java    From Ak47 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext nettyctx) throws Exception {
    log.debug("channelRegistered().");
    
    nettyctx.fireChannelRegistered();
}
 
Example 16
Source File: ReliableChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
  Gdx.app.debug(TAG, "channelRegistered");
  ctx.fireChannelRegistered();
}
 
Example 17
Source File: Http1ResponseDecoder.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    maybeInitializeKeepAliveHandler(ctx);
    ctx.fireChannelRegistered();
}
 
Example 18
Source File: HandlerPublisher.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    provideChannelContext(ctx);
    ctx.fireChannelRegistered();
}
 
Example 19
Source File: EndpointedChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "channelRegistered");
  ctx.fireChannelRegistered();
}
 
Example 20
Source File: ExceptionChannelHandler.java    From journalkeeper with Apache License 2.0 4 votes vote down vote up
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    ctx.fireChannelRegistered();
}