io.netty.handler.logging.LogLevel Java Examples

The following examples show how to use io.netty.handler.logging.LogLevel. 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: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 6 votes vote down vote up
public static void newServerBootstrap(String host, int port, ChannelInitializer<SocketChannel> initializer){
	EventLoopGroup bossGroup = new NioEventLoopGroup(1);
       EventLoopGroup workerGroup = new NioEventLoopGroup();
       try {
           ServerBootstrap b = new ServerBootstrap();
           b.group(bossGroup, workerGroup)
            .channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(initializer)
            .bind(port).sync().channel().closeFuture().sync();	        
       } catch (Exception e){   
       	e.printStackTrace();
       } 
       finally {
           bossGroup.shutdownGracefully();
           workerGroup.shutdownGracefully();
       }
}
 
Example #2
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 6 votes vote down vote up
public static void newClientBootstrap(String host, int port, ChannelInitializer<SocketChannel> initializer){
	EventLoopGroup group = new NioEventLoopGroup();
       try {
           Bootstrap b = new Bootstrap();
           ChannelFuture f = b.group(group)
           		.channel(NioSocketChannel.class)
           		.option(ChannelOption.SO_KEEPALIVE, true)
           		.handler(new LoggingHandler(LogLevel.INFO))
           		.handler(initializer)
           		.connect(host, port).sync();            
           f.channel().closeFuture().sync();            
       } catch (Exception e){   
           e.printStackTrace();
       } finally {        	
           group.shutdownGracefully();
       }
}
 
Example #3
Source File: HexDumpProxy.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("Proxying *:" + LOCAL_PORT + " to " + REMOTE_HOST + ':' + REMOTE_PORT + " ...");

    // Configure the bootstrap.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new HexDumpProxyInitializer(REMOTE_HOST, REMOTE_PORT))
         .childOption(ChannelOption.AUTO_READ, false)
         .bind(LOCAL_PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #4
Source File: TcpServer.java    From ns4_frame with Apache License 2.0 6 votes vote down vote up
@Override
public void startUp() throws Exception {
    initLog.info("启动Tcp服务");
    tcpBootstrap.option(ChannelOption.SO_BACKLOG, 1024);
    tcpBootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    tcpBootstrap.group(bossGroup, workerGroup);
    tcpBootstrap.channel(NioServerSocketChannel.class);
    tcpBootstrap.handler(new NSLogginHandler(LogLevel.INFO));
    tcpBootstrap.childHandler(new TcpServerInitializer());

    try {
        Channel ch = tcpBootstrap.bind(ConfigCenter.getConfig.getTcpPort()).sync().channel();
        ch.closeFuture().sync();
    } catch (Exception e) {
        e.printStackTrace();
        destroy();
    }
}
 
Example #5
Source File: BasicSSLServer.java    From elasticsearch-hadoop with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
    File cert = Paths.get(getClass().getResource("/ssl/server.pem").toURI()).toFile();
    File keyStore = Paths.get(getClass().getResource("/ssl/server.key").toURI()).toFile();

    SslContext sslCtx = SslContext.newServerContext(cert, keyStore);

    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();

    server = new ServerBootstrap();
    server.group(bossGroup, workerGroup)
          .channel(NioServerSocketChannel.class)
          .option(ChannelOption.SO_BACKLOG, 100)
          .handler(new LoggingHandler(LogLevel.INFO))
          .childHandler(new BasicSSLServerInitializer(sslCtx));

    server.bind(port).sync().channel().closeFuture();
}
 
Example #6
Source File: NettyRestServer.java    From netty-restful-server with MIT License 6 votes vote down vote up
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ServerInitializer());

        Channel ch = b.bind(Config.getInt("server.port")).sync().channel();

        ch.closeFuture().sync();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #7
Source File: NettyIoAcceptor.java    From termd with Apache License 2.0 6 votes vote down vote up
public NettyIoAcceptor(NettyIoServiceFactory factory, final IoHandler handler) {
  this.factory = factory;
  this.handler = handler;
  channelGroup = new DefaultChannelGroup("sshd-acceptor-channels", GlobalEventExecutor.INSTANCE);
  bootstrap.group(factory.eventLoopGroup)
      .channel(NioServerSocketChannel.class)
      .option(ChannelOption.SO_BACKLOG, 100)
      .handler(new LoggingHandler(LogLevel.INFO))
      .childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
          ChannelPipeline p = ch.pipeline();
          p.addLast(new NettyIoSession(NettyIoAcceptor.this, handler).adapter);
        }
      });
}
 
