List of usage examples for io.netty.channel ChannelOption MAX_MESSAGES_PER_READ
ChannelOption MAX_MESSAGES_PER_READ
To view the source code for io.netty.channel ChannelOption MAX_MESSAGES_PER_READ.
Click Source Link
From source file:com.ancun.netty.httpserver.HttpServer.java
License:Apache License
private void setBootstrapOptions(ServerBootstrap bootstrap) { bootstrap.option(ChannelOption.SO_KEEPALIVE, useKeepAlive()); bootstrap.option(ChannelOption.SO_BACKLOG, 1024); bootstrap.option(ChannelOption.TCP_NODELAY, useTcpNoDelay()); bootstrap.option(ChannelOption.SO_KEEPALIVE, serverSettings.isKeepAlive()); bootstrap.option(ChannelOption.SO_REUSEADDR, shouldReuseAddress()); bootstrap.option(ChannelOption.SO_LINGER, getSoLinger()); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectTimeoutMillis()); bootstrap.option(ChannelOption.SO_RCVBUF, getReceiveBufferSize()); bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE); bootstrap.childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)); bootstrap.childOption(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE); bootstrap.childOption(ChannelOption.SO_RCVBUF, getReceiveBufferSize()); bootstrap.childOption(ChannelOption.SO_REUSEADDR, shouldReuseAddress()); }
From source file:jlibs.wamp4j.netty.NettyClientEndpoint.java
License:Apache License
@Override public void connect(final URI uri, final ConnectListener listener, final String... subProtocols) { final SslContext sslContext; if ("wss".equals(uri.getScheme())) { try {/*from ww w. j a v a 2s . c o m*/ if (sslSettings == null) { sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE) .build(); } else { sslContext = SslContextBuilder.forClient().trustManager(sslSettings.trustCertChainFile) .keyManager(sslSettings.certificateFile, sslSettings.keyFile, sslSettings.keyPassword) .build(); } } catch (Throwable thr) { listener.onError(thr); return; } } else if ("ws".equals(uri.getScheme())) sslContext = null; else throw new IllegalArgumentException("invalid protocol: " + uri.getScheme()); final int port = uri.getPort() == -1 ? (sslContext == null ? 80 : 443) : uri.getPort(); Bootstrap bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.MAX_MESSAGES_PER_READ, 50000).option(ChannelOption.WRITE_SPIN_COUNT, 50000) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { if (sslContext != null) ch.pipeline().addLast(sslContext.newHandler(ch.alloc(), uri.getHost(), port)); WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, Util.toString(subProtocols), false, new DefaultHttpHeaders()); ch.pipeline().addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), new WebSocketClientProtocolHandler(handshaker) { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { super.exceptionCaught(ctx, cause); listener.onError(cause); } }, new HandshakeListener(handshaker, listener)); } }); bootstrap.connect(uri.getHost(), port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { assert !future.channel().isOpen(); listener.onError(future.cause()); } } }); }
From source file:jlibs.wamp4j.netty.NettyServerEndpoint.java
License:Apache License
@Override public void bind(final URI uri, final String subProtocols[], final AcceptListener listener) { final SslContext sslContext; if ("wss".equals(uri.getScheme())) { try {//from w ww.j a v a 2 s . co m if (sslSettings == null) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslSettings = new SSLSettings().keyFile(ssc.privateKey()).certificateFile(ssc.certificate()); } ClientAuth clientAuth = ClientAuth.values()[sslSettings.clientAuthentication.ordinal()]; sslContext = SslContextBuilder .forServer(sslSettings.certificateFile, sslSettings.keyFile, sslSettings.keyPassword) .clientAuth(clientAuth).trustManager(sslSettings.trustCertChainFile).build(); } catch (Throwable thr) { listener.onError(thr); return; } } else if ("ws".equals(uri.getScheme())) sslContext = null; else throw new IllegalArgumentException("invalid protocol: " + uri.getScheme()); int port = uri.getPort(); if (port == -1) port = sslContext == null ? 80 : 443; ServerBootstrap bootstrap = new ServerBootstrap().group(eventLoopGroup) .channel(NioServerSocketChannel.class) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.MAX_MESSAGES_PER_READ, 50000) .childOption(ChannelOption.WRITE_SPIN_COUNT, 50000) .childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { if (sslContext != null) ch.pipeline().addLast(sslContext.newHandler(ch.alloc())); ch.pipeline().addLast(new HttpServerCodec(), new HttpObjectAggregator(65536), new Handshaker(uri, listener, subProtocols)); } }); bootstrap.bind(uri.getHost(), port).addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { channel = future.channel(); channel.attr(ACCEPT_LISTENER).set(listener); listener.onBind(NettyServerEndpoint.this); } else listener.onError(future.cause()); } }); }
From source file:org.ballerinalang.test.agent.server.WebServer.java
License:Open Source License
/** * Initializes the server, socket, and channel. * * @param loopGroup The event loop group. * @param serverChannelClass The socket channel class. * @throws InterruptedException on interruption. *//*from w ww . ja v a 2 s . c om*/ private void start(final EventLoopGroup loopGroup, final Class<? extends ServerChannel> serverChannelClass) throws InterruptedException { try { final InetSocketAddress inet = new InetSocketAddress(host, port); final ServerBootstrap serverBootstrap = new ServerBootstrap(); serverBootstrap.option(ChannelOption.SO_BACKLOG, 1024); serverBootstrap.option(ChannelOption.SO_REUSEADDR, true); serverBootstrap.group(loopGroup).channel(serverChannelClass).childHandler(new WebServerInitializer()); serverBootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE); serverBootstrap.childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true)); serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, true); serverBootstrap.childOption(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE); final Channel ch = serverBootstrap.bind(inet).sync().channel(); ch.closeFuture().sync(); } finally { loopGroup.shutdownGracefully().sync(); } }
From source file:org.opendaylight.protocol.bgp.rib.impl.BGPDispatcherImpl.java
License:Open Source License
protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) { final Bootstrap bootstrap = new Bootstrap(); if (Epoll.isAvailable()) { bootstrap.channel(EpollSocketChannel.class); bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else {/*from w w w .j a v a2 s .c om*/ bootstrap.channel(NioSocketChannel.class); } if (keys.isPresent()) { if (Epoll.isAvailable()) { bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys.get()); } else { throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause()); } } // Make sure we are doing round-robin processing bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1); bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); bootstrap.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, HIGH_WATER_MARK); bootstrap.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, LOW_WATER_MARK); if (bootstrap.group() == null) { bootstrap.group(workerGroup); } return bootstrap; }
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 ww . j a v a 2 s . c o 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.bgp.rib.impl.TestClientDispatcher.java
License:Open Source License
protected TestClientDispatcher(final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MessageRegistry messageRegistry, final InetSocketAddress localAddress) { this.disp = new BGPDispatcherImpl(messageRegistry, bossGroup, workerGroup) { @Override/*w ww .j av a 2 s. co m*/ protected Bootstrap createClientBootStrap(final Optional<KeyMapping> keys, final EventLoopGroup workerGroup) { final Bootstrap bootstrap = new Bootstrap(); if (Epoll.isAvailable()) { bootstrap.channel(EpollSocketChannel.class); } else { bootstrap.channel(NioSocketChannel.class); } // Make sure we are doing round-robin processing bootstrap.option(ChannelOption.MAX_MESSAGES_PER_READ, 1); bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); if (bootstrap.group() == null) { bootstrap.group(workerGroup); } bootstrap.localAddress(localAddress); bootstrap.option(ChannelOption.SO_REUSEADDR, true); return bootstrap; } }; this.hf = new BGPHandlerFactory(messageRegistry); this.localAddress = localAddress; this.defaultAddress = localAddress; }
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//from w w w.j a va2 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.opendaylight.protocol.pcep.pcc.mock.protocol.PCCDispatcherImpl.java
License:Open Source License
@Override public Future<PCEPSession> createClient(@Nonnull final InetSocketAddress remoteAddress, @Nonnull final long reconnectTime, @Nonnull final PCEPSessionListenerFactory listenerFactory, @Nonnull final PCEPSessionNegotiatorFactory negotiatorFactory, @Nonnull final KeyMapping keys, @Nullable final InetSocketAddress localAddress, @Nonnull final BigInteger dbVersion) { final Bootstrap b = new Bootstrap(); b.group(this.workerGroup); b.localAddress(localAddress);//from ww w .j a v a 2 s . c o m final Optional<KeyMapping> optionalKey = Optional.fromNullable(keys); setChannelFactory(b, optionalKey); b.option(ChannelOption.SO_KEEPALIVE, true); b.option(ChannelOption.SO_REUSEADDR, true); b.option(ChannelOption.MAX_MESSAGES_PER_READ, 1); final long retryTimer = reconnectTime == -1 ? 0 : reconnectTime; final PCCReconnectPromise promise = new PCCReconnectPromise(remoteAddress, (int) retryTimer, CONNECT_TIMEOUT, b); final ChannelInitializer<SocketChannel> channelInitializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) throws Exception { ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getDecoders()); ch.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, ch, promise, new PCCPeerProposal(dbVersion))); ch.pipeline().addLast(PCCDispatcherImpl.this.factory.getEncoders()); ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { @Override public void channelInactive(final ChannelHandlerContext ctx) throws Exception { if (promise.isCancelled()) { return; } if (!promise.isInitialConnectFinished()) { LOG.debug("Connection to {} was dropped during negotiation, reattempting", remoteAddress); return; } LOG.debug("Reconnecting after connection to {} was dropped", remoteAddress); PCCDispatcherImpl.this.createClient(remoteAddress, reconnectTime, listenerFactory, negotiatorFactory, keys, localAddress, dbVersion); } }); } }; b.handler(channelInitializer); promise.connect(); return promise; }