當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerBootstrap.handler方法代碼示例

本文整理匯總了Java中io.netty.bootstrap.ServerBootstrap.handler方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerBootstrap.handler方法的具體用法?Java ServerBootstrap.handler怎麽用?Java ServerBootstrap.handler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.bootstrap.ServerBootstrap的用法示例。


在下文中一共展示了ServerBootstrap.handler方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start(int port) {
    // TODO review listening use
    listening = true;

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

    EthereumChannelInitializer ethereumChannelInitializer = ethereumChannelInitializerFactory.newInstance("");

    ethereumListener.trace("Listening on port " + port);


    try {
        ServerBootstrap b = new ServerBootstrap();

        b.group(bossGroup, workerGroup);
        b.channel(NioServerSocketChannel.class);

        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
        b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerConnectionTimeout());

        b.handler(new LoggingHandler());
        b.childHandler(ethereumChannelInitializer);

        // Start the client.
        logger.info("Listening for incoming connections, port: [{}] ", port);
        logger.info("NodeId: [{}] ", Hex.toHexString(config.nodeId()));

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

        // Wait until the connection is closed.
        f.channel().closeFuture().sync();
        logger.debug("Connection is closed");

        // TODO review listening use
        listening = false;
    } catch (Exception e) {
        logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
        throw new Error("Server Disconnected");
    } finally {
        workerGroup.shutdownGracefully();

    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:46,代碼來源:PeerServerImpl.java

示例2: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start() throws Exception {
    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(boss, worker);
        bootstrap.channel(NioServerSocketChannel.class);
        bootstrap.handler(new LoggingHandler(LogLevel.INFO));
        bootstrap.childHandler(ProxyServerChannelInitializerFactory.getChannelInitializer(definition));
        bootstrap.childOption(ChannelOption.AUTO_READ, false);
        bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
        server = bootstrap.bind(port).sync().channel();
        log.info("Started proxy server at port: " + port);
    } catch (Exception e) {
        log.error(String.format("Failed starting proxy server at port: %d", port), e);
    }
}
 
開發者ID:thebagchi,項目名稱:heimdall-proxy,代碼行數:16,代碼來源:TcpProxyServer.java

示例3: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start(int port) {

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

        ethereumChannelInitializer = ctx.getBean(EthereumChannelInitializer.class, "");

        ethereumListener.trace("Listening on port " + port);


        try {
            ServerBootstrap b = new ServerBootstrap();

            b.group(bossGroup, workerGroup);
            b.channel(NioServerSocketChannel.class);

            b.option(ChannelOption.SO_KEEPALIVE, true);
            b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
            b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerConnectionTimeout());

            b.handler(new LoggingHandler());
            b.childHandler(ethereumChannelInitializer);

            // Start the client.
            logger.info("Listening for incoming connections, port: [{}] ", port);
            logger.info("NodeId: [{}] ", Hex.toHexString(config.nodeId()));

            channelFuture = b.bind(port).sync();

            listening = true;
            // Wait until the connection is closed.
            channelFuture.channel().closeFuture().sync();
            logger.debug("Connection is closed");

        } catch (Exception e) {
            logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
            throw new Error("Server Disconnected");
        } finally {
            workerGroup.shutdownGracefully();
            bossGroup.shutdownGracefully();
            listening = false;
        }
    }
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:44,代碼來源:PeerServer.java


注:本文中的io.netty.bootstrap.ServerBootstrap.handler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。