List of usage examples for io.netty.channel ChannelOption SO_RCVBUF
ChannelOption SO_RCVBUF
To view the source code for io.netty.channel ChannelOption SO_RCVBUF.
Click Source Link
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 w ww .j ava 2 s . co 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.// ww w. j a v 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$ 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 w w w.jav a 2s . c o m*/ * * @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//ww w. ja v a 2s. c om 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 a v a 2s. 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.midonet.util.netty.ServerFrontEnd.java
License:Apache License
@Override protected void doStart() { try {/*from w w w .jav a 2 s . c o m*/ if (datagram) { log.info("Starting Netty UDP server on port {}", port); Bootstrap boot = new Bootstrap(); boot.group(wrkr).channel(NioDatagramChannel.class).handler(adapter); if (rcvbufSize != null) boot.option(ChannelOption.SO_RCVBUF, rcvbufSize).option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(rcvbufSize)); sock = boot.bind(port).sync(); } else { log.info("Starting Netty TCP server on port {}", port); ServerBootstrap boot = new ServerBootstrap(); boot.group(boss, wrkr).channel(NioServerSocketChannel.class).childHandler(adapter) .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_KEEPALIVE, true); sock = boot.bind(port).sync(); } log.info("Netty server started"); notifyStarted(); } catch (InterruptedException e) { log.warn("Netty server start interrupted"); Thread.currentThread().interrupt(); notifyFailed(e); } }
From source file:org.onlab.netty.NettyMessaging.java
License:Apache License
private void startAcceptingConnections() throws InterruptedException { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024); b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024); b.option(ChannelOption.SO_RCVBUF, 1048576); b.option(ChannelOption.TCP_NODELAY, true); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.group(serverGroup, clientGroup);//w w w . j ava2 s .c o m 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.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);//from w w w . ja v 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.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 v a 2 s . co 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); }