Example usage for io.netty.handler.logging LogLevel INFO

List of usage examples for io.netty.handler.logging LogLevel INFO

Introduction

In this page you can find the example usage for io.netty.handler.logging LogLevel INFO.

Prototype

LogLevel INFO

To view the source code for io.netty.handler.logging LogLevel INFO.

Click Source Link

Usage

From source file:com.mattrjacobs.hystrix.server.rs.ExampleServer.java

License:Apache License

public ExampleServer(final int port) {
    rsServer = ReactiveSocketWebSocketServer.create(setupPayload -> new ExampleServerHandler());

    server = HttpServer.newServer(port).clientChannelOption(ChannelOption.AUTO_READ, true)
            .enableWireLogging(LogLevel.INFO);
}

From source file:com.mattrjacobs.hystrix.server.rxnetty.ExampleServer.java

License:Apache License

public ExampleServer(final int port) {
    server = RxNetty.newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
        @Override/*from   ww w .jav a 2s .  c o  m*/
        public Observable<Void> handle(HttpServerRequest<ByteBuf> request,
                HttpServerResponse<ByteBuf> response) {
            System.out.println(
                    "Received request : " + request.getPath() + " on Channel : " + request.getNettyChannel());
            return response.writeStringAndFlush("RESPONSE");
        }
    }).enableWireLogging(LogLevel.INFO).build();
}

From source file:com.metasoft.empire.net.websocket.WebSocketServer.java

License:Apache License

public static void start() throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {/*from   w  w w . j av a 2s  .  c  o m*/
        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 WebSocketServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        //System.out.println("Open your web browser and navigate to " +
        //(SSL? "https" : "http") + "://127.0.0.1:" + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.mikesilversides.mod1.ServerTest.StubClient.java

License:Apache License

public void run() {
    System.out.println("StubClient.run() called!");
    // Configure the client.
    EventLoopGroup group = new NioEventLoopGroup();
    try {/*from  w w w .j  a  v  a 2  s .co m*/
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
                .handler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();

                        p.addLast(new LoggingHandler(LogLevel.INFO));
                        p.addLast(new StubClientHandler(stubPlayer));
                    }
                });

        // Start the client.
        ChannelFuture f = b.connect(HOST, PORT).sync();

        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // We've been interrupted: no more messages.
        System.out.println("InterruptedException caught, do return");
        return;
    } finally {
        // Shut down the event loop to terminate all threads.
        System.out.println("doing group.shutdownGracefully()");
        group.shutdownGracefully();
    }
}

From source file:com.nanxiaoqiang.test.netty.protocol.demo1.server.NettyServer.java

License:Apache License

public void bind() throws Exception {
    // ??NIO/*from   w  w  w.  j a v a  2  s  . com*/
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws IOException {
                    ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4));// ?
                    ch.pipeline().addLast(new NettyMessageEncoder());// ?
                    ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50));// ??
                    ch.pipeline().addLast(new LoginAuthRespHandler());// 
                    ch.pipeline().addLast("HeartBeatHandler", new HeartBeatRespHandler());// 
                }
            });

    // ???
    ChannelFuture cf = b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT);
    cf.channel().closeFuture().sync();
    System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT));
}

From source file:com.net.NettyServer.java

License:Apache License

public void bind() throws Exception {
    // ??NIO/* w w  w .j a v a2  s .  c  o m*/
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws IOException {
                    ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50));
                    ch.pipeline().addLast(new ServerHandler(redisTemplate));
                }
            });

    // ???
    b.bind(ContantUtil.port).sync();
    System.out.println("Netty server start ok : " + ("127.0.0.1" + " : " + ContantUtil.port));
}

From source file:com.netflix.hystrix.examples.reactivesocket.HystrixMetricsReactiveSocketServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    System.out.println("Starting HystrixMetricsReactiveSocketServer...");

    final ReactiveSocketServerHandler handler = ReactiveSocketServerHandler
            .create((setupPayload, rs) -> new EventStreamRequestHandler());

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

    try {/*from  w w  w .  ja  va2  s.  co m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel ch) throws Exception {
                        ChannelPipeline pipeline = ch.pipeline();
                        pipeline.addLast(handler);
                    }
                });
        Channel localhost = b.bind("127.0.0.1", 8025).sync().channel();

        executeCommands();
        localhost.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.netty.file.HttpUploadServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {/*from  w ww .j  ava  2 s .  c  o  m*/
        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);
        b.channel(NioServerSocketChannel.class);
        b.handler(new LoggingHandler(LogLevel.INFO));
        b.childHandler(new HttpUploadServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        System.out.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:"
                + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.netty.fileTest.file.FileSenderServer.java

License:Apache License

public static void main(String[] args) throws Exception {

    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/* www  .ja  va2s  .  c o  m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).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 StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(8192),
                                new StringDecoder(CharsetUtil.UTF_8), new ChunkedWriteHandler(),
                                new FileSenderServerHandler());
                    }
                });

        // Start the server.
        ChannelFuture f = b.bind(PORT).sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:com.netty.fileTest.http.download.HttpStaticFileServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {//from  ww w .j  a  v  a2 s . c  om
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(SslProvider.JDK, 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 HttpStaticFileServerInitializer(sslCtx));

        Channel ch = b.bind(PORT).sync().channel();

        System.err.println("Open your web browser and navigate to " + (SSL ? "https" : "http") + "://127.0.0.1:"
                + PORT + '/');

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}