Example usage for io.netty.channel ChannelOption ALLOCATOR

List of usage examples for io.netty.channel ChannelOption ALLOCATOR

Introduction

In this page you can find the example usage for io.netty.channel ChannelOption ALLOCATOR.

Prototype

ChannelOption ALLOCATOR

To view the source code for io.netty.channel ChannelOption ALLOCATOR.

Click Source Link

Usage

From source file:org.onosproject.ovsdb.controller.impl.Controller.java

License:Apache License

/**
 * Accepts incoming connections.// ww w .  j  a v  a2  s.co m
 */
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();

    b.group(bossGroup, workerGroup).channel(serverChannelClass)
            .childHandler(new OnosCommunicationChannelInitializer());
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);
    b.bind(ovsdbPort).sync();
}

From source file:org.onosproject.store.cluster.messaging.impl.NettyMessagingManager.java

License:Apache License

private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.SO_RCVBUF, 1048576);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.group(serverGroup, clientGroup);/* ww  w  . j  av  a 2s .  com*/
    b.channel(serverChannelClass);
    if (enableNettyTls) {
        b.childHandler(new SslServerCommunicationChannelInitializer());
    } else {
        b.childHandler(new OnosCommunicationChannelInitializer());
    }
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);

    // Bind and start to accept incoming connections.
    b.bind(localEp.port()).sync().addListener(future -> {
        if (future.isSuccess()) {
            log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port());
        } else {
            log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause());
        }
    });
}

From source file:org.onosproject.xmpp.core.ctl.XmppServer.java

License:Apache License

private void configureBootstrap(ServerBootstrap bootstrap) {
    bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    bootstrap.option(ChannelOption.SO_RCVBUF, 2048);
}

From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java

License:Open Source License

/**
 * Starts server on selected port./*w  w  w .  j  a  v a 2s .  c  om*/
 */
@Override
public void run() {
    /*
     * We generally do not perform IO-unrelated tasks, so we want to have
     * all outstanding tasks completed before the executing thread goes
     * back into select.
     *
     * Any other setting means netty will measure the time it spent selecting
     * and spend roughly proportional time executing tasks.
     */
    workerGroup.setIoRatio(100);

    final ChannelFuture f;
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(channelInitializer)
                .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true)
                //modify to "false" for OCP health-check
                .childOption(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, DEFAULT_WRITE_HIGH_WATERMARK * 1024)
                .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, DEFAULT_WRITE_LOW_WATERMARK * 1024)
                .childOption(ChannelOption.WRITE_SPIN_COUNT, DEFAULT_WRITE_SPIN_COUNT);

        if (startupAddress != null) {
            f = b.bind(startupAddress.getHostAddress(), port).sync();
        } else {
            f = b.bind(port).sync();
        }
    } catch (InterruptedException e) {
        LOG.error("Interrupted while binding port {}", port, e);
        return;
    }

    try {
        InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress();
        address = isa.getHostString();

        // Update port, as it may have been specified as 0
        this.port = isa.getPort();

        LOG.debug("address from tcphandler: {}", address);
        isOnlineFuture.set(true);
        LOG.info("RadioHead listener started and ready to accept incoming tcp/tls connections on port: {}",
                port);
        f.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOG.error("Interrupted while waiting for port {} shutdown", port, e);
    } finally {
        shutdown();
    }
}

From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java

License:Open Source License

public static ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer,
        final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {/*from   w w  w.ja  va 2s  .co  m*/
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);

    serverBootstrap.option(ChannelOption.SO_BACKLOG, Integer.valueOf(SOCKET_BACKLOG_SIZE));
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK);

    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1);

    if (serverBootstrap.group() == null) {
        serverBootstrap.group(bossGroup, workerGroup);
    }
    return serverBootstrap;
}

From source file:org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl.java

License:Open Source License

@Override
public ChannelFuture createServer(final InetSocketAddress address, final BmpSessionListenerFactory slf,
        final Optional<KeyMapping> keys) {
    Preconditions.checkNotNull(address);
    Preconditions.checkNotNull(slf);//from   w w w  . j  a  v  a2s.c om

    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(final Channel ch) throws Exception {
            ch.pipeline().addLast(BmpDispatcherImpl.this.hf.getDecoders());
            ch.pipeline().addLast(BmpDispatcherImpl.this.sessionFactory.getSession(ch, slf));
        }
    });

    b.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
    } else {
        b.channel(NioServerSocketChannel.class);
    }

    if (keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }
    b.group(this.bossGroup, this.workerGroup);
    final ChannelFuture f = b.bind(address);

    LOG.debug("Initiated BMP server {} at {}.", f, address);
    return f;
}

