Example usage for io.netty.channel ChannelOption SO_SNDBUF

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

Introduction

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

Prototype

ChannelOption SO_SNDBUF

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

Click Source Link

Usage

From source file:org.jupiter.transport.netty.NettyUdtAcceptor.java

License:Apache License

@Override
protected void setOptions() {
    super.setOptions();

    ServerBootstrap boot = bootstrap();//from  w  ww  . j a  v a 2s. c  o m

    // parent options
    NettyUdtConfigGroup.ParentConfig parent = configGroup.parent();
    boot.option(ChannelOption.SO_BACKLOG, parent.getBacklog());

    // child options
    NettyUdtConfigGroup.ChildConfig child = configGroup.child();
    boot.childOption(ChannelOption.SO_REUSEADDR, child.isReuseAddress());
    if (child.getRcvBuf() > 0) {
        boot.childOption(ChannelOption.SO_RCVBUF, child.getRcvBuf());
    }
    if (child.getSndBuf() > 0) {
        boot.childOption(ChannelOption.SO_SNDBUF, child.getSndBuf());
    }
    if (child.getLinger() > 0) {
        boot.childOption(ChannelOption.SO_LINGER, child.getLinger());
    }
    int bufLowWaterMark = child.getWriteBufferLowWaterMark();
    int bufHighWaterMark = child.getWriteBufferHighWaterMark();
    if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) {
        WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark);
        boot.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark);
    }
}

From source file:org.jupiter.transport.netty.NettyUdtConnector.java

License:Apache License

@Override
protected void setOptions() {
    super.setOptions();

    Bootstrap boot = bootstrap();//from   w  w  w .j  ava 2s.  c  om

    NettyUdtConfigGroup.ChildConfig child = childConfig;

    // child options
    boot.option(ChannelOption.SO_REUSEADDR, child.isReuseAddress());
    if (child.getRcvBuf() > 0) {
        boot.option(ChannelOption.SO_RCVBUF, child.getRcvBuf());
    }
    if (child.getSndBuf() > 0) {
        boot.option(ChannelOption.SO_SNDBUF, child.getSndBuf());
    }
    if (child.getLinger() > 0) {
        boot.option(ChannelOption.SO_LINGER, child.getLinger());
    }
    if (child.getConnectTimeoutMillis() > 0) {
        boot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, child.getConnectTimeoutMillis());
    }
    int bufLowWaterMark = child.getWriteBufferLowWaterMark();
    int bufHighWaterMark = child.getWriteBufferHighWaterMark();
    if (bufLowWaterMark >= 0 && bufHighWaterMark > 0) {
        WriteBufferWaterMark waterMark = new WriteBufferWaterMark(bufLowWaterMark, bufHighWaterMark);
        boot.option(ChannelOption.WRITE_BUFFER_WATER_MARK, waterMark);
    }
}

From source file:org.marketcetera.client.rpc.RpcClientImpl.java

@Override
protected void connectWebServices() throws I18NException, RemoteException {
    SLF4JLoggerProxy.debug(this, "Connecting to RPC server at {}:{}", mParameters.getHostname(),
            mParameters.getPort());/*from   ww  w . jav a 2 s .  c o m*/
    PeerInfo server = new PeerInfo(mParameters.getHostname(), mParameters.getPort());
    DuplexTcpClientPipelineFactory clientFactory = new DuplexTcpClientPipelineFactory();
    executor = new ThreadPoolCallExecutor(1, 10);
    clientFactory.setRpcServerCallExecutor(executor);
    clientFactory.setConnectResponseTimeoutMillis(10000);
    clientFactory.setCompression(true);
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup());
    bootstrap.handler(clientFactory);
    bootstrap.channel(NioSocketChannel.class);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
    bootstrap.option(ChannelOption.SO_SNDBUF, 1048576);
    bootstrap.option(ChannelOption.SO_RCVBUF, 1048576);
    try {
        channel = clientFactory.peerWith(server, bootstrap);
        clientService = RpcClientService.newBlockingStub(channel);
        controller = channel.newRpcController();
        java.util.Locale currentLocale = java.util.Locale.getDefault();
        LoginRequest loginRequest = LoginRequest.newBuilder().setAppId(ClientVersion.APP_ID.getValue())
                .setVersionId(ClientVersion.APP_ID_VERSION.getVersionInfo())
                .setClientId(NodeId.generate().getValue())
                .setLocale(Locale.newBuilder()
                        .setCountry(currentLocale.getCountry() == null ? "" : currentLocale.getCountry())
                        .setLanguage(currentLocale.getLanguage() == null ? "" : currentLocale.getLanguage())
                        .setVariant(currentLocale.getVariant() == null ? "" : currentLocale.getVariant())
                        .build())
                .setUsername(mParameters.getUsername()).setPassword(new String(mParameters.getPassword()))
                .build();
        LoginResponse loginResponse = clientService.login(controller, loginRequest);
        sessionId = new SessionId(loginResponse.getSessionId());
    } catch (IOException | ServiceException e) {
        throw new RemoteException(e);
    }
}

