@Override protected void initChannel(NioSocketChannel ch) throws Exception { // FIXME: should we use getTimeout()? int idleTimeout = UrlUtils.getIdleTimeout(getUrl()); NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this); ch.pipeline()//.addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug .addLast("decoder", adapter.getDecoder()) .addLast("encoder", adapter.getEncoder()) .addLast("server-idle-handler", new IdleStateHandler(0, 0, idleTimeout, MILLISECONDS)) .addLast("handler", nettyServerHandler); } });
@Override public void initChannel(NioSocketChannel ch) throws Exception { try { if (!peerDiscoveryMode) { logger.debug("Open {} connection, channel: {}", isInbound() ? "inbound" : "outbound", ch.toString()); } if (notEligibleForIncomingConnection(ch)) { ch.disconnect(); return; } final Channel channel = ctx.getBean(Channel.class); channel.setInetSocketAddress(ch.remoteAddress()); channel.init(ch.pipeline(), remoteId, peerDiscoveryMode, channelManager); if(!peerDiscoveryMode) { channelManager.add(channel); } // limit the size of receiving buffer to 1024 ch.config().setRecvByteBufAllocator(new FixedRecvByteBufAllocator(256 * 1024)); ch.config().setOption(ChannelOption.SO_RCVBUF, 256 * 1024); ch.config().setOption(ChannelOption.SO_BACKLOG, 1024); // be aware of channel closing ch.closeFuture().addListener((ChannelFutureListener) future -> { if (!peerDiscoveryMode) { channelManager.notifyDisconnect(channel); } }); } catch (Exception e) { logger.error("Unexpected error: ", e); } }
@Override protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { ChannelPipeline channelPipLine = nioSocketChannel.pipeline(); int maxLength = Integer.MAX_VALUE; channelPipLine.addLast("frame", new LengthFieldBasedFrameDecoder(maxLength,0,4,0,0)); channelPipLine.addLast("decoder", new RpcDecoder(RpcRequest.class)); channelPipLine.addLast("encoder", new RpcEncoder(RpcResponse.class)); int readerIdleTimeSeconds = 0; int writerIdleTimeSeconds = 0; int allIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; channelPipLine.addLast("idleStateHandler", new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds)); channelPipLine.addLast("logger", new LoggingHandler(LogLevel.DEBUG)); channelPipLine.addLast("handler", new GameNetRPCServerHandler()); } }
@Override public void channelCreated(Channel channel) { NioSocketChannel nioSocketChannel = (NioSocketChannel) channel; nioSocketChannel.config().setTcpNoDelay(true).setKeepAlive(true); final ChannelPipeline p = nioSocketChannel.pipeline(); //HTTPS if (sslCtx != null) { p.addLast(sslCtx.newHandler(channel.alloc())); } p.addLast(new HttpClientCodec(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)); p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE)); } }
@Override protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { ChannelPipeline channelPipLine = nioSocketChannel.pipeline(); int maxLength = Integer.MAX_VALUE; channelPipLine.addLast("frame", new LengthFieldBasedFrameDecoder(maxLength, 2, 4, 0, 0)); channelPipLine.addLast("encoder", new NetProtoBufMessageTCPEncoder()); channelPipLine.addLast("decoder", new NetProtoBufMessageTCPDecoder()); int readerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; int writerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; int allIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; GameServerConfigService gameServerConfigService = LocalMananger.getInstance().getLocalSpringServiceManager().getGameServerConfigService(); GameServerConfig gameServerConfig = gameServerConfigService.getGameServerConfig(); if(gameServerConfig.isDevelopModel()) { channelPipLine.addLast("logger", new GameLoggingHandler(LogLevel.DEBUG)); } channelPipLine.addLast("idleStateHandler", new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds)); channelPipLine.addLast("handler", new ProxyBackendHandler(inboundChannel)); } }
@Override protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { ChannelPipeline channelPipLine = nioSocketChannel.pipeline(); int maxLength = Integer.MAX_VALUE; channelPipLine.addLast("frame", new LengthFieldBasedFrameDecoder(maxLength, 2, 4, 0, 0)); channelPipLine.addLast("encoder", new NetProtoBufMessageTCPEncoder()); channelPipLine.addLast("decoder", new NetProtoBufMessageTCPDecoder()); int readerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; int writerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; int allIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; GameServerConfigService gameServerConfigService = LocalMananger.getInstance().getLocalSpringServiceManager().getGameServerConfigService(); GameServerConfig gameServerConfig = gameServerConfigService.getGameServerConfig(); if(gameServerConfig.isDevelopModel()) { channelPipLine.addLast("logger", new GameLoggingHandler(LogLevel.DEBUG)); } channelPipLine.addLast("idleStateHandler", new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds)); channelPipLine.addLast("handler", new ProxyFrontendHandler()); } }
@Override protected void initChannel(NioSocketChannel nioSocketChannel) throws Exception { ChannelPipeline channelPipLine = nioSocketChannel.pipeline(); int maxLength = Integer.MAX_VALUE; channelPipLine.addLast("frame", new LengthFieldBasedFrameDecoder(maxLength, 2, 4, 0, 0)); channelPipLine.addLast("encoder", new NetProtoBufMessageTCPEncoder()); channelPipLine.addLast("decoder", new NetProtoBufMessageTCPDecoder()); // int readerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_READ_TIMEOUT; // int writerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_WRITE_TIMEOUT; int readerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; int writerIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; int allIdleTimeSeconds = GlobalConstants.Net.SESSION_HEART_ALL_TIMEOUT; GameServerConfigService gameServerConfigService = LocalMananger.getInstance().getLocalSpringServiceManager().getGameServerConfigService(); GameServerConfig gameServerConfig = gameServerConfigService.getGameServerConfig(); if(gameServerConfig.isDevelopModel()) { channelPipLine.addLast("logger", new GameLoggingHandler(LogLevel.DEBUG)); } channelPipLine.addLast("idleStateHandler", new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds)); // channelPipLine.addLast("logger", new LoggingHandler(LogLevel.DEBUG)); boolean tcpMessageQueueDirectDispatch = gameServerConfigService.getGameServerConfig().isTcpMessageQueueDirectDispatch(); if(tcpMessageQueueDirectDispatch) { channelPipLine.addLast("handler", new GameNetMessageTcpServerHandler()); }else{ AsyncNettyTcpHandlerService asyncNettyTcpHandlerService = LocalMananger.getInstance().getLocalSpringServiceManager().getAsyncNettyTcpHandlerService(); channelPipLine.addLast(asyncNettyTcpHandlerService.getDefaultEventExecutorGroup(), new AsyncNettyGameNetMessageTcpServerHandler()); } } }
b.group(new NioEventLoopGroup()).handler(new ChannelInitializer<NioSocketChannel>() { @Override protected void initChannel(NioSocketChannel ch) throws Exception { ch.pipeline().addLast(new TestHandler()); } })
@Override protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline cp = ch.pipeline(); cp.addLast("frame", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 2, 0, 2)); cp.addLast("prepender", FRAME_PREPENDER); cp.addLast("decoder", GPB_DECODER_HANDLER); cp.addLast("encoder", GPB_ENCODER_HANDLER); // handler cp.addLast("handler", serverHandler); // cp.addLast("handler", new ServerHandler()); } };
@Override protected void initChannel(NioSocketChannel ch) throws Exception { ch.pipeline().addLast(watchdog.handlers()); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpObjectAggregator(65536)); pipeline.addLast(new HttpServerHandler(pojoEndpointServer, config)); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { NettyCodec nettyCodec = new NettyCodec(getCodec(), attachments); ch.pipeline() .addLast("codec", nettyCodec) .addLast("handler", clientHandler); } });
protected void initChannel(NioSocketChannel ch) throws Exception { ch.pipeline().addLast("protocol-detector", new ProtocolDetector(getPipelineConfigurator())); } };
@Override protected void initChannel(NioSocketChannel ch) throws Exception { Netty4CodecAdapter codecAdapter = new Netty4CodecAdapter(getCodec() ,getUrl(), Netty4Server.this); ch.pipeline() .addLast("decoder", codecAdapter.getDecoder()) .addLast("encoder", codecAdapter.getEncoder()) .addLast("handler", nettyHandler); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { Netty4CodecAdapter adapter = new Netty4CodecAdapter(getCodec(), getUrl(), Netty4Client.this); ch.pipeline().addLast("decoder", adapter.getDecoder()) .addLast("encoder", adapter.getEncoder()) .addLast("handler", nettyHandler); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this); ch.pipeline()//.addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug .addLast("decoder", adapter.getDecoder()) .addLast("encoder", adapter.getEncoder()) .addLast("handler", nettyServerHandler); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { Netty4CodecAdapter codecAdapter = new Netty4CodecAdapter(getCodec() ,getUrl(), Netty4Server.this); ch.pipeline() .addLast("decoder", codecAdapter.getDecoder()) .addLast("encoder", codecAdapter.getEncoder()) .addLast("handler", nettyHandler); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this); ch.pipeline()//.addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug .addLast("decoder", adapter.getDecoder()) .addLast("encoder", adapter.getEncoder()) .addLast("handler", nettyServerHandler); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this); ch.pipeline()//.addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug .addLast("decoder", adapter.getDecoder()) .addLast("encoder", adapter.getEncoder()) .addLast("handler", nettyServerHandler); } });
@Override protected void initChannel(NioSocketChannel ch) throws Exception { Netty4CodecAdapter adapter = new Netty4CodecAdapter(getCodec(), getUrl(), Netty4Client.this); ch.pipeline().addLast("decoder", adapter.getDecoder()) .addLast("encoder", adapter.getEncoder()) .addLast("handler", nettyHandler); } });