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:nettyechoserverdemo.EchoServer.java

public void bind(int port) throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {//from   w  w  w . jav  a 2s  .c o  m
        ServerBootstrap bootstrap = new ServerBootstrap();

        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    protected void initChannel(SocketChannel c) throws Exception {
                        ByteBuf delimiter = Unpooled.copiedBuffer("$_".getBytes());

                        c.pipeline().addLast(new DelimiterBasedFrameDecoder(1024, delimiter));
                        //c.pipeline().addLast(new FixedLengthFrameDecoder(10));
                        c.pipeline().addLast(new StringDecoder());
                        c.pipeline().addLast(new EchoServerHandler());
                    } //initChannel()

                });

        ChannelFuture future = bootstrap.bind(port).sync();

        future.channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    } //try-finally

}

From source file:nettyjavaserializationserverdemo.SubReqServer.java

public void bind(int port) throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {/*from w w  w .j  a v  a2  s . co m*/
        ServerBootstrap bootstrap = new ServerBootstrap();

        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    protected void initChannel(SocketChannel c) throws Exception {
                        c.pipeline().addLast(new ObjectDecoder(1024, ClassResolvers
                                .weakCachingConcurrentResolver(this.getClass().getClassLoader())));
                        c.pipeline().addLast(new ObjectEncoder());
                        c.pipeline().addLast(new SubReqServerHandler());
                    } //initChannel()

                });

        ChannelFuture future = bootstrap.bind(port).sync();

        future.channel().closeFuture().sync();

    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    } //try-finally

}

From source file:nettyjbossmarshallingserverdemo.SubReqServer.java

public void bind(int port) throws InterruptedException {

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

    try {/*from w  w w.j a  va  2  s.  c o m*/
        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
                    protected void initChannel(SocketChannel c) throws Exception {
                        c.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());
                        c.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());
                        c.pipeline().addLast(new SubReqServerHandler());
                    } //initChannel()

                });

        ChannelFuture channelFuture = serverBootstrap.bind(port).sync();

        channelFuture.channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    } //try-finally

}

From source file:nettyprivateprotocolserverdemo.NettyServer.java

public void bind() throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    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// w  ww .  java2s  .c  o  m
                protected void initChannel(SocketChannel ch) throws Exception {
                    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(new HeartBeatRespHandler());

                } //initChannel()

            });

    serverBootstrap.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync();
    System.out.println("Netty server start OK : " + NettyConstant.REMOTEIP + " : " + NettyConstant.PORT);
}

From source file:nettyTest.httpSsl.oneWay.HttpsHelloWorldServer.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {/*  w w  w  . ja v  a  2s . c  om*/
        File certificate = new File(
                HttpsHelloWorldServer.class.getClassLoader().getResource("nettyca/server.crt").getFile());
        File privateKey = new File(
                HttpsHelloWorldServer.class.getClassLoader().getResource("nettyca/server.pem").getFile());
        sslCtx = SslContextBuilder.forServer(certificate, privateKey).build();
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    } 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 HttpsHelloWorldServerInitializer(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:network.thunder.core.communication.nio.P2PServer.java

License:Apache License

public void startServer(int port, ArrayList<Node> connectedNodes) 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 {// w w  w . j a  v  a2 s  .co m
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInit(context, true));

        b.bind(port).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:object.server.ObjectServer.java

public void run(final ConnectionFeedBack connectionFeedBack)
        throws CertificateException, SSLException, InterruptedException, BindException {
    final SslContext sslCtx;
    if (SSL) {//from   www .  ja  va 2 s  . c o m
        SelfSignedCertificate ssc = new SelfSignedCertificate();
        sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
    } else {
        sslCtx = null;
    }
    bossGroup = new NioEventLoopGroup(1);
    workerGroup = new NioEventLoopGroup();
    try {
        server = new ServerBootstrap();
        server.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("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
                        p.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
                        if (sslCtx != null) {
                            p.addLast(sslCtx.newHandler(ch.alloc()));
                        }
                        p.addLast(new ObjectEncoder(),
                                new ObjectDecoder(ClassResolvers.cacheDisabled(classLoader)),
                                new ObjectServerHandler(connectionFeedBack));
                    }
                });

        // Bind and start to accept incoming connections.
        System.out.println("[ObjectServer]\t " + "Server listen to port " + PORT);
        server.bind(PORT).sync().channel().closeFuture().sync();
    } catch (InterruptedException ex) {
        throw new RuntimeException("bind failed..");
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }

}

From source file:org.aesh.terminal.http.netty.NettyWebsocketTtyBootstrap.java

License:Open Source License

public void start(Consumer<Connection> 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 -> {/*from  ww  w . j  av  a2  s. c  o  m*/
        if (abc.isSuccess()) {
            channel = f.channel();
            doneHandler.accept(null);
        } else {
            doneHandler.accept(abc.cause());
        }
    });
}

From source file:org.aotorrent.client.TorrentClient.java

License:Apache License

@Override
public void run() {
    // Configure the server.
    try {//w ww . j  a va 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 InboundChannelInitializer(this))
                .childAttr(AttributeKey.valueOf("torrentEngines"), torrentEngines);

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

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

From source file:org.aotorrent.tracker.TorrentTracker.java

License:Apache License

@Override
public void run() {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    NioEventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*from w w  w  . j a  v a2 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 TrackerChannelInitializer(torrents));

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

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