From source file:org.opendaylight.protocol.bmp.mock.BmpMockDispatcher.java

License:Open Source License

private ServerBootstrap createServerInstance() {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.childHandler(new ChannelInitializer<Channel>() {
        @Override/* w ww.  j a  va 2  s . com*/
        protected void initChannel(final Channel ch) throws Exception {
            ch.pipeline().addLast(BmpMockDispatcher.this.sessionFactory.getSession(ch, null));
            ch.pipeline().addLast(BmpMockDispatcher.this.hf.getEncoders());
        }
    });

    serverBootstrap.option(ChannelOption.SO_BACKLOG, MAX_CONNECTIONS_COUNT);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.channel(NioServerSocketChannel.class);
    serverBootstrap.group(bossGroup, workerGroup);
    return serverBootstrap;
}

From source file:org.opendaylight.protocol.framework.AbstractDispatcher.java

License:Open Source License

/**
 * Creates server. Each server needs factories to pass their instances to client sessions.
 *
 * @param address address to which the server should be bound
 * @param channelClass The {@link Class} which is used to create {@link Channel} instances from.
 * @param initializer instance of PipelineInitializer used to initialize the channel pipeline
 *
 * @return ChannelFuture representing the binding process
 *//*from  ww w  .  ja v a 2s . c o  m*/
protected <CH extends Channel> ChannelFuture createServer(final SocketAddress address,
        final Class<? extends ServerChannel> channelClass,
        final ChannelPipelineInitializer<CH, S> initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<CH>() {

        @Override
        protected void initChannel(final CH ch) {
            initializer.initializeChannel(ch, new DefaultPromise<S>(executor));
        }
    });

    b.option(ChannelOption.SO_BACKLOG, 128);
    if (LocalServerChannel.class.equals(channelClass) == false) {
        // makes no sense for LocalServer and produces warning
        b.childOption(ChannelOption.SO_KEEPALIVE, true);
        b.childOption(ChannelOption.TCP_NODELAY, true);
    }
    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    customizeBootstrap(b);

    if (b.group() == null) {
        b.group(bossGroup, workerGroup);
    }
    try {
        b.channel(channelClass);
    } catch (IllegalStateException e) {
        // FIXME: if this is ok, document why
        LOG.trace("Not overriding channelFactory on bootstrap {}", b, e);
    }

    // Bind and start to accept incoming connections.
    final ChannelFuture f = b.bind(address);
    LOG.debug("Initiated server {} at {}.", f, address);
    return f;
}

From source file:org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl.java

License:Open Source License

protected ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap b = new ServerBootstrap();
    b.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override/* w w  w. j  a  v a  2  s . c o  m*/
        protected void initChannel(final SocketChannel ch) {
            initializer.initializeChannel(ch, new DefaultPromise(PCEPDispatcherImpl.this.executor));
        }
    });
    b.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);

    b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    if (Epoll.isAvailable()) {
        b.channel(EpollServerSocketChannel.class);
        b.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        b.channel(NioServerSocketChannel.class);
    }
    if (this.keys.isPresent()) {
        if (Epoll.isAvailable()) {
            b.option(EpollChannelOption.TCP_MD5SIG, this.keys.get());
        } else {
            throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause());
        }
    }

    // Make sure we are doing round-robin processing
    b.childOption(ChannelOption.MAX_MESSAGES_PER_READ, 1);

    if (b.group() == null) {
        b.group(this.bossGroup, this.workerGroup);
    }

    return b;
}

From source file:org.pidome.server.system.network.sockets.SocketBase.java

/**
 * Returns a default with minimal requirements set server bootstrap.
 * @param parents The parent worker controller amount.
 * @param childs The amount of childs per parent worker.
 * @return Server Bootstrap with a socket service channel.
 *//*from  w w w  .jav a  2 s.c  o m*/
public final ServerBootstrap getSocketServerBootstrapContext(int parents, int childs) {
    if (workersGroup == null) {
        workersGroup = new NioEventLoopGroup();
    }
    return new ServerBootstrap().group(workersGroup)
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.DEBUG));
}