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.opendaylight.sxp.core.service.ConnectFacade.java

License:Open Source License

/**
 * Create new Node that listens to incoming connections
 *
 * @param node SxpNode containing options
 * @param hf   HandlerFactory providing handling of communication
 * @return ChannelFuture callback//from  ww  w  .j av  a 2s .c  om
 */
public static ChannelFuture createServer(final SxpNode node, final HandlerFactory hf) {
    if (!Epoll.isAvailable()) {
        throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
    }
    Map<InetAddress, byte[]> keyMapping = new HashMap<>();
    ServerBootstrap bootstrap = new ServerBootstrap();
    node.getDomains().forEach(d -> d.getConnectionTemplates().forEach(t -> {
        if (t.getTemplatePassword() != null && !t.getTemplatePassword().isEmpty()) {
            final byte[] password = t.getTemplatePassword().getBytes(StandardCharsets.US_ASCII);
            Search.expandPrefix(t.getTemplatePrefix())
                    .forEach(inetAddress -> keyMapping.put(inetAddress, password));
        }
    }));
    Collections2.filter(node.getAllConnections(), CONNECTION_ENTRY_WITH_PASSWORD).forEach(p -> keyMapping
            .put(p.getDestination().getAddress(), p.getPassword().getBytes(StandardCharsets.US_ASCII)));

    keyMapping.remove(node.getSourceIp());
    bootstrap.channel(EpollServerSocketChannel.class);
    bootstrap.option(EpollChannelOption.TCP_MD5SIG, keyMapping);
    bootstrap.group(eventLoopGroup);
    if (Configuration.NETTY_LOGGER_HANDLER) {
        bootstrap.handler(new LoggingHandler(LogLevel.INFO));
    }
    bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getDecoders());
            ch.pipeline().addLast(hf.getEncoders());
        }
    });
    return bootstrap.bind(node.getSourceIp(), node.getServerPort());
}

From source file:org.piindustries.pinetwork.server.Server.java

License:Apache License

public void run() throws Exception {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//from   ww w . java  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 {
                        ch.pipeline().addLast(
                                //new LoggingHandler(LogLevel.INFO),
                                new ServerHandler());
                    }
                });

        // 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:org.restlet.ext.netty.NettyServerHelper.java

License:Open Source License

@Override
public void start() throws Exception {
    super.start();
    setBossGroup(new NioEventLoopGroup(1));
    setWorkerGroup(new NioEventLoopGroup());
    setServerBootstrap(new ServerBootstrap());
    getServerBootstrap().option(ChannelOption.SO_BACKLOG, 1024);
    getServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new HttpServerInitializer(this, null));
    setChannel(serverBootstrap.bind(getHelped().getPort()).sync().channel());
    setEphemeralPort(((InetSocketAddress) getChannel().localAddress()).getPort());
    getLogger().info("Starting the Netty " + getProtocols() + " server on port " + getHelped().getPort());
}

From source file:org.shelloid.vpt.agent.LocalLink.java

License:Open Source License

public Channel bind(int port) throws Exception {
    final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    final EventLoopGroup workerGroup = new NioEventLoopGroup();
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 20)
            .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override/*from ww  w. j av a 2  s . co m*/
                public void initChannel(SocketChannel ch) throws Exception {
                    ChannelPipeline p = ch.pipeline();
                    p.addLast(new AppSideAgentHandler());
                }
            });
    ChannelFuture f = b.bind(port).sync();
    final Channel ch = f.channel();
    if (f.isSuccess()) {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                long timeOut = 1000 * 60 * 5;
                Platform.shelloidLogger.info("Gracefull shutdown initiated.");
                ChannelFuture cf = ch.close();
                cf.awaitUninterruptibly(timeOut);
                bossGroup.shutdownGracefully().awaitUninterruptibly(timeOut);
                workerGroup.shutdownGracefully().awaitUninterruptibly(timeOut);
                Platform.shelloidLogger.info("Gracefull shutdown finidhed.");
            }
        });
        return ch;
    } else {
        throw new Exception("Can't bind to " + port);
    }
}

From source file:org.shelloid.vpt.rms.server.VPTServer.java

License:Open Source License

public Channel run(ShelloidMX mx) throws Exception {
    final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    final EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {/*from  ww  w . j  av a 2 s .  c  o  m*/
        sslCtx = SslContext.newServerContext(
                new File(Configurations.get(Configurations.ConfigParams.CHAIN_FILE)),
                new File(Configurations.get(Configurations.ConfigParams.KEY_FILE)));
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new VPTServerInitializer(sslCtx, mx));
        final Channel ch = b.bind(port).sync().channel();
        Platform.shelloidLogger.warn("VPT Server running on " + Configurations.SERVER_IP + ":"
                + Configurations.get(Configurations.ConfigParams.SERVER_PORT));
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                long timeOut = 1000 * 60 * 5;
                Platform.shelloidLogger.warn("Gracefull shutdown initiated.");
                ChannelFuture cf = ch.close();
                cf.awaitUninterruptibly(timeOut);
                bossGroup.shutdownGracefully().awaitUninterruptibly(timeOut);
                workerGroup.shutdownGracefully().awaitUninterruptibly(timeOut);
                Platform.shelloidLogger.warn("Gracefull shutdown finished.");
            }
        });
        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
    return null;
}

From source file:org.tiger.netty.rpc.all.server.NettyServer.java

License:Apache License

