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

The following are Jave code examples for showing how to use fireChannelRegistered() of the io.netty.channel.ChannelHandlerContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: util4j   File: NettyBinaryWebSocketClient.java   View Source Code Vote up 6 votes
/**
	 * 适配
	 */
	@Override
	protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
		ChannelHandler result=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				ch.pipeline().addLast(new HttpClientCodec());
            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
				ctx.pipeline().remove(this);//移除当前handler
				ctx.fireChannelRegistered();//重新从第一个handler抛出事件
			}
		};
//		ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
//            @Override
//            protected void initChannel(SocketChannel ch) {
//            	ch.pipeline().addLast(new HttpClientCodec());
//            	ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
//            	ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
//            	ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
//            }
//        };
        return result;
	}
 
Example 2
Project: util4j   File: WebSocketServerTextAdapterHandler.java   View Source Code Vote up 5 votes
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
	ctx.channel().pipeline().addLast(new WebSocketTextFrameByteBufAdapter());//适配器
	ctx.channel().pipeline().addLast(handler);
	//为新加的handler手动触发必要事件
	ctx.fireChannelRegistered();
	ctx.fireChannelActive();
}
 
Example 3
Project: util4j   File: WebSocketClientTextAdapterHandler.java   View Source Code Vote up 5 votes
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
	ctx.channel().pipeline().addLast(new WebSocketTextFrameByteBufAdapter());//适配器
	ctx.channel().pipeline().addLast(handler);
	//为新加的handler手动触发必要事件
	ctx.fireChannelRegistered();
	ctx.fireChannelActive();
}
 
Example 4
Project: util4j   File: WebSocketClientBinaryAdapterHandler.java   View Source Code Vote up 5 votes
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
	ctx.channel().pipeline().addLast(new WebSocketBinaryFrameByteBufAdapter());//适配器
	ctx.channel().pipeline().addLast(handler);
	//为新加的handler手动触发必要事件
	ctx.fireChannelRegistered();
	ctx.fireChannelActive();
}
 
Example 5
Project: util4j   File: WebSocketServerBinaryAdapterHandler.java   View Source Code Vote up 5 votes
@Override
protected void webSocketHandComplete(ChannelHandlerContext ctx) {
	ctx.channel().pipeline().addLast(new WebSocketBinaryFrameByteBufAdapter());//适配器
	ctx.channel().pipeline().addLast(handler);
	//为新加的handler手动触发必要事件
	ctx.fireChannelRegistered();
	ctx.fireChannelActive();
}
 
Example 6
Project: util4j   File: NettyClient.java   View Source Code Vote up 5 votes
/**
 * 包装一个初始化父类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 7
Project: util4j   File: NettyTextWebSocketClient.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
		throws Exception {
	if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
		log.log(logLevel,"WebSocket:HANDSHAKE_COMPLETE,pipeline:"+ctx.channel().pipeline().toMap().toString());
		ctx.pipeline().addLast(new WebSocketTextFrameByteBufAdapter());//适配器
		ctx.pipeline().addLast(this.handler);//业务层handler
		//为新加的handler手动触发必要事件
		ctx.fireChannelRegistered();
		ctx.fireChannelActive();
		log.log(logLevel,"HANDSHAKE_COMPLETED HANDLERS:"+ctx.channel().pipeline().toMap().toString());
	}
	super.userEventTriggered(ctx, evt);
}
 
Example 8
Project: util4j   File: NettyBinaryWebSocketClient.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)
		throws Exception {
	if (evt == WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE) {
		log.log(logLevel,"WebSocket:HANDSHAKE_COMPLETE,pipeline:"+ctx.channel().pipeline().toMap().toString());
		ctx.pipeline().addLast(new WebSocketBinaryFrameByteBufAdapter());//适配器
		ctx.pipeline().addLast(this.handler);//业务层handler
		//为新加的handler手动触发必要事件
		ctx.fireChannelRegistered();
		ctx.fireChannelActive();
		log.log(logLevel,"HANDSHAKE_COMPLETED HANDLERS:"+ctx.channel().pipeline().toMap().toString());
	}
	super.userEventTriggered(ctx, evt);
}
 
Example 9
Project: util4j   File: NettyServer.java   View Source Code Vote up 5 votes
/**
	 * 初始化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 10
Project: nettyRpc   File: BusinessServerHandler.java   View Source Code Vote up 4 votes
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    ctx.fireChannelRegistered();
}
 
Example 11
Project: util4j   File: NettyClientConfig.java   View Source Code Vote up 4 votes
/**
	 * 初始化handler适配包装
	 * @param init
	 * @return
	 */
	protected ChannelHandler initHandlerAdapter(ChannelHandler init)
	{
		ChannelHandler handler=new ShareableChannelInboundHandler() {
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				Channel ch=ctx.channel();
				LogLevel level=getLevel();
				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 {
//				LogLevel level=getLevel();
//				if(level!=null)
//				{
//					ch.pipeline().addLast(new LoggerHandler(level));
//				}
//				ch.pipeline().addLast(init);
//			}
//		};
		/*
		 * 如果init里面后续有ChannelInitializer则会触发2次channelRegistered
		 * 导致LoggerHandler会打印2次channelRegistered无法避免,触发玩家自己的init不使用ChannelInitializer
		ChannelInboundHandlerAdapter handler=new ChannelInboundHandlerAdapter(){
			@Override
			public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
				ctx.pipeline().addLast(new LoggerHandler(getLevel()));
				ctx.pipeline().addLast(init);
				ctx.pipeline().remove(this);
				super.channelRegistered(ctx);
				
			}
		};
		 */
		return handler;
	}
 
Example 12
Project: aws-sdk-java-v2   File: LoggingHandler.java   View Source Code Vote up 4 votes
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
    log(() -> format(ctx, "CHANNEL_REGISTERED"));
    ctx.fireChannelRegistered();
}