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:io.samples.EchoServer.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 {//from w ww . j  a  va 2 s. c om
        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 EchoServerHandler());
                    }
                });

        // 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:io.termd.core.http.netty.NettyWebsocketTtyBootstrap.java

License:Apache License

public void start(Consumer<TtyConnection> handler, Consumer<Throwable> doneHandler) {
    group = new NioEventLoopGroup();

    ServerBootstrap b = new ServerBootstrap();
    b.group(group).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new TtyServerInitializer(channelGroup, handler));

    ChannelFuture f = b.bind(host, port);
    f.addListener(abc -> {//  w w  w.  jav a2  s .c o  m
        if (abc.isSuccess()) {
            channel = f.channel();
            doneHandler.accept(null);
        } else {
            doneHandler.accept(abc.cause());
        }
    });
}

From source file:io.termd.core.ssh.netty.NettyIoAcceptor.java

License:Apache License

public NettyIoAcceptor(NettyIoServiceFactory factory, IoHandler handler) {
    this.factory = factory;
    this.handler = handler;
    channelGroup = new DefaultChannelGroup("sshd-acceptor-channels", GlobalEventExecutor.INSTANCE);
    ;/*from  w ww .  java 2 s  .  c  om*/
    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);
                }
            });
}

From source file:io.termd.core.telnet.netty.NettyTelnetBootstrap.java

License:Apache License

@Override
public void start(Supplier<TelnetHandler> factory, Consumer<Throwable> doneHandler) {
    ServerBootstrap boostrap = new ServerBootstrap();
    boostrap.group(group).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//w  w w .ja v  a 2s  . com
                public void initChannel(SocketChannel ch) throws Exception {
                    channelGroup.add(ch);
                    ChannelPipeline p = ch.pipeline();
                    TelnetChannelHandler handler = new TelnetChannelHandler(factory);
                    p.addLast(handler);
                }
            });

    boostrap.bind(getHost(), getPort()).addListener(fut -> {
        if (fut.isSuccess()) {
            doneHandler.accept(null);
        } else {
            doneHandler.accept(fut.cause());
        }
    });
}

From source file:io.tilt.minka.broker.impl.SocketServer.java

License:Apache License

private boolean keepListening() {
    boolean disconnected;
    logger.info("{}: ({}:{}) Building server (using i: {}) with up to {} concurrent requests",
            getClass().getSimpleName(), serverAddress, serverPort, networkInterfase,
            this.connectionHandlerThreads);

    try {/*from   w  ww.ja v a2 s . c o  m*/
        final ServerBootstrap b = new ServerBootstrap();
        b.group(serverWorkerGroup).channel(NioServerSocketChannel.class)
                //.channel(OioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ObjectEncoder(),
                                new ObjectDecoder(ClassResolvers.cacheDisabled(null)), serverHandler);
                    }
                });
        logger.info("{}: Listening for client connections..", getClass().getSimpleName());
        b.childOption(ChannelOption.SO_KEEPALIVE, true);

        logger.info(
                "{}: ({}:{}) Listening to client connections (using i:{}) with up to {} concurrent requests",
                getClass().getSimpleName(), serverAddress, serverPort, networkInterfase,
                this.connectionHandlerThreads);

        b.bind(this.serverAddress, this.serverPort).sync().channel().closeFuture().sync();
        disconnected = false;
    } catch (Exception e) {
        disconnected = true;
        logger.error("{}: ({}:{}) Unexpected interruption while listening incoming connections",
                getClass().getSimpleName(), serverAddress, serverPort, e);
    } finally {
        logger.info("{}: ({}:{}) Exiting server listening scope", getClass().getSimpleName(), serverAddress,
                serverPort);
        shutdown();
    }
    return disconnected;
}

From source file:itlab.teleport.HttpServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    File_config.Read_ini();/*from  www  . ja  va 2  s . c  o  m*/
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }

    // Configure the server.
    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 HttpServerInitializer(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();
    }
}

From source file:james.learn.netty.echo.EchoServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    //final SslContext sslCtx;
    //if (SSL) {//from  ww  w . j a va  2  s.c om
    //    SelfSignedCertificate ssc = new SelfSignedCertificate();
    //    sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    //} else {
    //    sslCtx = null;
    //}

    // Configure the server.
    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.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        //                     if (sslCtx != null) {
                        //                         p.addLast(sslCtx.newHandler(ch.alloc()));
                        //                     }
                        //p.addLast(new LoggingHandler(LogLevel.INFO));
                        p.addLast(new EchoServerHandler());
                    }
                });

        // 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:james.learn.netty.echo2.EchoServer.java

License:Apache License

public void bind(int port) throws Exception {
    // ??NIO/*from w  ww.j  av  a2s. c  o m*/
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    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.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        /*ByteBuf delimiter = Unpooled.copiedBuffer("$_"
                           .getBytes());
                        ch.pipeline().addLast(
                           new DelimiterBasedFrameDecoder(1024,
                              delimiter));*/
                        ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024 * 1024, 0, 4));
                        ch.pipeline().addLast(new LengthFieldPrepender(4, false));
                        ch.pipeline().addLast(new StringDecoder());
                        ch.pipeline().addLast(new EchoServerHandler());
                    }
                });

        // ???
        ChannelFuture f = b.bind(port).sync();

        // ???
        f.channel().closeFuture().sync();
    } finally {
        // ?
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:jgnash.engine.attachment.AttachmentTransferServer.java

License:Open Source License

public boolean startServer(final char[] password) {
    boolean result = false;

    // If a password has been specified, create an EncryptionManager
    if (password != null && password.length > 0) {
        encryptionManager = new EncryptionManager(password);
    }//from   w w w  . jav  a2  s. c om

    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(eventLoopGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    public void initChannel(final SocketChannel ch) throws Exception {

                        ch.pipeline().addLast(
                                new DelimiterBasedFrameDecoder(((TRANSFER_BUFFER_SIZE + 2) / 3) * 4 + PATH_MAX,
                                        true, Delimiters.lineDelimiter()),

                                new StringEncoder(CharsetUtil.UTF_8), new StringDecoder(CharsetUtil.UTF_8),

                                new Base64Encoder(), new Base64Decoder(),

                                new ServerTransferHandler());
                    }
                });

        // Start the server.
        final ChannelFuture future = b.bind(port).sync();

        if (future.isDone() && future.isSuccess()) {
            result = true;
            logger.info("File Transfer Server started successfully");
        } else {
            logger.info("Failed to start the File Transfer Server");
        }
    } catch (final InterruptedException e) {
        logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        stopServer();
    }

    return result;
}

From source file:jp.ac.keio.sfc.ht.memsys.ghost.testserver.ObjectEchoServer.java

License:Apache License

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;
    //        }/*from   w  ww.j  av a2s  .co  m*/

    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 ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        //                            if (sslCtx != null) {
                        //                                p.addLast(sslCtx.newHandler(ch.alloc()));
                        //                            }
                        p.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)),
                                new ObjectEchoServerHandler());
                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PORT).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}