From source file:org.marketcetera.marketdata.core.rpc.MarketDataRpcClient.java

/**
 * Starts the remote service./*from   w  ww. ja  va2s.  com*/
 *
 * @throws IOException if an error occurs starting the service
 * @throws ServiceException if an error occurs starting the service
 */
private void startService() throws IOException, ServiceException {
    try (CloseableLock startLock = CloseableLock.create(serviceLock.writeLock())) {
        startLock.lock();
        SLF4JLoggerProxy.debug(this, "Connecting to RPC server at {}:{}", //$NON-NLS-1$
                hostname, port);
        PeerInfo server = new PeerInfo(hostname, port);
        DuplexTcpClientPipelineFactory clientFactory = new DuplexTcpClientPipelineFactory();
        executor = new ThreadPoolCallExecutor(1, 10);
        clientFactory.setRpcServerCallExecutor(executor);
        clientFactory.setConnectResponseTimeoutMillis(10000);
        clientFactory.setCompression(true);
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(new NioEventLoopGroup());
        bootstrap.handler(clientFactory);
        bootstrap.channel(NioSocketChannel.class);
        bootstrap.option(ChannelOption.TCP_NODELAY, true);
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
        bootstrap.option(ChannelOption.SO_SNDBUF, 1048576);
        bootstrap.option(ChannelOption.SO_RCVBUF, 1048576);
        channel = clientFactory.peerWith(server, bootstrap);
        clientService = RpcMarketDataService.newBlockingStub(channel);
        controller = channel.newRpcController();
        java.util.Locale currentLocale = java.util.Locale.getDefault();
        LoginRequest loginRequest = LoginRequest.newBuilder().setAppId(APP_ID.getValue())
                .setVersionId(APP_ID_VERSION.getVersionInfo()).setClientId(NodeId.generate().getValue())
                .setLocale(Locale.newBuilder()
                        .setCountry(currentLocale.getCountry() == null ? "" : currentLocale.getCountry()) //$NON-NLS-1$
                        .setLanguage(currentLocale.getLanguage() == null ? "" : currentLocale.getLanguage()) //$NON-NLS-1$
                        .setVariant(currentLocale.getVariant() == null ? "" : currentLocale.getVariant()) //$NON-NLS-1$
                        .build()).setUsername(username).setPassword(new String(password)).build();
        LoginResponse loginResponse = clientService.login(controller, loginRequest);
        sessionId = new SessionId(loginResponse.getSessionId());
        setServerStatus(true);
    }
}

From source file:org.marketcetera.saclient.rpc.RpcSAClientImpl.java

/**
 * Starts the remote service./*from  www  .j av a  2 s. c om*/
 *
 * @throws IOException if an error occurs starting the service
 * @throws ServiceException if an error occurs starting the service
 */
