本文整理了Java中io.netty.bootstrap.Bootstrap.remoteAddress()
方法的一些代码示例,展示了Bootstrap.remoteAddress()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bootstrap.remoteAddress()
方法的具体详情如下:
包路径:io.netty.bootstrap.Bootstrap
类名称:Bootstrap
方法名:remoteAddress
暂无
代码示例来源:origin: netty/netty
/**
* Returns the configured remote address or {@code null} if non is configured yet.
*/
public SocketAddress remoteAddress() {
return bootstrap.remoteAddress();
}
代码示例来源:origin: redisson/redisson
/**
* Returns the configured remote address or {@code null} if non is configured yet.
*/
public SocketAddress remoteAddress() {
return bootstrap.remoteAddress();
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns the configured remote address or {@code null} if non is configured yet.
*/
public SocketAddress remoteAddress() {
return bootstrap.remoteAddress();
}
代码示例来源:origin: dreamhead/moco
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();
}
}
}
代码示例来源:origin: apache/incubator-pinot
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));
}
});
}
代码示例来源:origin: ethereum/ethereumj
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();
}
代码示例来源:origin: normanmaurer/netty-in-action
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();
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
protected ChannelPool newPool(RequestKey key) {
Bootstrap newBootstrap = bootstrap.clone(group);
newBootstrap.remoteAddress(key.getRemoteAddress());
AbstractChannelPoolHandler channelPoolHandler = newPoolHandler(key);
return new SimpleChannelPool(
newBootstrap,
channelPoolHandler
);
}
};
代码示例来源:origin: Netflix/zuul
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();
}
代码示例来源:origin: atomix/atomix
bootstrap.remoteAddress(address.address(true), address.port());
if (enableNettyTls) {
try {
代码示例来源:origin: micronaut-projects/micronaut-core
@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()
);
}
};
代码示例来源:origin: relayrides/pushy
this.bootstrapTemplate.group(eventLoopGroup);
this.bootstrapTemplate.option(ChannelOption.TCP_NODELAY, true);
this.bootstrapTemplate.remoteAddress(apnsServerAddress);
this.bootstrapTemplate.resolver(this.addressResolverGroup);
代码示例来源:origin: aws/aws-sdk-java
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);
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
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,
代码示例来源:origin: alibaba/fescar
@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;
}
};
代码示例来源:origin: alipay/sofa-rpc
@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);
}
}
代码示例来源:origin: alipay/sofa-rpc
@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);
}
}
代码示例来源:origin: apache/incubator-shardingsphere
@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);
}
};
代码示例来源:origin: apache/incubator-shardingsphere
@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);
}
};
代码示例来源:origin: Netflix/zuul
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();
}
内容来源于网络,如有侵权,请联系作者删除!