本文整理了Java中io.netty.bootstrap.Bootstrap.clone()
方法的一些代码示例,展示了Bootstrap.clone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bootstrap.clone()
方法的具体详情如下:
包路径:io.netty.bootstrap.Bootstrap
类名称:Bootstrap
方法名:clone
[英]Returns a deep clone of this bootstrap which has the identical configuration except that it uses the given EventLoopGroup. This method is useful when making multiple Channels with similar settings.
[中]返回此引导程序的深层克隆,该克隆具有相同的配置,但它使用给定的EventLoopGroup。使用类似设置制作多个通道时,此方法非常有用。
代码示例来源:origin: line/armeria
/**
* Returns a new {@link Bootstrap} whose {@link ChannelFactory}, {@link AddressResolverGroup} and
* socket options are pre-configured.
*/
Bootstrap newBootstrap() {
return baseBootstrap.clone();
}
代码示例来源:origin: netty/netty
/**
* Creates a new instance.
*
* @param bootstrap the {@link Bootstrap} that is used for connections
* @param handler the {@link ChannelPoolHandler} that will be notified for the different pool actions
* @param healthCheck the {@link ChannelHealthChecker} that will be used to check if a {@link Channel} is
* still healthy when obtain from the {@link ChannelPool}
* @param releaseHealthCheck will check channel health before offering back if this parameter set to {@code true};
* otherwise, channel health is only checked at acquisition time
* @param lastRecentUsed {@code true} {@link Channel} selection will be LIFO, if {@code false} FIFO.
*/
public SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
boolean releaseHealthCheck, boolean lastRecentUsed) {
this.handler = checkNotNull(handler, "handler");
this.healthCheck = checkNotNull(healthCheck, "healthCheck");
this.releaseHealthCheck = releaseHealthCheck;
// Clone the original Bootstrap as we want to set our own handler
this.bootstrap = checkNotNull(bootstrap, "bootstrap").clone();
this.bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
assert ch.eventLoop().inEventLoop();
handler.channelCreated(ch);
}
});
this.lastRecentUsed = lastRecentUsed;
}
代码示例来源:origin: redisson/redisson
/**
* Creates a new instance.
*
* @param bootstrap the {@link Bootstrap} that is used for connections
* @param handler the {@link ChannelPoolHandler} that will be notified for the different pool actions
* @param healthCheck the {@link ChannelHealthChecker} that will be used to check if a {@link Channel} is
* still healthy when obtain from the {@link ChannelPool}
* @param releaseHealthCheck will check channel health before offering back if this parameter set to {@code true};
* otherwise, channel health is only checked at acquisition time
* @param lastRecentUsed {@code true} {@link Channel} selection will be LIFO, if {@code false} FIFO.
*/
public SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
boolean releaseHealthCheck, boolean lastRecentUsed) {
this.handler = checkNotNull(handler, "handler");
this.healthCheck = checkNotNull(healthCheck, "healthCheck");
this.releaseHealthCheck = releaseHealthCheck;
// Clone the original Bootstrap as we want to set our own handler
this.bootstrap = checkNotNull(bootstrap, "bootstrap").clone();
this.bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
assert ch.eventLoop().inEventLoop();
handler.channelCreated(ch);
}
});
this.lastRecentUsed = lastRecentUsed;
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Creates an initial connection to the given remote host.
*
* @param request The request
* @param host The host
* @param port The port
* @param sslCtx The SslContext instance
* @param isStream Is the connection a stream connection
* @return A ChannelFuture
*/
protected ChannelFuture doConnect(
io.micronaut.http.HttpRequest<?> request,
String host,
int port,
@Nullable SslContext sslCtx,
boolean isStream) {
Bootstrap localBootstrap = this.bootstrap.clone();
localBootstrap.handler(new HttpClientInitializer(
sslCtx,
host,
port,
isStream,
request.getHeaders().get(io.micronaut.http.HttpHeaders.ACCEPT, String.class).map(ct -> ct.equals(MediaType.TEXT_EVENT_STREAM)).orElse(false))
);
return doConnect(localBootstrap, host, port);
}
代码示例来源: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: wildfly/wildfly
/**
* Creates a new instance.
*
* @param bootstrap the {@link Bootstrap} that is used for connections
* @param handler the {@link ChannelPoolHandler} that will be notified for the different pool actions
* @param healthCheck the {@link ChannelHealthChecker} that will be used to check if a {@link Channel} is
* still healthy when obtain from the {@link ChannelPool}
* @param releaseHealthCheck will check channel health before offering back if this parameter set to {@code true};
* otherwise, channel health is only checked at acquisition time
* @param lastRecentUsed {@code true} {@link Channel} selection will be LIFO, if {@code false} FIFO.
*/
public SimpleChannelPool(Bootstrap bootstrap, final ChannelPoolHandler handler, ChannelHealthChecker healthCheck,
boolean releaseHealthCheck, boolean lastRecentUsed) {
this.handler = checkNotNull(handler, "handler");
this.healthCheck = checkNotNull(healthCheck, "healthCheck");
this.releaseHealthCheck = releaseHealthCheck;
// Clone the original Bootstrap as we want to set our own handler
this.bootstrap = checkNotNull(bootstrap, "bootstrap").clone();
this.bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
assert ch.eventLoop().inEventLoop();
handler.channelCreated(ch);
}
});
this.lastRecentUsed = lastRecentUsed;
}
代码示例来源: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
@Override
public void run() {
final Bootstrap bootstrap = ApnsChannelFactory.this.bootstrapTemplate.clone()
.channelFactory(new AugmentingReflectiveChannelFactory<>(
ClientChannelClassUtil.getSocketChannelClass(ApnsChannelFactory.this.bootstrapTemplate.config().group()),
CHANNEL_READY_PROMISE_ATTRIBUTE_KEY, channelReadyPromise));
final ChannelFuture connectFuture = bootstrap.connect();
connectFuture.addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(final ChannelFuture future) {
if (!future.isSuccess()) {
// This may seem spurious, but our goal here is to accurately report the cause of
// connection failure; if we just wait for connection closure, we won't be able to
// tell callers anything more specific about what went wrong.
tryFailureAndLogRejectedCause(channelReadyPromise, future.cause());
}
}
});
connectFuture.channel().closeFuture().addListener(new GenericFutureListener<ChannelFuture> () {
@Override
public void operationComplete(final ChannelFuture future) {
// We always want to try to fail the "channel ready" promise if the connection closes; if it has
// already succeeded, this will have no effect.
channelReadyPromise.tryFailure(
new IllegalStateException("Channel closed before HTTP/2 preface completed."));
}
});
}
}, delay, TimeUnit.SECONDS);
代码示例来源:origin: line/armeria
Bootstrap.class,
desiredProtocol -> {
final Bootstrap bootstrap = baseBootstrap.clone();
bootstrap.handler(new ChannelInitializer<Channel>() {
@Override
代码示例来源:origin: micronaut-projects/micronaut-core
private <T> Flowable<T> connectWebSocket(URI uri, MutableHttpRequest<?> request, Class<T> clientEndpointType, WebSocketBean<T> webSocketBean) {
Bootstrap bootstrap = this.bootstrap.clone();
if (webSocketBean == null) {
webSocketBean = webSocketRegistry.getWebSocket(clientEndpointType);
代码示例来源:origin: netty/netty
if (ch == null) {
Bootstrap bs = bootstrap.clone();
bs.attr(POOL_KEY, this);
ChannelFuture f = connectChannel(bs);
代码示例来源:origin: redisson/redisson
if (ch == null) {
Bootstrap bs = bootstrap.clone();
bs.attr(POOL_KEY, this);
ChannelFuture f = connectChannel(bs);
代码示例来源:origin: wildfly/wildfly
if (ch == null) {
Bootstrap bs = bootstrap.clone();
bs.attr(POOL_KEY, this);
ChannelFuture f = connectChannel(bs);
代码示例来源:origin: AsyncHttpClient/async-http-client
Bootstrap socksBootstrap = httpBootstrap.clone();
ChannelHandler httpBootstrapHandler = socksBootstrap.config().handler();
代码示例来源:origin: reactor/reactor-netty
/**
* Materialize a Bootstrap from the parent {@link UdpClient} chain to use with {@link
* #connect(Bootstrap)} or separately
*
* @return a configured {@link Bootstrap}
*/
protected Bootstrap configure() {
return DEFAULT_BOOTSTRAP.clone();
}
代码示例来源:origin: reactor/reactor-netty
/**
* Materialize a Bootstrap from the parent {@link TcpClient} chain to use with {@link
* #connect(Bootstrap)} or separately
*
* @return a configured {@link Bootstrap}
*/
public Bootstrap configure() {
return DEFAULT_BOOTSTRAP.clone();
}
代码示例来源:origin: reactor/reactor-netty
/**
* Materialize a Bootstrap from the parent {@link UdpServer} chain to use with {@link
* #bind(Bootstrap)} or separately
*
* @return a configured {@link Bootstrap}
*/
protected Bootstrap configure() {
return DEFAULT_BOOTSTRAP.clone();
}
代码示例来源:origin: io.projectreactor.netty/reactor-netty
/**
* Materialize a Bootstrap from the parent {@link UdpClient} chain to use with {@link
* #connect(Bootstrap)} or separately
*
* @return a configured {@link Bootstrap}
*/
protected Bootstrap configure() {
return DEFAULT_BOOTSTRAP.clone();
}
代码示例来源:origin: io.reactivex/rxnetty
private HttpClientImpl<I, O> newClient(ServerInfo serverInfo) {
if (null != poolBuilder) {
return new HttpClientImpl<I, O>(name, serverInfo, clientBootstrap.clone(), pipelineConfigurator, clientConfig,
clonePoolBuilder(serverInfo, poolBuilder), eventsSubject);
} else {
return new HttpClientImpl<I, O>(name, serverInfo, clientBootstrap.clone(), pipelineConfigurator, clientConfig,
channelFactory, connectionFactory, eventsSubject);
}
}
代码示例来源:origin: io.micronaut/micronaut-http-client
@Override
protected ChannelPool newPool(RequestKey key) {
Bootstrap newBootstrap = bootstrap.clone(group);
newBootstrap.remoteAddress(key.getRemoteAddress());
AbstractChannelPoolHandler channelPoolHandler = newPoolHandler(key);
return new SimpleChannelPool(
newBootstrap,
channelPoolHandler
);
}
};
内容来源于网络,如有侵权,请联系作者删除!