public void start() throws InterruptedException { final EventLoopGroup workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(workerGroup) .channel(Epoll.isAvailable() ? EpollSocketChannel.class : NioSocketChannel.class) .handler(new OpenCloudChannelInitializer(this)) .connect(this.host, this.port).sync().channel().closeFuture().syncUninterruptibly(); } catch (Exception ex) { if (ex.getClass().getSimpleName().equals("AnnotatedConnectException")) { System.err.println("Cannot connect to master!"); channel.close(); } else { ex.printStackTrace(); } } finally { workerGroup.shutdownGracefully(); System.out.println("Netty client stopped"); Runtime.getRuntime().halt(0); } }
public void connectPlugin(String host, int port) { ManagedChannel channel = NettyChannelBuilder.forAddress(host, port) .negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption .keepAliveTime(1, TimeUnit.MINUTES) .keepAliveTimeout(5, TimeUnit.SECONDS) .directExecutor() .channelType(EpollSocketChannel.class) .eventLoopGroup(new EpollEventLoopGroup()) .build(); PluginManagerGrpc.PluginManagerBlockingStub blocking = PluginManagerGrpc.newBlockingStub(channel); PluginManagerGrpc.PluginManagerStub async = PluginManagerGrpc.newStub(channel); ServiceConnection connection = ServiceConnection.builder() .channel(channel) .blockingStub(blocking) .asyncStub(async) .build(); this.pluginConnections.put(PLUGIN_MANAGER, connection); }
/** * Attempts to determine the {@link Channel} class that corresponds to the given * event loop group. * * @param eventLoopGroup the event loop group to determine the {@link Channel} for * @return A {@link Channel} class for the given event loop group. */ public static Class<? extends Channel> resolveSocketChannelClass(EventLoopGroup eventLoopGroup) { if (eventLoopGroup instanceof DelegatingEventLoopGroup) { return resolveSocketChannelClass(((DelegatingEventLoopGroup) eventLoopGroup).getDelegate()); } if (eventLoopGroup instanceof NioEventLoopGroup) { return NioSocketChannel.class; } if (eventLoopGroup instanceof EpollEventLoopGroup) { return EpollSocketChannel.class; } String socketFqcn = KNOWN_EL_GROUPS.get(eventLoopGroup.getClass().getName()); if (socketFqcn == null) { throw new IllegalArgumentException("Unknown event loop group : " + eventLoopGroup.getClass()); } return invokeSafely(() -> (Class<? extends Channel>) Class.forName(socketFqcn)); }
private static Pair<EventLoopGroup, Class<? extends Channel>> createEventLoopGroup( Configuration conf) { // Max amount of threads to use. 0 lets Netty decide based on amount of cores int maxThreads = conf.getInt(CLIENT_MAX_THREADS, 0); // Config to enable native transport. Does not seem to be stable at time of implementation // although it is not extensively tested. boolean epollEnabled = conf.getBoolean(USE_NATIVE_TRANSPORT, false); // Use the faster native epoll transport mechanism on linux if enabled if (epollEnabled && JVM.isLinux() && JVM.isAmd64()) { if (LOG.isDebugEnabled()) { LOG.debug("Create EpollEventLoopGroup with maxThreads = " + maxThreads); } return new Pair<EventLoopGroup, Class<? extends Channel>>(new EpollEventLoopGroup(maxThreads, Threads.newDaemonThreadFactory("AsyncRpcChannel")), EpollSocketChannel.class); } else { if (LOG.isDebugEnabled()) { LOG.debug("Create NioEventLoopGroup with maxThreads = " + maxThreads); } return new Pair<EventLoopGroup, Class<? extends Channel>>(new NioEventLoopGroup(maxThreads, Threads.newDaemonThreadFactory("AsyncRpcChannel")), NioSocketChannel.class); } }
@Override public void init(final InetAddress address, final int port, final boolean useEpoll) { final Class<? extends SocketChannel> socketChannelClass; final LazyValue<? extends EventLoopGroup> lazyInit; if ((Epoll.isAvailable()) && useEpoll) { socketChannelClass = EpollSocketChannel.class; lazyInit = this.epollEventLoopGroupLazyValue; CoreMain.debug("[Netty] Using epoll channel type"); } else { socketChannelClass = NioSocketChannel.class; lazyInit = this.nioEventLoopGroupLazyValue; CoreMain.debug("[Netty] Using default channel type"); } this.channelFuture = new Bootstrap().channel(socketChannelClass).handler(new ClientConnectionChannel(this)).group(lazyInit.get()).remoteAddress(address, port).connect().syncUninterruptibly(); }
public void connect(String apiKey) { Bootstrap bootstrap = new Bootstrap(); Class<? extends Channel> channelClazz; if (Epoll.isAvailable()) { channelClazz = EpollSocketChannel.class; eventLoopGroup = new EpollEventLoopGroup(); } else { channelClazz = NioSocketChannel.class; eventLoopGroup = new NioEventLoopGroup(); } bootstrap.group(eventLoopGroup) .channel(channelClazz) .option(ChannelOption.SO_KEEPALIVE, true) // TODO: add function to get data class by topic and add handler .remoteAddress(host, port) .connect(); }
private void initEventLoopGroup() { // try Epoll first and if that does work, use nio. try { clientGroup = new EpollEventLoopGroup(); serverGroup = new EpollEventLoopGroup(); serverChannelClass = EpollServerSocketChannel.class; clientChannelClass = EpollSocketChannel.class; return; } catch (Throwable t) { log.warn("Failed to initialize native (epoll) transport. Reason: {}. Proceeding with nio.", t.getMessage()); } clientGroup = new NioEventLoopGroup(); serverGroup = new NioEventLoopGroup(); serverChannelClass = NioServerSocketChannel.class; clientChannelClass = NioSocketChannel.class; }
private void initEventLoopGroup() { // try Epoll first and if that does work, use nio. try { clientGroup = new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-client-%d", log)); serverGroup = new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-server-%d", log)); serverChannelClass = EpollServerSocketChannel.class; clientChannelClass = EpollSocketChannel.class; return; } catch (Throwable e) { log.debug("Failed to initialize native (epoll) transport. " + "Reason: {}. Proceeding with nio.", e.getMessage()); } clientGroup = new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-client-%d", log)); serverGroup = new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-server-%d", log)); serverChannelClass = NioServerSocketChannel.class; clientChannelClass = NioSocketChannel.class; }
public static ChannelConfiguration clientConfig(EventLoopGroup workerGroup) { EventLoopGroup parent = workerGroup; if (parent instanceof EventLoop) { parent = ((EventLoop) workerGroup).parent(); } Class<? extends Channel> channelClass; if (parent instanceof EpollEventLoopGroup) { channelClass = EpollSocketChannel.class; } else if (parent instanceof NioEventLoopGroup) { channelClass = NioSocketChannel.class; } else { throw new RuntimeException("Unsupported EventLoopGroup " + workerGroup.getClass()); } return new ChannelConfiguration(workerGroup, channelClass); }
/** * This method will configure a worker EventLoopGroup and a Channel for use by a client. It will * try to use the correct SocketChannel for the provided workerGroup. * * @param workerGroup uses EventLoopGroup in the ClientChannelConfiguration * @return ClientChannelConfiguration */ public static ClientChannelConfiguration clientConfig(EventLoopGroup workerGroup) { EventLoopGroup parent = workerGroup; if (parent instanceof EventLoop) { parent = ((EventLoop) workerGroup).parent(); } Class<? extends Channel> channelClass; if (parent instanceof EpollEventLoopGroup) { channelClass = EpollSocketChannel.class; } else if (parent instanceof NioEventLoopGroup) { channelClass = NioSocketChannel.class; } else { throw new RuntimeException("Unsupported EventLoopGroup " + workerGroup.getClass()); } return new ClientChannelConfiguration(workerGroup, channelClass); }
private void initEventLoopGroup() { // try Epoll first and if that does work, use nio. try { clientGroup = new EpollEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "epollC-%d", log)); serverGroup = new EpollEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "epollS-%d", log)); serverChannelClass = EpollServerSocketChannel.class; clientChannelClass = EpollSocketChannel.class; return; } catch (Throwable e) { log.debug("Failed to initialize native (epoll) transport. " + "Reason: {}. Proceeding with nio.", e.getMessage()); } clientGroup = new NioEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "nioC-%d", log)); serverGroup = new NioEventLoopGroup(0, groupedThreads("NettyMessagingEvt", "nioS-%d", log)); serverChannelClass = NioServerSocketChannel.class; clientChannelClass = NioSocketChannel.class; }
/** Returns the correct (client) SocketChannel class based on IOMode. */ public static Class<? extends Channel> getClientChannelClass(IOMode mode) { switch (mode) { case NIO: return NioSocketChannel.class; case EPOLL: return EpollSocketChannel.class; default: throw new IllegalArgumentException("Unknown io mode: " + mode); } }
@SuppressWarnings("unchecked") @Override public void addConnection(ServiceType serviceType, String host, int port) { ManagedChannel channel = NettyChannelBuilder.forAddress(host, port) .negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption .keepAliveTime(1, TimeUnit.MINUTES) .keepAliveTimeout(5, TimeUnit.SECONDS) .directExecutor() .channelType(EpollSocketChannel.class) .eventLoopGroup(new EpollEventLoopGroup()) .build(); AbstractStub blocking; AbstractStub async; switch (serviceType) { case WORLD: { blocking = WorldServiceGrpc.newBlockingStub(channel); async = WorldServiceGrpc.newStub(channel); break; } case PLUGIN_MANAGER: { blocking = PluginManagerGrpc.newBlockingStub(channel); async = PluginManagerGrpc.newStub(channel); break; } default: { throw new RuntimeException("Service type not handled: " + serviceType.name()); } } ServiceConnection connection = ServiceConnection.builder() .channel(channel) .blockingStub(blocking) .asyncStub(async) .build(); this.connections.put(serviceType, connection); }
public static NetworkManager func_181124_a(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_) { final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); Class <? extends SocketChannel > oclass; LazyLoadBase <? extends EventLoopGroup > lazyloadbase; if (Epoll.isAvailable() && p_181124_2_) { oclass = EpollSocketChannel.class; lazyloadbase = field_181125_e; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); } })).channel(oclass)).connect(p_181124_0_, p_181124_1_).syncUninterruptibly(); return networkmanager; }
@Before public void setUp() throws Exception { serverMock = new EpollConnDroppingServer(DEFAULT_PORT, FAIL_EVERY_CONN_ATTEMPT); final Semaphore concurrencyThrottle = new Semaphore(CONCURRENCY); group = new EpollEventLoopGroup(); final Bootstrap bootstrap = new Bootstrap() .group(group) .channel(EpollSocketChannel.class) .handler( new ChannelInitializer<SocketChannel>() { @Override protected final void initChannel(final SocketChannel conn) throws Exception { conn.pipeline().addLast(new DummyClientChannelHandler()); } } ) .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.TCP_NODELAY, true); connPool = new BasicMultiNodeConnPool( concurrencyThrottle, NODES, bootstrap, CPH, DEFAULT_PORT, 0 ); connPool.preCreateConnections(CONCURRENCY); }
public static Class<? extends SocketChannel> getClientSocketChannel(){ if(SUPPORTS_EPOLL){ return EpollSocketChannel.class; }else{ return NioSocketChannel.class; } }
public static OAuthNetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport, OAuthCallback callback) { final OAuthNetworkManager networkmanager = new OAuthNetworkManager(EnumPacketDirection.CLIENTBOUND, callback); Class<? extends SocketChannel> oclass; LazyLoadBase<? extends EventLoopGroup> lazyloadbase; if (Epoll.isAvailable() && useNativeTransport) { oclass = EpollSocketChannel.class; lazyloadbase = CLIENT_EPOLL_EVENTLOOP; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } (new Bootstrap()).group(lazyloadbase.getValue()).handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast("timeout", new ReadTimeoutHandler(30)) .addLast("splitter", new NettyVarint21FrameDecoder()) .addLast("decoder", new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND)) .addLast("prepender", new NettyVarint21FrameEncoder()) .addLast("encoder", new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND)) .addLast("packet_handler", networkmanager); } }).channel(oclass).connect(address, serverPort).syncUninterruptibly(); return networkmanager; }
/** * Create a new NetworkManager from the server host and connect it to the server */ public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport) { final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); Class <? extends SocketChannel > oclass; LazyLoadBase <? extends EventLoopGroup > lazyloadbase; if (Epoll.isAvailable() && useNativeTransport) { oclass = EpollSocketChannel.class; lazyloadbase = CLIENT_EPOLL_EVENTLOOP; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); } })).channel(oclass)).connect(address, serverPort).syncUninterruptibly(); return networkmanager; }
/** * Create a new NetworkManager from the server host and connect it to the server */ @SideOnly(Side.CLIENT) public static NetworkManager createNetworkManagerAndConnect(InetAddress address, int serverPort, boolean useNativeTransport) { final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND); Class <? extends SocketChannel > oclass; LazyLoadBase <? extends EventLoopGroup > lazyloadbase; if (Epoll.isAvailable() && useNativeTransport) { oclass = EpollSocketChannel.class; lazyloadbase = CLIENT_EPOLL_EVENTLOOP; } else { oclass = NioSocketChannel.class; lazyloadbase = CLIENT_NIO_EVENTLOOP; } ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel p_initChannel_1_) throws Exception { try { p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); } catch (ChannelException var3) { ; } p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new NettyVarint21FrameDecoder())).addLast((String)"decoder", (ChannelHandler)(new NettyPacketDecoder(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new NettyVarint21FrameEncoder())).addLast((String)"encoder", (ChannelHandler)(new NettyPacketEncoder(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager); } })).channel(oclass)).connect(address, serverPort).syncUninterruptibly(); return networkmanager; }
private void createEpollClient(Listener listener) { EpollEventLoopGroup workerGroup = new EpollEventLoopGroup( getWorkThreadNum(), new DefaultThreadFactory(ThreadNames.T_TCP_CLIENT) ); workerGroup.setIoRatio(getIoRate()); createClient(listener, workerGroup, EpollSocketChannel::new); }
public void initialize(String host, int port) { this.host = host; this.port = port; // bootstrap = new Bootstrap(); if (Epoll.isAvailable()) { this.childGroup = new EpollEventLoopGroup(cThreadCount); this.bootstrap.group(childGroup).channel(EpollSocketChannel.class); } else { this.childGroup = new NioEventLoopGroup(cThreadCount); this.bootstrap.group(childGroup).channel(NioSocketChannel.class); } // handlers this.prepender = new LengthFieldPrepender(this.lengthFieldLength, false); bootstrap.handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { ClientContext.this.initChannel(ch); } }); // this.defaultOptions(); if (!options.isEmpty()) { for (Map.Entry<ChannelOption<Object>, Object> entry : options.entrySet()) { bootstrap.option(entry.getKey(), entry.getValue()); } } }
/** * Return a SocketChannel class suitable for the given EventLoopGroup implementation * * @param eventLoopGroup * @return */ public static Class<? extends SocketChannel> getClientSocketChannelClass(EventLoopGroup eventLoopGroup) { if (eventLoopGroup instanceof EpollEventLoopGroup) { return EpollSocketChannel.class; } else { return NioSocketChannel.class; } }
@Override public void configure(NetworkChannelHandler handler) { this.handler = handler; final boolean useEpoll = Epoll.isAvailable() && this.configuration.getBoolean("epoll"); this.eventLoopGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("threads")) : new NioEventLoopGroup(this.configuration.getInt("threads")); bootstrap.group(this.eventLoopGroup); bootstrap.channel(useEpoll ? EpollSocketChannel.class : NioSocketChannel.class); bootstrap.option(ChannelOption.SO_KEEPALIVE, true); bootstrap.option(ChannelOption.TCP_NODELAY, true); }
@Override public ManagedChannel forDescriptor(ApiServiceDescriptor apiServiceDescriptor) { SocketAddress address = SocketAddressFactory.createFrom(apiServiceDescriptor.getUrl()); return NettyChannelBuilder.forAddress(address) .channelType(address instanceof DomainSocketAddress ? EpollDomainSocketChannel.class : EpollSocketChannel.class) .eventLoopGroup(new EpollEventLoopGroup()) .usePlaintext(true) // Set the message size to max value here. The actual size is governed by the // buffer size in the layers above. .maxInboundMessageSize(Integer.MAX_VALUE) .build(); }
protected void startServerBootstrap() throws Exception { // prefer using explicit configured thread pools EventLoopGroup wg = configuration.getWorkerGroup(); if (wg == null) { // create new pool which we should shutdown when stopping as its not shared workerGroup = new NettyWorkerPoolBuilder() .withNativeTransport(configuration.isNativeTransport()) .withWorkerCount(configuration.getWorkerCount()) .withName("NettyServerTCPWorker") .build(); wg = workerGroup; } clientBootstrap = new Bootstrap(); if (configuration.isNativeTransport()) { clientBootstrap.channel(EpollSocketChannel.class); } else { clientBootstrap.channel(NioSocketChannel.class); } clientBootstrap.group(wg); clientBootstrap.option(ChannelOption.SO_KEEPALIVE, configuration.isKeepAlive()); clientBootstrap.option(ChannelOption.TCP_NODELAY, configuration.isTcpNoDelay()); clientBootstrap.option(ChannelOption.SO_REUSEADDR, configuration.isReuseAddress()); clientBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, configuration.getConnectTimeout()); LOG.debug("Created ClientBootstrap {}", clientBootstrap); clientBootstrap.handler(pipelineFactory); ChannelFuture channelFuture = clientBootstrap.connect(new InetSocketAddress(configuration.getHost(), configuration.getPort())); if (LOG.isDebugEnabled()) { LOG.debug("Created new TCP client bootstrap connecting to {}:{} with options: {}", new Object[]{configuration.getHost(), configuration.getPort(), clientBootstrap}); } LOG.info("ClientModeServerBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort()); channel = openChannel(channelFuture); }
protected void init(Config cfg) { if (cfg.isUseLinuxNativeEpoll()) { this.group = new EpollEventLoopGroup(cfg.getThreads()); this.socketChannelClass = EpollSocketChannel.class; } else { this.group = new NioEventLoopGroup(cfg.getThreads()); this.socketChannelClass = NioSocketChannel.class; } this.codec = cfg.getCodec(); }
private @NotNull Bootstrap bootstrap(@NotNull TChannel topChannel) { return new Bootstrap() .group(this.childGroup) .channel(useEpoll ? EpollSocketChannel.class : NioSocketChannel.class) .handler(this.channelInitializer(false, topChannel)) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(WRITE_BUFFER_LOW_WATER_MARK, WRITE_BUFFER_HIGH_WATER_MARK)) .validate(); }
private static void setChannelFactory(final Bootstrap bootstrap, final KeyMapping keys) { if (Epoll.isAvailable()) { bootstrap.channel(EpollSocketChannel.class); bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else { bootstrap.channel(NioSocketChannel.class); } if (!keys.isEmpty()) { if (Epoll.isAvailable()) { bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys); } else { throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause()); } } }
private synchronized Bootstrap createClientBootStrap(final KeyMapping keys, final boolean reuseAddress) { final Bootstrap bootstrap = new Bootstrap(); if (Epoll.isAvailable()) { bootstrap.channel(EpollSocketChannel.class); bootstrap.option(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED); } else { bootstrap.channel(NioSocketChannel.class); } if (keys != null && !keys.isEmpty()) { if (Epoll.isAvailable()) { bootstrap.option(EpollChannelOption.TCP_MD5SIG, keys); } else { throw new UnsupportedOperationException(Epoll.unavailabilityCause().getCause()); } } // Make sure we are doing round-robin processing bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE)); bootstrap.option(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK); bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress); if (bootstrap.config().group() == null) { bootstrap.group(this.workerGroup); } return bootstrap; }
public static Class<? extends SocketChannel> socketChannel() { return EPOLL ? EpollSocketChannel.class : NioSocketChannel.class; }
public MasterSlaveConnectionManager(Config cfg) { Version.logVersion(); if (cfg.isUseLinuxNativeEpoll()) { if (cfg.getEventLoopGroup() == null) { this.group = new EpollEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty")); } else { this.group = cfg.getEventLoopGroup(); } this.socketChannelClass = EpollSocketChannel.class; } else { if (cfg.getEventLoopGroup() == null) { this.group = new NioEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty")); } else { this.group = cfg.getEventLoopGroup(); } this.socketChannelClass = NioSocketChannel.class; // if (cfg.getEventLoopGroup() == null) { // this.group = new OioEventLoopGroup(cfg.getThreads()); // } else { // this.group = cfg.getEventLoopGroup(); // } // // this.socketChannelClass = OioSocketChannel.class; } if (cfg.getExecutor() == null) { int threads = Runtime.getRuntime().availableProcessors() * 2; if (cfg.getThreads() != 0) { threads = cfg.getThreads(); } executor = Executors.newFixedThreadPool(threads, new DefaultThreadFactory("redisson")); } else { executor = cfg.getExecutor(); } this.cfg = cfg; this.codec = cfg.getCodec(); this.shutdownPromise = newPromise(); this.commandExecutor = new CommandSyncService(this); }
public static Class<? extends Channel> getChannel() { return EPOLL ? EpollSocketChannel.class : NioSocketChannel.class; }
public static Class<? extends Channel> clientChannelType() { if (Epoll.isAvailable()) { return EpollSocketChannel.class; } return NioSocketChannel.class; }