本文整理汇总了Java中reactor.ipc.netty.resources.PoolResources类的典型用法代码示例。如果您正苦于以下问题:Java PoolResources类的具体用法?Java PoolResources怎么用?Java PoolResources使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PoolResources类属于reactor.ipc.netty.resources包,在下文中一共展示了PoolResources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
/**
* Create a {@link ClientHttpConnector} for the given {@link ClientOptions} and
* {@link SslConfiguration}.
*
* @param options must not be {@literal null}
* @param sslConfiguration must not be {@literal null}
* @return a new {@link ClientHttpConnector}.
*/
public static ClientHttpConnector create(ClientOptions options,
SslConfiguration sslConfiguration) {
return new ReactorClientHttpConnector(builder -> {
if (hasSslConfiguration(sslConfiguration)) {
builder.sslSupport(sslContextBuilder -> {
configureSsl(sslConfiguration, sslContextBuilder);
}).poolResources(
PoolResources.elastic("vault-http-"
+ POOL_COUNTER.incrementAndGet()));
}
builder.sslHandshakeTimeout(options.getConnectionTimeout());
builder.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
Math.toIntExact(options.getConnectionTimeout().toMillis()));
});
}
示例2: disableChunkImplicit
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
public void disableChunkImplicit() throws Exception {
PoolResources p = PoolResources.fixed("test", 1);
HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(p))
.get("http://google.com/unsupportedURI",
c -> c.failOnClientError(false)
.sendHeaders())
.block(Duration.ofSeconds(30));
HttpClientResponse r2 = HttpClient.create(opts -> opts.poolResources(p))
.get("http://google.com/unsupportedURI",
c -> c.failOnClientError(false)
.sendHeaders())
.block(Duration.ofSeconds(30));
Assert.assertTrue(r.context()
.channel() == r2.context()
.channel());
Assert.assertTrue(r.status() == HttpResponseStatus.NOT_FOUND);
r.dispose();
r2.dispose();
}
示例3: contentHeader
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
public void contentHeader() throws Exception {
PoolResources fixed = PoolResources.fixed("test", 1);
HttpClientResponse r = HttpClient.create(opts -> opts.poolResources(fixed))
.get("http://google.com",
c -> c.header("content-length", "1")
.failOnClientError(false)
.sendString(Mono.just(" ")))
.block(Duration.ofSeconds(30));
HttpClientResponse r1 = HttpClient.create(opts -> opts.poolResources(fixed))
.get("http://google.com",
c -> c.header("content-length", "1")
.failOnClientError(false)
.sendString(Mono.just(" ")))
.block(Duration.ofSeconds(30));
Assert.assertTrue(r.status() == HttpResponseStatus.BAD_REQUEST);
r.dispose();
r1.dispose();
}
示例4: testIssue186
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
public void testIssue186() {
NettyContext server =
HttpServer.create(0)
.newHandler((req, res) -> res.status(200).send())
.block(Duration.ofSeconds(300));
HttpClient client =
HttpClient.create(ops -> ops.connectAddress(() -> server.address())
.poolResources(PoolResources.fixed("test", 1)));
try {
doTestIssue186(client);
doTestIssue186(client);
}
finally {
server.dispose();
}
}
示例5: nettyClientOptions
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Bean
public Consumer<? super HttpClientOptions.Builder> nettyClientOptions() {
return opts -> {
opts.poolResources(PoolResources.elastic("proxy"));
// opts.disablePool(); //TODO: why do I need this again?
};
}
示例6: getOrCreate
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
/**
* Safely check if existing resource exist and proceed to update/cleanup if new
* resources references are passed.
*
* @param ref the resources atomic reference
* @param loops the eventual new {@link LoopResources}
* @param pools the eventual new {@link PoolResources}
* @param onNew a {@link TcpResources} factory
* @param name a name for resources
* @param <T> the reified type of {@link TcpResources}
*
* @return an existing or new {@link TcpResources}
*/
protected static <T extends TcpResources> T getOrCreate(AtomicReference<T> ref,
LoopResources loops,
PoolResources pools,
BiFunction<LoopResources, PoolResources, T> onNew,
String name) {
T update;
for (; ; ) {
T resources = ref.get();
if (resources == null || loops != null || pools != null) {
update = create(resources, loops, pools, name, onNew);
if (ref.compareAndSet(resources, update)) {
if(resources != null){
if(loops != null){
resources.defaultLoops.dispose();
}
if(pools != null){
resources.defaultPools.dispose();
}
}
return update;
}
else {
update._dispose();
}
}
else {
return resources;
}
}
}
示例7: create
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
static <T extends TcpResources> T create(T previous,
LoopResources loops,
PoolResources pools,
String name,
BiFunction<LoopResources, PoolResources, T> onNew) {
if (previous == null) {
loops = loops == null ? LoopResources.create("reactor-" + name) : loops;
pools = pools == null ? PoolResources.elastic(name) : pools;
}
else {
loops = loops == null ? previous.defaultLoops : loops;
pools = pools == null ? previous.defaultPools : pools;
}
return onNew.apply(loops, pools);
}
示例8: newHandler
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
/**
* @param handler
* @param address
* @param secure
* @param onSetup
*
* @return a new Mono to connect on subscribe
*/
protected Mono<NettyContext> newHandler(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler,
InetSocketAddress address,
boolean secure,
Consumer<? super Channel> onSetup) {
final BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>>
targetHandler =
null == handler ? ChannelOperations.noopHandler() : handler;
return Mono.create(sink -> {
SocketAddress remote = address != null ? address : options.getAddress();
ChannelPool pool = null;
PoolResources poolResources = options.getPoolResources();
if (poolResources != null) {
pool = poolResources.selectOrCreate(remote, options,
doHandler(null, sink, secure, remote, null, null),
options.getLoopResources().onClient(options.preferNative()));
}
ContextHandler<SocketChannel> contextHandler =
doHandler(targetHandler, sink, secure, remote, pool, onSetup);
sink.onCancel(contextHandler);
if (pool == null) {
Bootstrap b = options.get();
b.remoteAddress(remote);
b.handler(contextHandler);
contextHandler.setFuture(b.connect());
}
else {
contextHandler.setFuture(pool.acquire());
}
});
}
示例9: testIssue196
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
@Ignore
public void testIssue196() throws Exception {
ExecutorService threadPool = Executors.newCachedThreadPool();
int testServerPort = SocketUtils.findAvailableTcpPort();
TestServer testServer = new TestServer(testServerPort);
threadPool.submit(testServer);
if(!testServer.await(10, TimeUnit.SECONDS)){
throw new IOException("Fail to start test server");
}
HttpClient client =
HttpClient.create(opt -> opt.port(testServerPort)
.poolResources(PoolResources.fixed("test", 1)));
Flux.range(0, 2)
.flatMap(i -> client.get("/205")
.flatMap(res -> res.receive()
.aggregate()
.asString()))
.blockLast(Duration.ofSeconds(100));
testServer.close();
}
示例10: redirectTests
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
private void redirectTests(String url) {
AtomicInteger counter = new AtomicInteger(1);
NettyContext server =
HttpServer.create(9999)
.newHandler((req, res) -> {
if (req.uri().contains("/login") &&
req.method().equals(HttpMethod.POST) &&
counter.getAndDecrement() > 0) {
return res.sendRedirect("http://localhost:9999" + url);
}
else {
return res.status(200)
.send();
}
})
.block(Duration.ofSeconds(30));
PoolResources pool = PoolResources.fixed("test", 1);
HttpClient client =
HttpClient.create(ops -> ops.connectAddress(() -> server.address())
.poolResources(pool));
try {
Flux.range(0, this.numberOfTests)
.concatMap(i -> client.post("/login", r -> r.followRedirect())
.flatMap(r -> r.receive()
.then()))
.blockLast(Duration.ofSeconds(30));
}
finally {
server.dispose();
}
}
示例11: userIssue
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
public void userIssue() throws Exception {
final PoolResources pool = PoolResources.fixed("local", 1);
CountDownLatch latch = new CountDownLatch(3);
Set<String> localAddresses = ConcurrentHashMap.newKeySet();
NettyContext serverContext = HttpServer.create(8080)
.newRouter(r -> r.post("/",
(req, resp) -> req.receive()
.asString()
.flatMap(data -> {
latch.countDown();
return resp.status(
200)
.send();
})))
.block();
final HttpClient client = HttpClient.create(options -> {
options.poolResources(pool);
options.connectAddress(() -> new InetSocketAddress(8080));
});
Flux.just("1", "2", "3")
.concatMap(data -> client.post("/", req -> req.sendString(Flux.just(data)))
.doOnNext(r -> r.receive()
.subscribe()))
.subscribe(response -> {
localAddresses.add(response.channel()
.localAddress()
.toString());
});
latch.await();
pool.dispose();
serverContext.dispose();
System.out.println("Local Addresses used: " + localAddresses);
}
示例12: pipelined
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
@Ignore
public void pipelined() throws Exception {
NettyContext x = TcpServer.create("localhost", 0)
.newHandler((in, out) -> out.context(c -> c.addHandlerFirst(new
HttpResponseEncoder()))
.sendObject(Flux.just(
response(),
response()))
.neverComplete())
.block(Duration.ofSeconds(30));
PoolResources pool = PoolResources.fixed("test", 1);
HttpClient.create(opts -> opts.host("localhost")
.port(x.address().getPort())
.poolResources(pool))
.get("/")
.flatMap(r -> {
r.dispose();
return Mono.just(r.status().code());
})
.log()
.block(Duration.ofSeconds(30));
try {
HttpClient.create(opts -> opts.host("localhost")
.port(x.address().getPort())
.poolResources(pool))
.get("/")
.log()
.block(Duration.ofSeconds(30));
}
catch (AbortedException ae) {
return;
}
x.dispose();
Assert.fail("Not aborted");
}
示例13: simpleTest404_1
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
@Test
public void simpleTest404_1() {
HttpClient client =
HttpClient.create(ops -> ops.host("google.com")
.port(80)
.poolResources(PoolResources.fixed("http", 1)));
doSimpleTest404(client);
doSimpleTest404(client);
}
示例14: TcpResources
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
protected TcpResources(LoopResources defaultLoops, PoolResources defaultPools) {
this.defaultLoops = defaultLoops;
this.defaultPools = defaultPools;
}
示例15: HttpResources
import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
HttpResources(LoopResources loops, PoolResources pools) {
super(loops, pools);
}