List of usage examples for io.netty.channel.epoll EpollChannelOption EPOLL_MODE
ChannelOption EPOLL_MODE
To view the source code for io.netty.channel.epoll EpollChannelOption EPOLL_MODE.
Click Source Link
From source file:alluxio.network.netty.NettyClient.java
License:Apache License
/** * Creates and returns a new Netty client bootstrap for clients to connect to remote servers. * * @param address the socket address//from www . j a v a 2 s.c o m * @return the new client {@link Bootstrap} */ public static Bootstrap createClientBootstrap(SocketAddress address) { final Bootstrap boot = new Bootstrap(); boot.group(WORKER_GROUP).channel( NettyUtils.getClientChannelClass(NettyUtils.CHANNEL_TYPE, !(address instanceof InetSocketAddress))); boot.option(ChannelOption.SO_KEEPALIVE, true); boot.option(ChannelOption.TCP_NODELAY, true); boot.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); if (NettyUtils.CHANNEL_TYPE == ChannelType.EPOLL) { boot.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } // After 10 missed heartbeat attempts and no write activity, the server will close the channel. final long timeoutMs = Configuration.getMs(PropertyKey.NETWORK_NETTY_HEARTBEAT_TIMEOUT_MS); final long heartbeatPeriodMs = Math.max(timeoutMs / 10, 1); boot.handler(new ChannelInitializer<Channel>() { @Override public void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(RPCMessage.createFrameDecoder()); pipeline.addLast(ENCODER); pipeline.addLast(DECODER); pipeline.addLast(new IdleStateHandler(0, heartbeatPeriodMs, 0, TimeUnit.MILLISECONDS)); pipeline.addLast(new IdleWriteHandler()); } }); return boot; }
From source file:alluxio.worker.grpc.GrpcDataServer.java
License:Apache License
private GrpcServerBuilder createServerBuilder(String hostName, SocketAddress bindAddress, ChannelType type) { GrpcServerBuilder builder = GrpcServerBuilder.forAddress(hostName, bindAddress, ServerConfiguration.global(), ServerUserState.global()); int bossThreadCount = ServerConfiguration.getInt(PropertyKey.WORKER_NETWORK_NETTY_BOSS_THREADS); // If number of worker threads is 0, Netty creates (#processors * 2) threads by default. int workerThreadCount = ServerConfiguration.getInt(PropertyKey.WORKER_NETWORK_NETTY_WORKER_THREADS); String dataServerEventLoopNamePrefix = "data-server-" + ((mSocketAddress instanceof DomainSocketAddress) ? "domain-socket" : "tcp-socket"); mBossGroup = NettyUtils.createEventLoop(type, bossThreadCount, dataServerEventLoopNamePrefix + "-boss-%d", true);// w w w . j a v a 2 s . co m mWorkerGroup = NettyUtils.createEventLoop(type, workerThreadCount, dataServerEventLoopNamePrefix + "-worker-%d", true); Class<? extends ServerChannel> socketChannelClass = NettyUtils .getServerChannelClass(mSocketAddress instanceof DomainSocketAddress, ServerConfiguration.global()); if (type == ChannelType.EPOLL) { builder.withChildOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } return builder.bossEventLoopGroup(mBossGroup).workerEventLoopGroup(mWorkerGroup) .channelType(socketChannelClass) .withChildOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) // set write buffer // this is the default, but its recommended to set it in case of change in future netty. .withChildOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, (int) ServerConfiguration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_WATERMARK_HIGH)) .withChildOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, (int) ServerConfiguration.getBytes(PropertyKey.WORKER_NETWORK_NETTY_WATERMARK_LOW)); }
From source file:com.yahoo.pulsar.broker.service.BrokerService.java
License:Apache License
public void start() throws Exception { this.producerNameGenerator = new DistributedIdGenerator(pulsar.getZkClient(), producerNameGeneratorPath, pulsar.getConfiguration().getClusterName()); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.group(acceptorGroup, workerGroup); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1024, 16 * 1024, 1 * 1024 * 1024)); if (workerGroup instanceof EpollEventLoopGroup) { bootstrap.channel(EpollServerSocketChannel.class); bootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else {//from w ww. ja v a 2 s . c o m bootstrap.channel(NioServerSocketChannel.class); } ServiceConfiguration serviceConfig = pulsar.getConfiguration(); bootstrap.childHandler(new PulsarChannelInitializer(this, serviceConfig, false)); // Bind and start to accept incoming connections. bootstrap.bind(new InetSocketAddress(pulsar.getBindAddress(), port)).sync(); log.info("Started Pulsar Broker service on port {}", port); if (serviceConfig.isTlsEnabled()) { ServerBootstrap tlsBootstrap = bootstrap.clone(); tlsBootstrap.childHandler(new PulsarChannelInitializer(this, serviceConfig, true)); tlsBootstrap.bind(new InetSocketAddress(pulsar.getBindAddress(), tlsPort)).sync(); log.info("Started Pulsar Broker TLS service on port {}", tlsPort); } // start other housekeeping functions this.startStatsUpdater(); this.startInactivityMonitor(); this.startMessageExpiryMonitor(); this.startBacklogQuotaChecker(); }
From source file:com.yahoo.pulsar.discovery.service.DiscoveryService.java
License:Apache License
/** * starts server to handle discovery-request from client-channel * /* www.ja v a 2 s . c o m*/ * @throws Exception */ public void startServer() throws Exception { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.group(acceptorGroup, workerGroup); bootstrap.childOption(ChannelOption.TCP_NODELAY, true); bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1024, 16 * 1024, 1 * 1024 * 1024)); if (workerGroup instanceof EpollEventLoopGroup) { bootstrap.channel(EpollServerSocketChannel.class); bootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else { bootstrap.channel(NioServerSocketChannel.class); } bootstrap.childHandler(new ServiceChannelInitializer(this, config, false)); // Bind and start to accept incoming connections. bootstrap.bind(config.getServicePort()).sync(); LOG.info("Started Pulsar Broker service on port {}", config.getWebServicePort()); if (config.isTlsEnabled()) { ServerBootstrap tlsBootstrap = bootstrap.clone(); tlsBootstrap.childHandler(new ServiceChannelInitializer(this, config, true)); tlsBootstrap.bind(config.getServicePortTls()).sync(); LOG.info("Started Pulsar Broker TLS service on port {}", config.getWebServicePortTls()); } }
From source file:de.jackwhite20.apex.tcp.ApexSocket.java
License:Open Source License
@Override public Channel bootstrap(EventLoopGroup bossGroup, EventLoopGroup workerGroup, String ip, int port, int backlog, int readTimeout, int writeTimeout) throws Exception { logger.info("Bootstrapping socket server"); ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup) .channel(PipelineUtils.getServerChannel()) .childHandler(new ApexSocketChannelInitializer(readTimeout, writeTimeout)) .childOption(ChannelOption.AUTO_READ, false); if (PipelineUtils.isEpoll()) { bootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); logger.debug("Epoll mode is now level triggered"); }//from w ww . ja va2 s . co m return bootstrap.option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.SO_BACKLOG, backlog) .bind(ip, port).sync().channel(); }
From source file:de.jackwhite20.apex.udp.ApexDatagram.java
License:Open Source License
@Override public Channel bootstrap(EventLoopGroup bossGroup, EventLoopGroup workerGroup, String ip, int port, int backlog, int readTimeout, int writeTimeout) throws Exception { logger.info("Bootstrapping datagram server"); Bootstrap bootstrap = new Bootstrap().group(workerGroup).channel(PipelineUtils.getDatagramChannel()) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .handler(new DatagramUpstreamHandler()); if (PipelineUtils.isEpoll()) { bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); logger.debug("Epoll mode is now level triggered"); }/*from w w w. j a v a 2 s.c o m*/ return bootstrap.bind(ip, port).sync().channel(); }
From source file:org.apache.pulsar.common.util.netty.EventLoopUtil.java
License:Apache License
public static void enableTriggeredMode(ServerBootstrap bootstrap) { if (Epoll.isAvailable()) { bootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); }//from ww w. j a v a 2 s. c om }
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 {/*w ww.j av a 2 s . com*/ 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 {// www .j a v a2 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.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 v a 2s. c om*/ 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; }