Example #8
Source File: CustomProtocolServer.java    From IOT-Technical-Guide with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.valueOf(leakDetectorLevel.toUpperCase()));

    EventLoopGroup bossGroup = new NioEventLoopGroup(bossGroupThreadCount);
    EventLoopGroup workerGroup = new NioEventLoopGroup(workerGroupThreadCount);

    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup,workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new CustomProtocolInitializer(maxPayloadSize));
        ChannelFuture f = b.bind(PORT);
        f.channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #9
Source File: TelnetServer.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {
        sslCtx = null;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new TelnetServerInitializer(sslCtx));

        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #10
Source File: DefaultRedisKeeperServer.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
protected void startServer() throws InterruptedException {

      ServerBootstrap b = new ServerBootstrap();
      b.group(bossGroup, workerGroup)
       .channel(NioServerSocketChannel.class)
       .handler(new LoggingHandler(LogLevel.INFO))
       .childHandler(new ChannelInitializer<SocketChannel>() {
           @Override
           public void initChannel(SocketChannel ch) throws Exception {
               ChannelPipeline p = ch.pipeline();
               p.addLast(new LoggingHandler(LogLevel.DEBUG));
               p.addLast(new NettySimpleMessageHandler());
               p.addLast(new NettyMasterHandler(DefaultRedisKeeperServer.this, new CommandHandlerManager(), keeperConfig.getTrafficReportIntervalMillis()));
           }
       });
      serverSocketChannel = (ServerSocketChannel) b.bind(currentKeeperMeta.getPort()).sync().channel();
  }
 
Example #11
Source File: BootstrapTemplate.java    From netty-cookbook with Apache License 2.0 6 votes vote down vote up
public static void newClientBootstrap(String host, int port, ChannelInitializer<SocketChannel> initializer){
	EventLoopGroup group = new NioEventLoopGroup();
       try {
           Bootstrap b = new Bootstrap();
           ChannelFuture f = b.group(group)
           		.channel(NioSocketChannel.class)
           		.option(ChannelOption.SO_KEEPALIVE, true)
           		.handler(new LoggingHandler(LogLevel.INFO))
           		.handler(initializer)
           		.connect(host, port).sync();            
           f.channel().closeFuture().sync();            
       } catch (Exception e){   
           e.printStackTrace();
       } finally {        	
           group.shutdownGracefully();
       }
}
 
Example #12
Source File: DefaultProxyServer.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
private void startTcpServer() throws Exception {
    logger.info("[startTcpServer] start with port: {}", config.frontendTcpPort());
    ServerBootstrap b = bootstrap("tcp").childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {

            ChannelPipeline p = ch.pipeline();
            p.addLast(new InternalNetworkHandler(config.getInternalNetworkPrefix()));
            p.addLast(new LoggingHandler(LogLevel.DEBUG));
            p.addLast(new ProxyProtocolDecoder(ProxyProtocolDecoder.DEFAULT_MAX_LENGTH));
            p.addLast(new ProxyProtocolHandler(tunnelManager, resourceManager, pingStatsManager));
        }
    });
    // port 80 bind only local address
    InetSocketAddress bindAddress = new InetSocketAddress(FoundationService.DEFAULT.getLocalIp(),
            config.frontendTcpPort());
    logger.info("[startTcpServer] bind socket: {}", bindAddress);
    tcpFuture = b.bind(bindAddress).sync();
}
 
Example #13
Source File: HttpHelloWorldServer.java    From netty-learning-example with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.childOption(ChannelOption.TCP_NODELAY,true);
        b.childOption(ChannelOption.SO_KEEPALIVE,true);
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new HttpHelloWorldServerInitializer());

        Channel ch = b.bind(PORT).sync().channel();
        logger.info("Netty http server listening on port "+ PORT);
        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #14
Source File: MixServer.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
private void acceptConnections(@Nonnull MixServerInitializer initializer, int port,
        @Nonnegative int numWorkers) throws InterruptedException {
    final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    final EventLoopGroup workerGroup = new NioEventLoopGroup(numWorkers);
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.group(bossGroup, workerGroup);
        b.channel(NioServerSocketChannel.class);
        b.handler(new LoggingHandler(LogLevel.INFO));
        b.childHandler(initializer);

        // Bind and start to accept incoming connections.
        ChannelFuture f = b.bind(port).sync();
        this.state = ServerState.RUNNING;

        // Wait until the server socket is closed.
        // In this example, this does not happen, but you can do that to gracefully
        // shut down your server.
        f.channel().closeFuture().sync();
    } finally {
        this.state = ServerState.STOPPING;
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
 
Example #15
Source File: SecureChatServer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
        .build();

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new SecureChatServerInitializer(sslCtx));

        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #16
