.group(eventLoopGroup) .channel(NioSocketChannel.class) .attr(REGISTRATION_FUTURE, registrationFuture) .handler(new ChannelInitializer<SocketChannel>() { @Override
bootstrap.option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000); bootstrap.attr(id, 123456); ChannelFuture future = bootstrap.connect( new InetSocketAddress("www.manning.com", 80));
.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(8 * 1024, 32 * 1024)) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutMillis) .attr(SECURE, httpRequest.isSecure() != null && httpRequest.isSecure()) .attr(REMOTE_SOCKET, remoteAddress) .attr(RESPONSE_FUTURE, httpResponseSettableFuture) .handler(new HttpClientInitializer(proxyConfiguration, mockServerLogger)) .connect(remoteAddress)
public ChannelFuture connect(final EventLoop eventLoop, String host, final int port, CurrentPassport passport) { Class socketChannelClass; if (Server.USE_EPOLL.get()) { socketChannelClass = EpollSocketChannel.class; } else { socketChannelClass = NioSocketChannel.class; } SocketAddress socketAddress = new InetSocketAddress(host, port); final Bootstrap bootstrap = new Bootstrap() .channel(socketChannelClass) .handler(channelInitializer) .group(eventLoop) .attr(CurrentPassport.CHANNEL_ATTR, passport) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connPoolConfig.getConnectTimeout()) .option(ChannelOption.SO_KEEPALIVE, connPoolConfig.getTcpKeepAlive()) .option(ChannelOption.TCP_NODELAY, connPoolConfig.getTcpNoDelay()) .option(ChannelOption.SO_SNDBUF, connPoolConfig.getTcpSendBufferSize()) .option(ChannelOption.SO_RCVBUF, connPoolConfig.getTcpReceiveBufferSize()) .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, connPoolConfig.getNettyWriteBufferHighWaterMark()) .option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, connPoolConfig.getNettyWriteBufferLowWaterMark()) .option(ChannelOption.AUTO_READ, connPoolConfig.getNettyAutoRead()) .remoteAddress(socketAddress); ZuulBootstrap zuulBootstrap = new ZuulBootstrap(bootstrap); if (!zuulBootstrap.getResolver(eventLoop).isResolved(socketAddress)) { LOGGER.warn("NettyClientConnectionFactory got an unresolved server address, host: " + host + ", port: " + port); unresolvedDiscoveryHost.increment(); } return bootstrap.connect(); }
bs.attr(POOL_KEY, this); ChannelFuture f = connectChannel(bs); if (f.isDone()) {
bs.attr(POOL_KEY, this); ChannelFuture f = connectChannel(bs); if (f.isDone()) {
public ChannelFuture connect(final EventLoop eventLoop, String host, final int port, CurrentPassport passport) { Class socketChannelClass; if (Server.USE_EPOLL.get()) { socketChannelClass = EpollSocketChannel.class; } else { socketChannelClass = NioSocketChannel.class; } SocketAddress socketAddress = new InetSocketAddress(host, port); final Bootstrap bootstrap = new Bootstrap() .channel(socketChannelClass) .handler(channelInitializer) .group(eventLoop) .attr(CurrentPassport.CHANNEL_ATTR, passport) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connPoolConfig.getConnectTimeout()) .option(ChannelOption.SO_KEEPALIVE, connPoolConfig.getTcpKeepAlive()) .option(ChannelOption.TCP_NODELAY, connPoolConfig.getTcpNoDelay()) .option(ChannelOption.SO_SNDBUF, connPoolConfig.getTcpSendBufferSize()) .option(ChannelOption.SO_RCVBUF, connPoolConfig.getTcpReceiveBufferSize()) .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, connPoolConfig.getNettyWriteBufferHighWaterMark()) .option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, connPoolConfig.getNettyWriteBufferLowWaterMark()) .option(ChannelOption.AUTO_READ, connPoolConfig.getNettyAutoRead()) .remoteAddress(socketAddress); ZuulBootstrap zuulBootstrap = new ZuulBootstrap(bootstrap); if (!zuulBootstrap.getResolver(eventLoop).isResolved(socketAddress)) { LOGGER.warn("NettyClientConnectionFactory got an unresolved server address, host: " + host + ", port: " + port); unresolvedDiscoveryHost.increment(); } return bootstrap.connect(); }
bs.attr(POOL_KEY, this); ChannelFuture f = connectChannel(bs); if (f.isDone()) {
/** * Inject default attribute to the future child {@link Channel} connections. They * will be available via {@link Channel#attr(AttributeKey)}. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link UdpClient} * * @see Bootstrap#attr(AttributeKey, Object) */ public final <T> UdpClient attr(AttributeKey<T> key, T value) { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); return bootstrap(b -> b.attr(key, value)); }
/** * Inject default attribute to the future child {@link Channel} connections. They * will be available via {@link Channel#attr(AttributeKey)}. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link UdpServer} * * @see Bootstrap#attr(AttributeKey, Object) */ public final <T> UdpServer attr(AttributeKey<T> key, T value) { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); return bootstrap(b -> b.attr(key, value)); }
/** * Inject default attribute to the future child {@link Channel} connections. They * will be available via {@link Channel#attr(AttributeKey)}. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link UdpServer} * * @see Bootstrap#attr(AttributeKey, Object) */ public final <T> UdpServer attr(AttributeKey<T> key, T value) { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); return bootstrap(b -> b.attr(key, value)); }
/** * Inject default attribute to the future {@link Channel} connection. They will be * available via {@link Channel#attr(AttributeKey)}. * If the {@code value} is {@code null}, the attribute of the specified {@code key} * is removed. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link TcpClient} * * @see Bootstrap#attr(AttributeKey, Object) */ public final <T> TcpClient attr(AttributeKey<T> key, @Nullable T value) { Objects.requireNonNull(key, "key"); return bootstrap(b -> b.attr(key, value)); }
/** * Inject default attribute to the future child {@link Channel} connections. They * will be available via {@link Channel#attr(AttributeKey)}. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link UdpClient} * * @see Bootstrap#attr(AttributeKey, Object) */ public final <T> UdpClient attr(AttributeKey<T> key, T value) { Objects.requireNonNull(key, "key"); Objects.requireNonNull(value, "value"); return bootstrap(b -> b.attr(key, value)); }
/** * Inject default attribute to the future {@link Channel} connection. They will be * available via {@link Channel#attr(AttributeKey)}. * If the {@code value} is {@code null}, the attribute of the specified {@code key} * is removed. * * @param key the attribute key * @param value the attribute value * @param <T> the attribute type * * @return a new {@link TcpClient} * * @see Bootstrap#attr(AttributeKey, Object) */ public final <T> TcpClient attr(AttributeKey<T> key, @Nullable T value) { Objects.requireNonNull(key, "key"); return bootstrap(b -> b.attr(key, value)); }
static HttpClientConfiguration getAndClean(Bootstrap b) { HttpClientConfiguration hcc = (HttpClientConfiguration) b.config() .attrs() .get(CONF_KEY); b.attr(CONF_KEY, null); if (hcc == null) { hcc = DEFAULT; } return hcc; }
static HttpClientConfiguration getAndClean(Bootstrap b) { HttpClientConfiguration hcc = (HttpClientConfiguration) b.config() .attrs() .get(CONF_KEY); b.attr(CONF_KEY, null); if (hcc == null) { hcc = DEFAULT; } return hcc; }
public NettyClient(Node node) { this.node = node; boot = new Bootstrap(); boot.attr(NodeAttributeKey.NODE_KEY, node); boot.group(worker) .channel(NioSocketChannel.class) // .option(ChannelOption.SO_BACKLOG, 1024) .option(ChannelOption.TCP_NODELAY, true) //Send messages immediately .option(ChannelOption.SO_KEEPALIVE, true) .option(ChannelOption.SO_SNDBUF, 128 * 1024) .option(ChannelOption.SO_RCVBUF, 128 * 1024) .option(ChannelOption.RCVBUF_ALLOCATOR, AdaptiveRecvByteBufAllocator.DEFAULT) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNETCI_TIME_OUT) .handler(new NulsChannelInitializer<>(new ClientChannelHandler())); }
@SuppressWarnings("unchecked") static HttpClientConfiguration getOrCreate(Bootstrap b) { HttpClientConfiguration hcc = (HttpClientConfiguration) b.config() .attrs() .get(CONF_KEY); if (hcc == null) { hcc = new HttpClientConfiguration(); b.attr(CONF_KEY, hcc); } return hcc; }
@SuppressWarnings("unchecked") static HttpClientConfiguration getOrCreate(Bootstrap b) { HttpClientConfiguration hcc = (HttpClientConfiguration) b.config() .attrs() .get(CONF_KEY); if (hcc == null) { hcc = new HttpClientConfiguration(); b.attr(CONF_KEY, hcc); } return hcc; }
public ChannelFuture connect(final EventLoop eventLoop, String host, final int port, CurrentPassport passport) { Class socketChannelClass; if (Server.USE_EPOLL.get()) { socketChannelClass = EpollSocketChannel.class; } else { socketChannelClass = NioSocketChannel.class; } SocketAddress socketAddress = new InetSocketAddress(host, port); final Bootstrap bootstrap = new Bootstrap() .channel(socketChannelClass) .handler(channelInitializer) .group(eventLoop) .attr(CurrentPassport.CHANNEL_ATTR, passport) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connPoolConfig.getConnectTimeout()) .option(ChannelOption.SO_KEEPALIVE, connPoolConfig.getTcpKeepAlive()) .option(ChannelOption.TCP_NODELAY, connPoolConfig.getTcpNoDelay()) .option(ChannelOption.SO_SNDBUF, connPoolConfig.getTcpSendBufferSize()) .option(ChannelOption.SO_RCVBUF, connPoolConfig.getTcpReceiveBufferSize()) .option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, connPoolConfig.getNettyWriteBufferHighWaterMark()) .option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, connPoolConfig.getNettyWriteBufferLowWaterMark()) .option(ChannelOption.AUTO_READ, connPoolConfig.getNettyAutoRead()) .remoteAddress(socketAddress); ZuulBootstrap zuulBootstrap = new ZuulBootstrap(bootstrap); if (!zuulBootstrap.getResolver(eventLoop).isResolved(socketAddress)) { LOGGER.warn("NettyClientConnectionFactory got an unresolved server address, host: " + host + ", port: " + port); unresolvedDiscoveryHost.increment(); } return bootstrap.connect(); }