private void startService() throws IOException, ServiceException {
    try (CloseableLock startLock = CloseableLock.create(serviceLock.writeLock())) {
        startLock.lock();
        SLF4JLoggerProxy.debug(this, "Connecting to RPC server at {}:{}", //$NON-NLS-1$
                parameters.getHostname(), parameters.getPort());
        PeerInfo server = new PeerInfo(parameters.getHostname(), parameters.getPort());
        DuplexTcpClientPipelineFactory clientFactory = new DuplexTcpClientPipelineFactory();
        executor = new ThreadPoolCallExecutor(1, 10);
        clientFactory.setRpcServerCallExecutor(executor);
        clientFactory.setConnectResponseTimeoutMillis(10000);
        clientFactory.setCompression(true);
        Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(new NioEventLoopGroup());
        bootstrap.handler(clientFactory);
        bootstrap.channel(NioSocketChannel.class);
        bootstrap.option(ChannelOption.TCP_NODELAY, true);
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
        bootstrap.option(ChannelOption.SO_SNDBUF, 1048576);
        bootstrap.option(ChannelOption.SO_RCVBUF, 1048576);
        channel = clientFactory.peerWith(server, bootstrap);
        clientService = RpcSAClientService.newBlockingStub(channel);
        controller = channel.newRpcController();
        java.util.Locale currentLocale = java.util.Locale.getDefault();
        LoginRequest loginRequest = LoginRequest.newBuilder().setAppId(SAClientVersion.APP_ID.getValue())
                .setVersionId(SAClientVersion.APP_ID_VERSION.getVersionInfo())
                .setClientId(NodeId.generate().getValue())
                .setLocale(Locale.newBuilder()
                        .setCountry(currentLocale.getCountry() == null ? "" : currentLocale.getCountry()) //$NON-NLS-1$
                        .setLanguage(currentLocale.getLanguage() == null ? "" : currentLocale.getLanguage()) //$NON-NLS-1$
                        .setVariant(currentLocale.getVariant() == null ? "" : currentLocale.getVariant()) //$NON-NLS-1$
                        .build()).setUsername(parameters.getUsername()).setPassword(new String(parameters.getPassword()))
                .build();
        LoginResponse loginResponse = clientService.login(controller, loginRequest);
        sessionId = new SessionId(loginResponse.getSessionId());
        connectionStatusChanged(isRunning(), true);
    }
}

From source file:org.marketcetera.util.rpc.RpcServer.java

@Override
@PostConstruct//from  w  ww .j a  va  2 s  .  c o m
public synchronized void start() {
    Validate.notNull(hostname);
    Validate.isTrue(port > 0 && port < 65536);
    Validate.notNull(sessionManager);
    Validate.notNull(authenticator);
    Validate.isTrue(threadPoolCore > 0);
    Validate.isTrue(threadPoolMax > 0);
    Validate.isTrue(threadPoolMax >= threadPoolCore);
    Validate.isTrue(sendBufferSize > 0);
    Validate.isTrue(receiveBufferSize > 0);
    Validate.notEmpty(serviceSpecs);
    Messages.SERVER_STARTING.info(this, hostname, port);
    if (isRunning()) {
        stop();
    }
    try {
        reportContext = JAXBContext.newInstance(
                contextClassProvider == null ? new Class<?>[0] : contextClassProvider.getContextClasses());
        marshaller = reportContext.createMarshaller();
        unmarshaller = reportContext.createUnmarshaller();
    } catch (JAXBException e) {
        SLF4JLoggerProxy.error(this, e);
        throw new RuntimeException(e);
    }
    PeerInfo serverInfo = new PeerInfo(getRpcHostname(), getRpcPort());
    executor = new ThreadPoolCallExecutor(threadPoolCore, threadPoolMax);
    DuplexTcpServerPipelineFactory serverFactory = new DuplexTcpServerPipelineFactory(serverInfo);
    serverFactory.setRpcServerCallExecutor(executor);
    ServerBootstrap bootstrap = new ServerBootstrap();
    bootstrap.group(
            new NioEventLoopGroup(0, new RenamingThreadFactoryProxy("boss", Executors.defaultThreadFactory())),
            new NioEventLoopGroup(0,
                    new RenamingThreadFactoryProxy("worker", Executors.defaultThreadFactory())));
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.childHandler(serverFactory);
    bootstrap.localAddress(serverInfo.getPort());
    bootstrap.option(ChannelOption.SO_SNDBUF, sendBufferSize);
    bootstrap.option(ChannelOption.SO_RCVBUF, receiveBufferSize);
    bootstrap.childOption(ChannelOption.SO_RCVBUF, receiveBufferSize);
    bootstrap.childOption(ChannelOption.SO_SNDBUF, sendBufferSize);
    bootstrap.option(ChannelOption.TCP_NODELAY, noDelay);
    for (RpcServiceSpec<SessionClazz> serviceSpec : serviceSpecs) {
        serviceSpec.setRpcServerServices(this);
        BlockingService activeService = serviceSpec.generateService();
        serverFactory.getRpcServiceRegistry().registerService(activeService);
        Messages.SERVICE_STARTING.info(this, serviceSpec.getDescription());
    }
    channelToken = bootstrap.bind();
    while (!channelToken.isDone()) {
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    // TODO throw exception?
    running.set(channelToken.isSuccess());
    //RpcClientConnectionRegistry clientRegistry = new RpcClientConnectionRegistry();
    //serverFactory.registerConnectionEventListener(clientRegistry);
}

From source file:org.mbmg.udp.server.Server.java

License:Apache License

public void run() throws Exception {
    EventLoopGroup group = new NioEventLoopGroup();
    try {//from   w  ww  . j av  a 2  s .c  o m
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioDatagramChannel.class).option(ChannelOption.SO_RCVBUF, 1048576)
                .option(ChannelOption.SO_SNDBUF, 1048576)
                .handler(new ServerHandler(graphiteHost, graphitePort));
        b.bind(port).sync().channel().closeFuture().await();
    } finally {
        group.shutdownGracefully();
    }
}

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