Source File: TestString.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
private void createChannel(int port) throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup(2);
    b.group(bossGroup, workerGroup)
            .channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    p.addLast(new LoggingHandler(LogLevel.DEBUG));
                    p.addLast(new NettySimpleMessageHandler());
                    p.addLast(new NettyMasterHandler(null, new CommandHandlerManager(), 1000 * 60 * 24));
                    p.addLast(new HAProxyMessageDecoder());
                }
            });
    b.bind(port).sync();
}
 
Example #17
Source File: NettyRestServer.java    From netty-restful-server with MIT License 6 votes vote down vote up
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ServerInitializer());

        Channel ch = b.bind(Config.getInt("server.port")).sync().channel();

        ch.closeFuture().sync();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #18
Source File: NettyServer.java    From syncer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void startAndSync(ChannelInitializer<SocketChannel> initializer, int port) throws InterruptedException {
  EventLoopGroup bossGroup = new NioEventLoopGroup(1);
  EventLoopGroup workerGroup = new NioEventLoopGroup();
  try {
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup)
        .channel(NioServerSocketChannel.class)
        .option(ChannelOption.SO_BACKLOG, 100)
        .handler(new LoggingHandler(LogLevel.DEBUG))
        .childHandler(initializer);

    ChannelFuture f = b.bind(port).sync();
    // wait until the server socket is closed
    f.channel().closeFuture().sync();
  } finally {
    bossGroup.shutdownGracefully();
    workerGroup.shutdownGracefully();
  }
}
 
Example #19
Source File: RxMovieServer.java    From ribbon with Apache License 2.0 6 votes vote down vote up
public HttpServer<ByteBuf, ByteBuf> createServer() {
    HttpServer<ByteBuf, ByteBuf> server = RxNetty.newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
        @Override
        public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) {
            if (request.getPath().contains("/users")) {
                if (request.getHttpMethod().equals(HttpMethod.GET)) {
                    return handleRecommendationsByUserId(request, response);
                } else {
                    return handleUpdateRecommendationsForUser(request, response);
                }
            }
            if (request.getPath().contains("/recommendations")) {
                return handleRecommendationsBy(request, response);
            }
            if (request.getPath().contains("/movies")) {
                return handleRegisterMovie(request, response);
            }
            response.setStatus(HttpResponseStatus.NOT_FOUND);
            return response.close();
        }
    }).pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator()).enableWireLogging(LogLevel.ERROR).build();

    System.out.println("RxMovie server started...");
    return server;
}
 
Example #20
Source File: SimpleSctpServer.java    From netty-cookbook with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {       
    EventLoopGroup mainLoop = new NioEventLoopGroup(1);
    EventLoopGroup workerLoop = new NioEventLoopGroup();
    try {
    	ChannelFuture f = new ServerBootstrap().group(mainLoop, workerLoop)
         .channel(NioSctpServerChannel.class)
         .option(ChannelOption.SO_BACKLOG, 100)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new ChannelInitializer<SctpChannel>() {
             @Override
             public void initChannel(SctpChannel ch) throws Exception {
            	 ChannelPipeline p = ch.pipeline();                	
                 p.addLast(new SimpleSctpServerHandler());
             }
         }).bind(PORT).sync();            
        f.channel().closeFuture().sync();
    } finally {            
        mainLoop.shutdownGracefully();
        workerLoop.shutdownGracefully();
    }
}
 
Example #21
Source File: OvsdbConnectionService.java    From ovsdb with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
 * passive connection with Ssl and handle channel callbacks.
 */
@SuppressWarnings("checkstyle:IllegalCatch")
private void ovsdbManagerWithSsl(final String ip, final int port, final ServerChannelInitializer channelHandler) {
    bootstrapFactory.newServer()
        .handler(new LoggingHandler(LogLevel.INFO))
        .childHandler(channelHandler)
        // Start the server.
        .bind(ip, port)
        // Propagate the channel when its ready
        .addListener((ChannelFutureListener) future -> {
            if (future.isSuccess()) {
                serverChannel = future.channel();
            } else {
                LOG.error("Error while binding to address {}, port {}", ip, port, future.cause());
            }
        });
}
 
Example #22
Source File: FactorialServer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new FactorialServerInitializer(sslCtx));

        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
Example #23
Source File: PortListenerAbstract.java    From iot-dc with Apache License 2.0 6 votes vote down vote up
@Override
        protected void initChannel(SocketChannel socketChannel) {
            ChannelPipeline pipeline = socketChannel.pipeline();
            pipeline
                    // log
                    .addLast("logging", new LoggingHandler(LogLevel.INFO))
                    // 心跳检测
//                    .addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS))
//                    .addLast(new HeartBeatHandler())
                    //  链路管理
                    .addLast(new ChannelManagerHandler())
            ;
            // 拓展
            extHandler(socketChannel.pipeline());
            pipeline.addLast(new MqHandler())
                    // 异常管理
                    .addLast(new ExceptionHandler())
            ;
        }
 