public void bind() throws Exception {
    //??NIO//from w  w  w . j av  a 2  s .com
    //????EventLoopGroup
    //NioEventLoopGroupReactor
    //???boss?Reactor?
    //???worker??IOReactor?
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    //Netty??
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup)
            //Channel????????
            .channel(NioServerSocketChannel.class)
            //TCP?
            //backlog???
            //??TCP??
            //??listen?syn(connect)??
            //????syn???(?synack)
            // ????????
            //accept???????
            //backlog5?Web??lighttpd128*8
            //???syn??
            //Nettybacklog100???
            .option(ChannelOption.SO_BACKLOG, 100)
            //?HandlerHandler???HandlerNioServerSocketChannelChannelPipelineHandler
            //HandlerSocketChannelChannelPipelineHandler
            .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 future = b.bind(NettyConstant.REMOTEIP, NettyConstant.PORT).sync();
    System.out.println("Netty server start ok : " + (NettyConstant.REMOTEIP + " : " + NettyConstant.PORT));
    future.channel().closeFuture().sync();
}

From source file:org.vootoo.client.netty.NettySolrClientTest.java

License:Apache License

@BeforeClass
public static void start_local_netty() throws InterruptedException {
    ServerBootstrap sb = new ServerBootstrap();
    sb.group(serverGroup).channel(LocalServerChannel.class)
            .handler(new ChannelInitializer<LocalServerChannel>() {
                @Override//from  ww w  .j av  a 2s. c  om
                public void initChannel(LocalServerChannel ch) throws Exception {
                    ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
                }
            }).childHandler(new MockSolrServerChannelInitializer());

    //client
    client = new Bootstrap();
    client.group(clientGroup).channel(LocalChannel.class).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000);

    // Start the server.
    ChannelFuture serverFuture = sb.bind(addr).sync();

    serverChannel = serverFuture.channel();
}

From source file:org.vootoo.server.netty.SolrNettyServer.java

License:Apache License

protected void startNetty() throws Exception {
    logger.info("netty server starting port={} ...", port);
    queryExecutor = new RequestExecutor(queryConfig);
    updateExecutor = new RequestExecutor(updateConfig);

    EventLoopGroup bossGroup = new NioEventLoopGroup(bossWorkerNum);
    EventLoopGroup workerGroup = new NioEventLoopGroup(ioWorkerNum);
    try {/*from   w ww. j  a  v  a2s . c o m*/
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SolrServerChannelInitializer(
                        coreContainer, handlerConfigs, queryExecutor, updateExecutor));

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

        logger.info("netty server started port={}", port);

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

        // Wait until all threads are terminated.
        bossGroup.terminationFuture().sync();
        workerGroup.terminationFuture().sync();
    }
}

From source file:org.vootoo.server.netty.SolrServerHandlerTest.java

License:Apache License

@BeforeClass
public static void start_local_netty() throws InterruptedException {
    queryExecutor = new RequestExecutor(
            ExecutorConfig.createDefault().setName("query-executor").setThreadNum(5));
    updateExecutor = new RequestExecutor(
            ExecutorConfig.createDefault().setName("update-executor").setThreadNum(2));
    // Note that we can use any event loop to ensure certain local channels
    // are handled by the same event loop thread which drives a certain socket channel
    // to reduce the communication latency between socket channels and local channels.
    ServerBootstrap sb = new ServerBootstrap();
    sb.group(serverGroup).channel(LocalServerChannel.class)
            .handler(new ChannelInitializer<LocalServerChannel>() {
                @Override/*from   ww  w .j a  v a 2 s .c o  m*/
                public void initChannel(LocalServerChannel ch) throws Exception {
                    ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO));
                }
            }).childHandler(new SolrServerChannelInitializer(h.getCoreContainer(), new ChannelHandlerConfigs(),
                    queryExecutor, updateExecutor));

    client = new Bootstrap();
    client.group(clientGroup).channel(LocalChannel.class).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000);

    // Start the server.
    ChannelFuture serverFuture = sb.bind(addr).sync();

    serverChannel = serverFuture.channel();
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EndpointManager.java

License:Open Source License

public boolean startListener(int port, String name, InboundProcessorParams params) {
    if (org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EventExecutorManager.getInstance()
            .isRegisteredExecutor(port)) {
        log.info("Netty Listener already started on port " + port);
        return true;
    }/*w  ww.j a  v  a 2s. c o m*/

    InboundHttp2Configuration config = buildConfiguration(port, name, params);
    NettyThreadPoolConfiguration threadPoolConfig = new NettyThreadPoolConfiguration(
            config.getBossThreadPoolSize(), config.getWorkerThreadPoolSize());

    if (config.isEnableServerPush()) {
        if (config.getDispatchSequence() == null || config.getErrorSequence() == null) {
            throw new SynapseException("dispatch.outflow.sequence and error.outflow.sequence "
                    + "cannot be empty if server-push enabled");
        }
    }
    InboundHttp2EventExecutor eventExecutor = new InboundHttp2EventExecutor(threadPoolConfig);

    org.wso2.carbon.inbound.endpoint.protocol.http2.management.Http2EventExecutorManager.getInstance()
            .registerEventExecutor(port, eventExecutor);
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.SO_BACKLOG, 1024);
    b.group(eventExecutor.getBossGroupThreadPool(), eventExecutor.getWorkerGroupThreadPool())
            .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO))
            .childHandler(new InboundHttp2ServerInitializer(null, config));
    try {

        b.bind(config.getPort()).sync().channel();
        log.info("Http2 Inbound started on Port : " + config.getPort());
        return true;
    } catch (InterruptedException e) {
        log.error(e.getMessage(), e);
        return false;
    }
}