License:Apache License

/**
 * Tell controller that we're ready to accept switches loop.
 *//*from w w w.  java2s  .co m*/
public void run() {

    try {
        final ServerBootstrap bootstrap = createServerBootStrap();
        bootstrap.option(ChannelOption.SO_REUSEADDR, true);
        bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
        bootstrap.childOption(ChannelOption.SO_SNDBUF, Controller.SEND_BUFFER_SIZE);
        //            bootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK,
        //                                  new WriteBufferWaterMark(8 * 1024, 32 * 1024));

        bootstrap.childHandler(new OFChannelInitializer(this, null, sslContext));

        openFlowPorts.forEach(port -> {
            // TODO revisit if this is best way to listen to multiple ports
            cg.add(bootstrap.bind(port).syncUninterruptibly().channel());
            log.info("Listening for switch connections on {}", port);
        });

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

From source file:org.opencloudb.config.model.SystemConfig.java

License:Open Source License

public void setSocketParams(AbstractBootstrap<?, ?> bootstrap, boolean isFrontChannel) throws IOException {
    int sorcvbuf = 0;
    int sosndbuf = 0;
    int soNoDelay = 0;
    if (isFrontChannel) {
        sorcvbuf = getFrontsocketsorcvbuf();
        sosndbuf = getFrontsocketsosndbuf();
        soNoDelay = getFrontSocketNoDelay();
    } else {//from  w w  w  .ja  va  2s. c  o m
        sorcvbuf = getBacksocketsorcvbuf();
        sosndbuf = getBacksocketsosndbuf();
        soNoDelay = getBackSocketNoDelay();
    }

    bootstrap.option(ChannelOption.SO_RCVBUF, sorcvbuf);
    bootstrap.option(ChannelOption.SO_SNDBUF, sosndbuf);
    bootstrap.option(ChannelOption.TCP_NODELAY, soNoDelay == 1);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    bootstrap.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 1024 * 1024);
}

From source file:org.teiid.transport.SocketListener.java

License:Apache License

public SocketListener(final InetSocketAddress address, final int inputBufferSize, final int outputBufferSize,
        int maxWorkers, final SSLConfiguration config, final ClientServiceRegistryImpl csr,
        final StorageManager storageManager) {

    if (config != null) {
        this.isClientEncryptionEnabled = config.isClientEncryptionEnabled();
    }//  w  ww .  j  a  v  a 2s .c  o m
    this.csr = csr;

    NamedThreadFactory nettyPool = new NamedThreadFactory("NIO"); //$NON-NLS-1$
    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_TRANSPORT, MessageLevel.DETAIL)) {
        LogManager.logDetail(LogConstants.CTX_TRANSPORT,
                "server = " + address.getAddress() + "binding to port:" + address.getPort()); //$NON-NLS-1$ //$NON-NLS-2$
    }

    if (maxWorkers == 0) {
        maxWorkers = Math.max(4, PropertiesUtils.getIntProperty(System.getProperties(),
                "io.netty.eventLoopThreads", 2 * Runtime.getRuntime().availableProcessors())); //$NON-NLS-1$
    }
    EventLoopGroup workers = new NioEventLoopGroup(maxWorkers, nettyPool);

    bootstrap = new ServerBootstrap();
    bootstrap.group(workers).channel(NioServerSocketChannel.class);
    this.channelHandler = createChannelHandler();
    bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            configureChannelPipeline(pipeline, config, storageManager);
        }
    });
    if (inputBufferSize != 0) {
        bootstrap.childOption(ChannelOption.SO_RCVBUF, new Integer(inputBufferSize));
    }
    if (outputBufferSize != 0) {
        bootstrap.childOption(ChannelOption.SO_SNDBUF, new Integer(outputBufferSize));
    }
    bootstrap.childOption(ChannelOption.TCP_NODELAY, Boolean.TRUE);
    bootstrap.childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE);
    ChannelFuture future = bootstrap.bind(address);
    future.syncUninterruptibly();
    this.serverChannel = future.channel();
}