Example #24
Source File: ByteEchoPeerBase.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
public void run() throws Exception {
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoPeerHandler(messageSize));
                    }
                });
        final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync();
        future.channel().closeFuture().sync();
    } finally {
        connectGroup.shutdownGracefully();
    }
}
 
Example #25
Source File: NettyServerServiceImpl.java    From sds with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void start() {
    bossGroup = new NioEventLoopGroup(); // (1)
    workerGroup = new NioEventLoopGroup();
    try {
        b = new ServerBootstrap(); // (2)
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new SocketServerChannelInitializer(socketConfig.getHeartTime(),socketService,applicationContext));
        // Bind and start to accept incoming connections.
        b.bind(socketConfig.getPort());

        logger.info("socket: "+socketConfig.getPort()+" starting....");
        // Wait until the server socket is closed.
        // In this example, this does not happen, but you can do that to gracefully
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #26
Source File: Http2Server.java    From glowroot with Apache License 2.0 5 votes vote down vote up
Http2Server(int port, boolean supportHttp1) throws InterruptedException {
    group = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_BACKLOG, 1024);
    b.group(group)
            .channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(supportHttp1 ? new Http2ServerWithHttp1SupportInitializer()
                    : new Http2ServerInitializer());
    channel = b.bind(port).sync().channel();
}
 
Example #27
Source File: NettyChatServerInitializer.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("framer", new LengthFieldBasedFrameDecoder(400 * 1024, 0, 4, -4, 0));
    pipeline.addLast("decoder", new PacketDecoder());
    pipeline.addLast("encoder", new PacketEncoder());
    pipeline.addLast(new LoggingHandler(LogLevel.DEBUG));
    pipeline.addLast("handler", new MessageServerHandler(handlerManager));
}
 
Example #28
Source File: ConnectionTest.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast("framer", new LengthFieldBasedFrameDecoder(400 * 1024, 0, 4, -4, 0));
    pipeline.addLast("decoder", new ClientPacketDecoder());
    pipeline.addLast("encoder", new PacketEncoder());
    pipeline.addLast(new LoggingHandler(LogLevel.WARN));
    pipeline.addLast("handler", new ClientMessageClientHandler(name));
}
 
Example #29
Source File: NettyTelnetServer.java    From sofa-ark with Apache License 2.0 5 votes vote down vote up
public void open() throws InterruptedException {
    serverBootstrap = new ServerBootstrap();
    serverBootstrap.option(ChannelOption.SO_BACKLOG, 1024);
    serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
        .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new NettyTelnetInitializer());
    channel = serverBootstrap.bind(port).sync().channel();
}
 
Example #30
Source File: ReactorNettyClient.java    From r2dbc-mysql with Apache License 2.0 5 votes vote down vote up
ReactorNettyClient(Connection connection, MySqlSslConfiguration ssl, ConnectionContext context) {
    requireNonNull(connection, "connection must not be null");
    requireNonNull(context, "context must not be null");
    requireNonNull(ssl, "ssl must not be null");

    this.connection = connection;
    this.context = context;

    // Note: encoder/decoder should before reactor bridge.
    connection.addHandlerLast(EnvelopeSlicer.NAME, new EnvelopeSlicer())
        .addHandlerLast(MessageDuplexCodec.NAME, new MessageDuplexCodec(context, this.closing, this.requestQueue));

    if (ssl.getSslMode().startSsl()) {
        connection.addHandlerFirst(SslBridgeHandler.NAME, new SslBridgeHandler(context, ssl));
    }

    if (InternalLoggerFactory.getInstance(ReactorNettyClient.class).isTraceEnabled()) {
        // Or just use logger.isTraceEnabled()?
        logger.debug("Connection tracking logging is enabled");
        connection.addHandlerFirst(LoggingHandler.class.getSimpleName(), new LoggingHandler(ReactorNettyClient.class, LogLevel.TRACE));
    }

    Flux<ServerMessage> inbound = connection.inbound().receiveObject()
        .handle(INBOUND_HANDLE);

    if (logger.isDebugEnabled()) {
        inbound = inbound.doOnNext(DEBUG_LOGGING);
    } else if (logger.isInfoEnabled()) {
        inbound = inbound.doOnNext(INFO_LOGGING);
    }

    inbound.subscribe(this.responseProcessor::onNext, throwable -> {
        try {
            logger.error("Connection Error: {}", throwable.getMessage(), throwable);
            responseProcessor.onError(throwable);
        } finally {
            connection.dispose();
        }
    }, this.responseProcessor::onComplete);
}