当前位置: 首页>>代码示例>>Java>>正文


Java PoolResources类代码示例

本文整理汇总了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()));
	});
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:28,代码来源:ClientHttpConnectorFactory.java

示例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();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:HttpClientTest.java

示例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();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:22,代码来源:HttpClientTest.java

示例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();
	}

}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:HttpServerTests.java

示例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?
	};
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:8,代码来源:GatewayAutoConfiguration.java

示例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;
		}
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:44,代码来源:TcpResources.java

示例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);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:16,代码来源:TcpResources.java

示例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());
		}
	});
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:45,代码来源:TcpClient.java

示例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();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:28,代码来源:ChannelOperationsHandlerTest.java

示例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();
	}

}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:36,代码来源:HttpRedirectTest.java

示例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);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:37,代码来源:HttpClientTest.java

示例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");
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:41,代码来源:HttpClientTest.java

示例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);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:10,代码来源:HttpClientTest.java

示例14: TcpResources

import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
protected TcpResources(LoopResources defaultLoops, PoolResources defaultPools) {
	this.defaultLoops = defaultLoops;
	this.defaultPools = defaultPools;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:5,代码来源:TcpResources.java

示例15: HttpResources

import reactor.ipc.netty.resources.PoolResources; //导入依赖的package包/类
HttpResources(LoopResources loops, PoolResources pools) {
	super(loops, pools);
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:4,代码来源:HttpResources.java


注:本文中的reactor.ipc.netty.resources.PoolResources类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。