/** * Returns the configured remote address or {@code null} if non is configured yet. */ public SocketAddress remoteAddress() { return bootstrap.remoteAddress(); }
/** * Returns the configured remote address or {@code null} if non is configured yet. */ public SocketAddress remoteAddress() { return bootstrap.remoteAddress(); }
/** * Returns the configured remote address or {@code null} if non is configured yet. */ public SocketAddress remoteAddress() { return bootstrap.remoteAddress(); }
public final void run(final String host, final int port, final ChannelHandler pipelineFactory) { EventLoopGroup group = new NioEventLoopGroup(); Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) .remoteAddress(host, port) .option(ChannelOption.TCP_NODELAY, true) .handler(pipelineFactory); try { Channel channel = bootstrap.connect().sync().channel(); ChannelFuture future = channel.closeFuture().sync(); future.addListener(ChannelFutureListener.CLOSE); } catch (InterruptedException e) { throw new MocoException(e); } finally { group.shutdownGracefully(); } } }
ServerChannel(Server server) { _server = server; _bootstrap = new Bootstrap().remoteAddress(server.getHostName(), server.getPort()).group(_eventLoopGroup) .channel(NioSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) { ch.pipeline() .addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, Integer.BYTES, 0, Integer.BYTES), new LengthFieldPrepender(Integer.BYTES), // NOTE: data table de-serialization happens inside this handler // Revisit if this becomes a bottleneck new DataTableHandler(_queryRouter, _server, _brokerMetrics)); } }); }
public ChannelFuture connectAsync(String host, int port, String remoteId, boolean discoveryMode) { ethereumListener.trace("Connecting to: " + host + ":" + port); EthereumChannelInitializer ethereumChannelInitializer = ctx.getBean(EthereumChannelInitializer.class, remoteId); ethereumChannelInitializer.setPeerDiscoveryMode(discoveryMode); Bootstrap b = new Bootstrap(); b.group(workerGroup); b.channel(NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT); b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerConnectionTimeout()); b.remoteAddress(host, port); b.handler(ethereumChannelInitializer); // Start the client. return b.connect(); }
public void start() throws Exception { EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap b = new Bootstrap(); b.group(group) .channel(NioSocketChannel.class) .remoteAddress(new InetSocketAddress(host, port)) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast( new EchoClientHandler()); } }); ChannelFuture f = b.connect().sync(); f.channel().closeFuture().sync(); } finally { group.shutdownGracefully().sync(); } }
@Override protected ChannelPool newPool(RequestKey key) { Bootstrap newBootstrap = bootstrap.clone(group); newBootstrap.remoteAddress(key.getRemoteAddress()); AbstractChannelPoolHandler channelPoolHandler = newPoolHandler(key); return new SimpleChannelPool( newBootstrap, channelPoolHandler ); } };
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(); }
bootstrap.remoteAddress(address.address(true), address.port()); if (enableNettyTls) { try {
@Override protected ChannelPool newPool(RequestKey key) { Bootstrap newBootstrap = bootstrap.clone(group); newBootstrap.remoteAddress(key.getRemoteAddress()); AbstractChannelPoolHandler channelPoolHandler = newPoolHandler(key); return new FixedChannelPool( newBootstrap, channelPoolHandler, ChannelHealthChecker.ACTIVE, FixedChannelPool.AcquireTimeoutAction.FAIL, connectionPoolConfiguration.getAcquireTimeout().map(Duration::toMillis).orElse(-1L), maxConnections, connectionPoolConfiguration.getMaxPendingAcquires() ); } };
this.bootstrapTemplate.group(eventLoopGroup); this.bootstrapTemplate.option(ChannelOption.TCP_NODELAY, true); this.bootstrapTemplate.remoteAddress(apnsServerAddress); this.bootstrapTemplate.resolver(this.addressResolverGroup);
private void doPutMedia(PutMediaRequest request, PutMediaResponseHandler responseHandler, List<ChannelHandler> requestHandlers) { request.getRequestClientOptions().appendUserAgent(USER_AGENT); Request<PutMediaRequest> marshalled = marshall(request); applyUserAgent(request, marshalled); signer.sign(marshalled, resolveCredentials(request)); try { Bootstrap b = new Bootstrap() .group(group) .channel(NioSocketChannel.class) .remoteAddress(marshalled.getEndpoint().getHost(), getPort(marshalled.getEndpoint())) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutInMillis) .handler(new PutMediaHandlerInitializer(getSslContext(marshalled.getEndpoint()), createHandlers(responseHandler, marshalled, requestHandlers))); invoke(marshalled, b, responseHandler); } catch (InterruptedException e) { throw handleInterruptedException(e); } }
int maxFramePayloadLength = finalWebSocketBean.messageMethod().flatMap(m -> m.getValue(OnMessage.class, "maxPayloadLength", Integer.class)).orElse(65536); bootstrap.remoteAddress(uri.getHost(), uri.getPort()); bootstrap.handler(new HttpClientInitializer( sslContext,
@Override protected FixedChannelPool newPool(InetSocketAddress key) { FixedChannelPool fixedClientChannelPool = new FixedChannelPool( bootstrap.remoteAddress(key), new DefaultChannelPoolHandler() { @Override public void channelCreated(Channel ch) throws Exception { super.channelCreated(ch); final ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(defaultEventExecutorGroup, new IdleStateHandler(nettyClientConfig.getChannelMaxReadIdleSeconds(), nettyClientConfig.getChannelMaxWriteIdleSeconds(), nettyClientConfig.getChannelMaxAllIdleSeconds())); pipeline.addLast(defaultEventExecutorGroup, new RpcClientHandler()); } }, ChannelHealthChecker.ACTIVE, AcquireTimeoutAction.FAIL, nettyClientConfig.getMaxAcquireConnMills(), nettyClientConfig.getPerHostMaxConn(), nettyClientConfig.getPendingConnSize(), false ); return fixedClientChannelPool; } };
@Override public void connect() { if (isAvailable()) { return; } EventLoopGroup workerGroup = NettyHelper.getClientIOEventLoopGroup(); Http2ClientInitializer initializer = new Http2ClientInitializer(transportConfig); try { String host = providerInfo.getHost(); int port = providerInfo.getPort(); Bootstrap b = new Bootstrap(); b.group(workerGroup); b.channel(transportConfig.isUseEpoll() ? EpollSocketChannel.class : NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.remoteAddress(host, port); b.handler(initializer); // Start the client. Channel channel = b.connect().syncUninterruptibly().channel(); this.channel = new NettyChannel(channel); // Wait for the HTTP/2 upgrade to occur. Http2SettingsHandler http2SettingsHandler = initializer.settingsHandler(); http2SettingsHandler.awaitSettings(transportConfig.getConnectTimeout(), TimeUnit.MILLISECONDS); responseChannelHandler = initializer.responseHandler(); // RESET streamId streamId.set(START_STREAM_ID); } catch (Exception e) { throw new SofaRpcException(RpcErrorType.CLIENT_NETWORK, e); } }
@Override public void connect() { if (isAvailable()) { return; } EventLoopGroup workerGroup = NettyHelper.getClientIOEventLoopGroup(); Http2ClientInitializer initializer = new Http2ClientInitializer(transportConfig); try { String host = providerInfo.getHost(); int port = providerInfo.getPort(); Bootstrap b = new Bootstrap(); b.group(workerGroup); b.channel(transportConfig.isUseEpoll() ? EpollSocketChannel.class : NioSocketChannel.class); b.option(ChannelOption.SO_KEEPALIVE, true); b.remoteAddress(host, port); b.handler(initializer); // Start the client. Channel channel = b.connect().syncUninterruptibly().channel(); this.channel = new NettyChannel(channel); // Wait for the HTTP/2 upgrade to occur. Http2SettingsHandler http2SettingsHandler = initializer.settingsHandler(); http2SettingsHandler.awaitSettings(transportConfig.getConnectTimeout(), TimeUnit.MILLISECONDS); responseChannelHandler = initializer.responseHandler(); // RESET streamId streamId.set(START_STREAM_ID); } catch (Exception e) { throw new SofaRpcException(RpcErrorType.CLIENT_NETWORK, e); } }
@Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = logicSchema.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); return new FixedChannelPool( bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName, logicSchema.getName()), maxConnections); } };
@Override protected SimpleChannelPool newPool(final String dataSourceName) { DataSourceMetaData dataSourceMetaData = logicSchema.getMetaData().getDataSource().getActualDataSourceMetaData(dataSourceName); return new FixedChannelPool( bootstrap.remoteAddress(dataSourceMetaData.getHostName(), dataSourceMetaData.getPort()), new BackendNettyClientChannelPoolHandler(dataSourceName, logicSchema.getName()), maxConnections); } };
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(); }