private Bootstrap buildBootstrap(URI uri, boolean isSecure) { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) throws Exception { configureChannel(channel.config()); ChannelPipeline pipeline = channel.pipeline(); if (isSecure) { Assert.notNull(sslContext, "sslContext should not be null"); pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort())); } pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); if (readTimeout > 0) { pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS)); } } }); return bootstrap; }
private void groupsEpoll(final Bootstrap bootstrap) { bootstrap.group(workerGroup) .channel(EpollSocketChannel.class) .option(EpollChannelOption.TCP_CORK, true) .option(EpollChannelOption.SO_KEEPALIVE, true) .option(EpollChannelOption.SO_BACKLOG, 128) .option(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); }
public EventLoopGroup kqueueGroup() { EventLoopGroup nioEventLoopGroup = new KQueueEventLoopGroup(0, createThreadFactory()); bootstrap.group(nioEventLoopGroup).channel(KQueueDomainSocketChannel.class) .handler(new ChannelInitializer<KQueueDomainSocketChannel>() { @Override protected void initChannel(final KQueueDomainSocketChannel channel) throws Exception { channel.pipeline().addLast(new HttpClientCodec()); channel.pipeline().addLast(new HttpContentDecompressor()); } }); return nioEventLoopGroup; }
private void createClient(Listener listener, EventLoopGroup workerGroup, ChannelFactory<? extends Channel> channelFactory) { this.workerGroup = workerGroup; this.bootstrap = new Bootstrap(); bootstrap.group(workerGroup)// .option(ChannelOption.SO_REUSEADDR, true)// .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)// .channelFactory(channelFactory); bootstrap.handler(new ChannelInitializer<Channel>() { // (4) @Override public void initChannel(Channel ch) throws Exception { initPipeline(ch.pipeline()); } }); initOptions(bootstrap); listener.onSuccess(); }
AtomicReference<Thread> channelThread = new AtomicReference<>(); CountDownLatch connectLatch = new CountDownLatch(1); Bootstrap bootstrap = new Bootstrap(); bootstrap.channelFactory(((VertxInternal)vertx).transport().channelFactory(false)); bootstrap.group(vertx.nettyEventLoopGroup()); bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup()); bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelFuture channelFut = bootstrap.connect("localhost", 1234); awaitLatch(connectLatch); channelFut.addListener(v -> {
@Override public EventLoopGroup init(Bootstrap bootstrap, final DockerClientConfig dockerClientConfig) { EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(0, createThreadFactory()); // TODO do we really need BouncyCastle? Security.addProvider(new BouncyCastleProvider()); ChannelFactory<NioSocketChannel> factory = () -> 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 HttpClientCodec()); channel.pipeline().addLast(new HttpContentDecompressor()); } }); return nioEventLoopGroup; }
protected void channelType(ConnectionBuilder connectionBuilder, ConnectionPoint connectionPoint) { LettuceAssert.notNull(connectionPoint, "ConnectionPoint must not be null"); connectionBuilder.bootstrap().group(getEventLoopGroup(connectionPoint)); if (connectionPoint.getSocket() != null) { NativeTransports.assertAvailable(); connectionBuilder.bootstrap().channel(NativeTransports.domainSocketChannelClass()); } else { connectionBuilder.bootstrap().channel(Transports.socketChannelClass()); } }
private Bootstrap buildBootstrap(URI uri, boolean isSecure) { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel channel) throws Exception { configureChannel(channel.config()); ChannelPipeline pipeline = channel.pipeline(); if (isSecure) { Assert.notNull(sslContext, "sslContext should not be null"); pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort())); } pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); if (readTimeout > 0) { pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS)); } } }); return bootstrap; }
private CompletableFuture<Void> bootstrapServer() { Bootstrap serverBootstrap = new Bootstrap() .group(group) .channelFactory(() -> new NioDatagramChannel(InternetProtocolFamily.IPv4)) .handler(new SimpleChannelInboundHandler<Object>() { @Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { // Nothing will be sent. } }) .option(ChannelOption.IP_MULTICAST_IF, iface) .option(ChannelOption.SO_REUSEADDR, true); CompletableFuture<Void> future = new CompletableFuture<>(); serverBootstrap.bind(localAddress).addListener((ChannelFutureListener) f -> { if (f.isSuccess()) { serverChannel = f.channel(); future.complete(null); } else { future.completeExceptionally(f.cause()); } }); return future; }
/** * Establishing TCP connection to server * * @param remoteAddress remote address * */ public ChannelFuture connectToServer(final InetSocketAddress remoteAddress) { if (remoteAddress == null) { throw new IllegalStateException("remote address is null"); } Bootstrap bootstrap = new Bootstrap().group(_upstreamWorkerGroup); bootstrap.channelFactory(NioSocketChannel::new); ServerChannelHandler serverChannelHandler = new ServerChannelHandler(this); bootstrap.handler(new ChannelInitializer<Channel>() { protected void initChannel(Channel ch) throws Exception { initChannelPipeline(ch.pipeline(), serverChannelHandler, _serverConnectionIdleTimeoutMsec); _serverChannel = ch; } }); LOG.debug("Server channel is ready. About to connect...."); return bootstrap.connect(remoteAddress); }
private void groupsNio(final Bootstrap bootstrap) { bootstrap.group(workerGroup) .channel(NioSocketChannel.class) .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 100) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); }
public EventLoopGroup kqueueGroup() { EventLoopGroup nioEventLoopGroup = new KQueueEventLoopGroup(0, new DefaultThreadFactory(threadPrefix)); bootstrap.group(nioEventLoopGroup).channel(KQueueDomainSocketChannel.class) .handler(new ChannelInitializer<KQueueDomainSocketChannel>() { @Override protected void initChannel(final KQueueDomainSocketChannel channel) throws Exception { channel.pipeline().addLast(new LoggingHandler(getClass())); channel.pipeline().addLast(new HttpClientCodec()); channel.pipeline().addLast(new HttpContentDecompressor()); } }); return nioEventLoopGroup; }
public EventLoopGroup epollGroup() { EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, createThreadFactory()); ChannelFactory<EpollDomainSocketChannel> factory = () -> 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()); channel.pipeline().addLast(new HttpContentDecompressor()); } }); return epollEventLoopGroup; }
@VisibleForTesting Bootstrap getBootstrap(MessageInput input) { LOG.debug("Setting UDP receive buffer size to {} bytes", getRecvBufferSize()); final NettyTransportType transportType = nettyTransportConfiguration.getType(); eventLoopGroup = eventLoopGroupFactory.create(workerThreads, localRegistry, "workers"); return new Bootstrap() .group(eventLoopGroup) .channelFactory(new DatagramChannelFactory(transportType)) .option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(getRecvBufferSize())) .option(ChannelOption.SO_RCVBUF, getRecvBufferSize()) .option(UnixChannelOption.SO_REUSEPORT, true) .handler(getChannelInitializer(getChannelHandlers(input))) .validate(); }
AtomicReference<Thread> channelThread = new AtomicReference<>(); CountDownLatch connectLatch = new CountDownLatch(1); Bootstrap bootstrap = new Bootstrap(); bootstrap.channelFactory(((VertxInternal)vertx).transport().channelFactory(false)); bootstrap.group(vertx.nettyEventLoopGroup()); bootstrap.resolver(((VertxInternal) vertx).nettyAddressResolverGroup()); bootstrap.handler(new ChannelInitializer<Channel>() { @Override protected void initChannel(Channel ch) throws Exception { ChannelFuture channelFut = bootstrap.connect("localhost", 1234); awaitLatch(connectLatch); channelFut.addListener(v -> {
private void groupsEpoll(final Bootstrap bootstrap) { bootstrap.group(workerGroup) .channel(EpollSocketChannel.class) .option(EpollChannelOption.TCP_CORK, true) .option(EpollChannelOption.SO_KEEPALIVE, true) .option(EpollChannelOption.SO_BACKLOG, 128) .option(EpollChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); }