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:org.msrpenabler.server.net.NioMsrpSockServerBootStrap.java

License:Apache License

public void run() throws Exception {

    // Configure the server.

    ServerBootstrap b = new ServerBootstrap();
    b = b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .option(ChannelOption.SO_BACKLOG, 500) // maximum queue length sock waiting to be accepted
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {

                // Create a new socket / channel / pipeline for each new Cnx
                @Override/*from   w w  w .jav a  2s.  co m*/
                public void initChannel(SocketChannel ch) throws Exception {

                    ch.pipeline().addLast(new LoggingHandler(LogLevel.DEBUG));

                    ch.pipeline().addLast(new NioMsrpMsgDecoder());
                    ch.pipeline().addLast(new NioMsrpMsgEncoder());
                    ch.pipeline().addLast("msrpHandler", new MsgRcvHandler(addrServ));

                }
            });

    // Start the server.
    futureBind = b.bind(addrServ.inetAddr, addrServ.port);

    futureBind.addListener(new ChannelFutureListener() {
        public void operationComplete(ChannelFuture future) {
            if (future.isSuccess()) {
                logger.info(" Bind success on {}:{}", addrServ.inetAddr, addrServ.port);
            } else {
                logger.error(" Bind failed on {}:{}", addrServ.inetAddr, addrServ.port, future.cause());
            }
        }
    });
}

From source file:org.msrpenabler.server.test.EchoClient.java

License:Apache License

public void run() throws Exception {
    // Configure the client.
    group = new NioEventLoopGroup();
    //        try {
    Bootstrap b = new Bootstrap();
    b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
            .handler(new ChannelInitializer<SocketChannel>() {
                @Override//from   www .  j  a  v  a  2  s .co  m
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new EchoClientHandler());
                }
            });

    // Start the client.
    ChannelFuture f = b.connect(host, port).sync();

    ch = f.channel();

    //            // Wait until the connection is closed.
    //            f.channel().closeFuture().sync();
    //        } finally {
    //            // Shut down the event loop to terminate all threads.
    //            group.shutdown();
    //        }
}

From source file:org.neo4j.ndp.transport.socket.SocketTransport.java

License:Open Source License

@Override
public void start() throws Throwable {
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//from w w  w . j a va2 s  .  c  o m
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new SocketTransportHandler(
                            new SocketTransportHandler.ProtocolChooser(availableProtocols)));
                }
            });

    // Bind and start to accept incoming connections.
    b.bind(address.getHost(), address.getPort()).sync();
}

From source file:org.nepu.chat.SecureChatServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    //SelfSignedCertificate
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    ///*from  w w w  .j av a  2  s.co  m*/
    SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    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();
        //bindchannnel
        //syncfuture futurefuture
        //channel futureiochannel
        //closefuture future
        //

    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.nexxy.http.reverseproxy.HttpReverseProxyServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {//from www . ja va2s  .  c o  m
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
    } else {
        sslCtx = null;
    }

    // Configure the cache
    Cache.init();

    // 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 HttpReverseProxyServerInitializer(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:org.opendaylight.controller.netconf.netty.EchoServer.java

License:Open Source License

public void run() {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/* w  w  w .  j  a v  a  2s  .  c om*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(LocalServerChannel.class).option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<LocalChannel>() {
                    @Override
                    public void initChannel(LocalChannel ch) throws Exception {
                        ch.pipeline().addLast(new EchoServerHandler());
                    }
                });

        // Start the server.
        LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
        ChannelFuture f = b.bind(localAddress).sync();

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

From source file:org.opendaylight.controller.netconf.netty.ProxyServer.java

License:Open Source License

public void run() {
    // Configure the server.
    final EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {// w  ww. ja  v a  2  s.  c  o  m
        final LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.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 {
                        ch.pipeline().addLast(proxyHandlerFactory.create(bossGroup, localAddress));
                    }
                });

        // Start the server.
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", 8080);
        ChannelFuture f = serverBootstrap.bind(address).sync();

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

From source file:org.opendaylight.groupbasedpolicy.jsonrpc.RpcServer.java

License:Open Source License

public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {// w  w w  . java 2 s . 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 {
                        logger.debug("New Passive channel created : " + ch.toString());
                        InetAddress address = ch.remoteAddress().getAddress();
                        int port = ch.remoteAddress().getPort();
                        String identifier = address.getHostAddress() + ":" + port;
                        ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new JsonRpcDecoder(100000),
                                new StringEncoder(CharsetUtil.UTF_8));

                        handleNewConnection(identifier, ch);
                        logger.warn("Connected Node : " + identifier);
                    }
                });
        b.option(ChannelOption.TCP_NODELAY, true);
        b.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
        // Start the server.
        ChannelFuture f = b.bind(identity, listenPort).sync();
        String id = f.channel().localAddress().toString();
        logger.warn("Connected Node : " + id);

        this.channel = f.channel();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("Thread interrupted", e);
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.opendaylight.ovsdb.lib.impl.OvsdbConnectionService.java

License:Open Source License

/**
 * OVSDB Passive listening thread that uses Netty ServerBootstrap to open
 * passive connection with Ssl and handle channel callbacks.
 *//*from w  w w . ja  v a 2 s.  c  o  m*/
private static void ovsdbManagerWithSsl(int port, final SSLContext sslContext) {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.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 channel) throws Exception {
                        logger.debug("New Passive channel created : {}", channel);
                        if (sslContext != null) {
                            /* Add SSL handler first if SSL context is provided */
                            SSLEngine engine = sslContext.createSSLEngine();
                            engine.setUseClientMode(false); // work in a server mode
                            engine.setNeedClientAuth(true); // need client authentication
                            channel.pipeline().addLast("ssl", new SslHandler(engine));
                        }

                        channel.pipeline().addLast(new JsonRpcDecoder(100000),
                                new StringEncoder(CharsetUtil.UTF_8), new ExceptionHandler());

                        handleNewPassiveConnection(channel);
                    }
                });
        serverBootstrap.option(ChannelOption.TCP_NODELAY, true);
        serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR,
                new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
        // Start the server.
        ChannelFuture channelFuture = serverBootstrap.bind(port).sync();
        Channel serverListenChannel = channelFuture.channel();
        // Wait until the server socket is closed.
        serverListenChannel.closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("Thread interrupted", e);
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.opendaylight.ovsdb.plugin.ConnectionService.java

License:Open Source License

private void ovsdbManager() {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//from   www  . j  a  v a 2 s .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 channel) throws Exception {
                        logger.debug("New Passive channel created : " + channel.toString());
                        InetAddress address = channel.remoteAddress().getAddress();
                        int port = channel.remoteAddress().getPort();
                        String identifier = address.getHostAddress() + ":" + port;
                        channel.pipeline().addLast(new LoggingHandler(LogLevel.INFO),
                                new JsonRpcDecoder(10000000), new StringEncoder(CharsetUtil.UTF_8));

                        Node node = handleNewConnection(identifier, channel, ConnectionService.this);
                        logger.debug("Connected Node : " + node.toString());
                    }
                });
        b.option(ChannelOption.TCP_NODELAY, true);
        b.option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(65535, 65535, 65535));
        // Start the server.
        ChannelFuture f = b.bind(ovsdbListenPort).sync();
        serverListenChannel = f.channel();
        // Wait until the server socket is closed.
        serverListenChannel.closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("Thread interrupted", e);
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}