public EventLoopGroup epollGroup() { EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix)); ChannelFactory<EpollDomainSocketChannel> factory = new ChannelFactory<EpollDomainSocketChannel>() { @Override public EpollDomainSocketChannel newChannel() { return configure(new EpollDomainSocketChannel()); } }; bootstrap.group(epollEventLoopGroup).channelFactory(factory).handler(new ChannelInitializer<UnixChannel>() { @Override protected void initChannel(final UnixChannel channel) throws Exception { channel.pipeline().addLast(new HttpClientCodec()); } }); return epollEventLoopGroup; }
private void createServer(Listener listener, EventLoopGroup eventLoopGroup, ChannelFactory<? extends DatagramChannel> channelFactory) { this.eventLoopGroup = eventLoopGroup; try { Bootstrap b = new Bootstrap(); b.group(eventLoopGroup)//默认是根据机器情况创建Channel,如果机器支持ipv6,则无法使用ipv4的地址加入组播 .channelFactory(channelFactory) .option(ChannelOption.SO_BROADCAST, true) .handler(getChannelHandler()); initOptions(b); //直接绑定端口,不要指定host,不然收不到组播消息 b.bind(port).addListener(future -> { if (future.isSuccess()) { logger.info("udp server start success on:{}", port); if (listener != null) listener.onSuccess(port); } else { logger.error("udp server start failure on:{}", port, future.cause()); if (listener != null) listener.onFailure(future.cause()); } }); } catch (Exception e) { logger.error("udp server start exception", e); if (listener != null) listener.onFailure(e); throw new ServiceException("udp server start exception, port=" + port, e); } }
@Override public EventLoopGroup init(Bootstrap bootstrap, final DockerClientConfig dockerClientConfig) { EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(0, new DefaultThreadFactory(threadPrefix)); InetAddress addr = InetAddress.getLoopbackAddress(); final SocketAddress proxyAddress = new InetSocketAddress(addr, 8008); Security.addProvider(new BouncyCastleProvider()); ChannelFactory<NioSocketChannel> factory = new ChannelFactory<NioSocketChannel>() { @Override public NioSocketChannel newChannel() { return configure(new NioSocketChannel()); } }; bootstrap.group(nioEventLoopGroup).channelFactory(factory) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel channel) throws Exception { // channel.pipeline().addLast(new // HttpProxyHandler(proxyAddress)); channel.pipeline().addLast(new HttpClientCodec()); } }); return nioEventLoopGroup; }