Example usage for io.netty.channel DefaultMessageSizeEstimator DEFAULT

List of usage examples for io.netty.channel DefaultMessageSizeEstimator DEFAULT

Introduction

In this page you can find the example usage for io.netty.channel DefaultMessageSizeEstimator DEFAULT.

Prototype

MessageSizeEstimator DEFAULT

To view the source code for io.netty.channel DefaultMessageSizeEstimator DEFAULT.

Click Source Link

Document

Return the default implementation which returns 8 for unknown messages.

Usage

From source file:org.ethereum.net.server.PeerServerImpl.java

License:Open Source License

public void start(int port) {
    // TODO review listening use
    listening = true;/* w w  w  .  j  a va2 s. c o m*/

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup 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 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();

    }
}