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


Java Tuple2类代码示例

本文整理汇总了Java中reactor.util.function.Tuple2的典型用法代码示例。如果您正苦于以下问题:Java Tuple2类的具体用法?Java Tuple2怎么用?Java Tuple2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Tuple2类属于reactor.util.function包,在下文中一共展示了Tuple2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSslHandler

import reactor.util.function.Tuple2; //导入依赖的package包/类
/**
 * Return a new eventual {@link SslHandler}, optionally with SNI activated
 *
 * @param allocator {@link ByteBufAllocator} to allocate for packet storage
 * @param sniInfo {@link Tuple2} with hostname and port for SNI (any null will skip SNI).
 * @return a new eventual {@link SslHandler} with SNI activated
 */
public final SslHandler getSslHandler(ByteBufAllocator allocator,
		Tuple2<String, Integer> sniInfo) {
	SslContext sslContext =
			this.sslContext == null ? defaultSslContext() : this.sslContext;

	if (sslContext == null) {
		return null;
	}

	Objects.requireNonNull(allocator, "allocator");
	SslHandler sslHandler;
	if (sniInfo != null && sniInfo.getT1() != null && sniInfo.getT2() != null) {
		sslHandler = sslContext.newHandler(allocator, sniInfo.getT1(), sniInfo.getT2());
	}
	else {
		sslHandler = sslContext.newHandler(allocator);
	}
	sslHandler.setHandshakeTimeoutMillis(sslHandshakeTimeoutMillis);
	sslHandler.setCloseNotifyFlushTimeoutMillis(sslCloseNotifyFlushTimeoutMillis);
	sslHandler.setCloseNotifyReadTimeoutMillis(sslCloseNotifyReadTimeoutMillis);
	return sslHandler;
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:30,代码来源:NettyOptions.java

示例2: Lapin

import reactor.util.function.Tuple2; //导入依赖的package包/类
Lapin(ConnectionFactory connectionFactory,
      List<Tuple2<String, Integer>> addresses,
      ExecutorService executorService,
      boolean keepAlive) throws IOException {

	this.connectionFactory = connectionFactory == null ? new ConnectionFactory() : connectionFactory;
	this.keepAlive = keepAlive;

	if (addresses != null) {
		if (executorService == null) {
			refreshConnection(addresses);
		} else {
			refreshConnection(addresses, executorService);
		}
	} else {
		refreshConnection();
	}
}
 
开发者ID:smaldini,项目名称:reactor-incubator,代码行数:19,代码来源:Lapin.java

示例3: createOrAppend

import reactor.util.function.Tuple2; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static <T> ParallelFlux<T> createOrAppend(ParallelFlux<T> source, String tagName, String tagValue) {
	Objects.requireNonNull(tagName, "tagName");
	Objects.requireNonNull(tagValue, "tagValue");

	Set<Tuple2<String, String>> tags = Collections.singleton(Tuples.of(tagName, tagValue));

	if (source instanceof ParallelFluxName) {
		ParallelFluxName<T> s = (ParallelFluxName<T>) source;
		if(s.tags != null) {
			tags = new HashSet<>(tags);
			tags.addAll(s.tags);
		}
		return new ParallelFluxName<>(s.source, s.name, tags);
	}
	return new ParallelFluxName<>(source, null, tags);
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:18,代码来源:ParallelFluxName.java

示例4: tags

import reactor.util.function.Tuple2; //导入依赖的package包/类
/**
 * Visit this {@link Scannable} and its {@link #parents()} and stream all the
 * observed tags
 *
 * @return the stream of tags for this {@link Scannable} and its parents
 */
default Stream<Tuple2<String, String>> tags() {
	Stream<Tuple2<String, String>> parentTags =
			parents().flatMap(s -> s.scan(Attr.TAGS));

	Stream<Tuple2<String, String>> thisTags = scan(Attr.TAGS);

	if (thisTags == null) {
		return parentTags;
	}

	return Stream.concat(
			thisTags,
			parentTags
	);
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:22,代码来源:Scannable.java

示例5: doPut

import reactor.util.function.Tuple2; //导入依赖的package包/类
Mono<Tuple2<Integer, String>> doPut(String url, Mono<String> data) {
	Mono<Tuple2<String, Optional<Object>>> dataAndContext =
			data.zipWith(Mono.subscriberContext()
			                 .map(c -> c.getOrEmpty(HTTP_CORRELATION_ID)));

	return dataAndContext
			.<String>handle((dac, sink) -> {
				if (dac.getT2().isPresent()) {
					sink.next("PUT <" + dac.getT1() + "> sent to " + url + " with header X-Correlation-ID = " + dac.getT2().get());
				}
				else {
					sink.next("PUT <" + dac.getT1() + "> sent to " + url);
				}
				sink.complete();
			})
			.map(msg -> Tuples.of(200, msg));
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:18,代码来源:GuideTests.java

示例6: delayFirstInterval

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void delayFirstInterval() {
	Supplier<Flux<Tuple2<Long, Long>>> test = () -> Flux.interval(Duration.ofMillis(50))
                                                    .delaySequence(Duration.ofMillis(500))
                                                    .elapsed()
                                                        .take(33);

	StepVerifier.withVirtualTime(test)
	            .thenAwait(Duration.ofMillis(500 + 50))
	            .recordWith(ArrayList::new)
	            .assertNext(t2 -> assertThat(t2.getT1()).isEqualTo(550))
	            .thenAwait(Duration.ofMillis(33 * 50))
	            .thenConsumeWhile(t2 -> t2.getT1() == 50)
	            .consumeRecordedWith(record -> {
		            assertThat(record.stream().mapToLong(Tuple2::getT2))
		                      .startsWith(0L, 1L, 2L)
		                      .endsWith(30L, 31L, 32L)
		                      .isSorted()
		                      .hasSize(33);
	            })
	            .verifyComplete();
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:23,代码来源:FluxDelaySequenceTest.java

示例7: scanOperator

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void scanOperator() throws Exception {
	Tuple2<String, String> tag1 = Tuples.of("foo", "oof");
	Tuple2<String, String> tag2 = Tuples.of("bar", "rab");
	Set<Tuple2<String, String>> tags = new HashSet<>();
	tags.add(tag1);
	tags.add(tag2);

	Flux<Integer> source = Flux.range(1, 4).map(i -> i);
	FluxName<Integer> test = new FluxName<>(source, "foo", tags);

	assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source);
	assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(-1);

	assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo");

	//noinspection unchecked
	assertThat(test.scan(Scannable.Attr.TAGS)).containsExactlyInAnyOrder(tag1, tag2);
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:20,代码来源:FluxNameTest.java

示例8: publishOnAsyncDetection

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void publishOnAsyncDetection() {
 Publisher<String> a = Flux.just("a");
 Publisher<String> b = Mono.just("b");

 Flux<Tuple2<String, String>> flux =
   Flux.from(a)
       .flatMap(value -> Mono.just(value)
                             .zipWith(Mono.from(b)))
       .publishOn(Schedulers.single());

 StepVerifier.create(flux)
             .expectFusion(Fuseable.ASYNC)
             .assertNext(tuple -> {
             	Assertions.assertThat(tuple.getT1()).isEqualTo("a");
              Assertions.assertThat(tuple.getT2()).isEqualTo("b");
             })
             .verifyComplete();
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:20,代码来源:FluxPublishOnTest.java

示例9: publishOnAsyncDetectionConditional

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void publishOnAsyncDetectionConditional() {
 Publisher<String> a = Flux.just("a");
 Publisher<String> b = Mono.just("b");

 Flux<Tuple2<String, String>> flux =
   Flux.from(a)
       .flatMap(value -> Mono.just(value)
                             .zipWith(Mono.from(b)))
       .publishOn(Schedulers.single())
       .filter(t -> true);

 StepVerifier.create(flux)
             .expectFusion(Fuseable.ASYNC)
             .assertNext(tuple -> {
             	Assertions.assertThat(tuple.getT1()).isEqualTo("a");
              Assertions.assertThat(tuple.getT2()).isEqualTo("b");
             })
             .verifyComplete();
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:21,代码来源:FluxPublishOnTest.java

示例10: scanOperator

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void scanOperator() throws Exception {
	Tuple2<String, String> tag1 = Tuples.of("foo", "oof");
	Tuple2<String, String> tag2 = Tuples.of("bar", "rab");
	Set<Tuple2<String, String>> tags = new HashSet<>();
	tags.add(tag1);
	tags.add(tag2);

	Mono<Integer> source = Mono.just(1).map(i -> i);
	MonoName<Integer> test = new MonoName<>(source, "foo", tags);

	assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(source);
	assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);

	assertThat(test.scan(Scannable.Attr.NAME)).isEqualTo("foo");

	//noinspection unchecked
	assertThat(test.scan(Scannable.Attr.TAGS)).containsExactlyInAnyOrder(tag1, tag2);
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:20,代码来源:MonoNameTest.java

示例11: nextComplete

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void nextComplete() {
	List<Tuple2<Signal, Context>> signalsAndContext = new ArrayList<>();
	Mono.just(1)
	    .doOnEach(s -> signalsAndContext.add(Tuples.of(s, s.getContext())))
	    .subscriberContext(Context.of("foo", "bar"))
	    .subscribe();

	assertThat(signalsAndContext)
			.hasSize(2)
			.allSatisfy(t2 -> {
				assertThat(t2.getT1())
						.isNotNull();
				assertThat(t2.getT2().getOrDefault("foo", "baz"))
						.isEqualTo("bar");
			});

	assertThat(signalsAndContext.stream().map(t2 -> t2.getT1().getType()))
			.containsExactly(SignalType.ON_NEXT, SignalType.ON_COMPLETE);
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:21,代码来源:MonoDoOnEachTest.java

示例12: publisherOfPublishersUsesCorrectTuple

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void publisherOfPublishersUsesCorrectTuple() {
	Flux<Flux<Integer>> map = Flux.range(1, 7)
	                              .map(Flux::just);

	Flux<Tuple2> zipped = Flux.zip(map, t -> t);
	StepVerifier.create(zipped)
	            .consumeNextWith(t -> Assertions.assertThat((Iterable<?>) t)
	                                            .isEqualTo(Tuples.of(1,
			                                            2,
			                                            3,
			                                            4,
			                                            5,
			                                            6,
			                                            7))
	                                            .isExactlyInstanceOf(Tuple7.class))
	            .expectComplete()
	            .verify();
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:20,代码来源:FluxZipTest.java

示例13: nonPairWisePairWise

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void nonPairWisePairWise() {
	Flux<Tuple2<Tuple3<Integer, String, String>, String>> f =
			Flux.zip(Flux.just(1), Flux.just("test"), Flux.just("test0"))
			    .zipWith(Flux.just("test2"));

	Assert.assertTrue(f instanceof FluxZip);
	FluxZip<?, ?> s = (FluxZip<?, ?>) f;
	Assert.assertTrue(s.sources != null);
	Assert.assertTrue(s.sources.length == 2);

	Flux<Tuple2<Integer, String>> ff = f.map(t -> Tuples.of(t.getT1()
	                                                         .getT1(),
			t.getT1()
			 .getT2() + t.getT2()));

	ff.subscribeWith(AssertSubscriber.create())
	  .assertValues(Tuples.of(1, "testtest2"))
	  .assertComplete();
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:21,代码来源:FluxZipTest.java

示例14: pairWise3

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void pairWise3() {
	AtomicLong ref = new AtomicLong();
	Flux<Tuple2<Tuple2<Integer, String>, String>> f =
			Flux.zip(Flux.just(1), Flux.just("test"))
			    .zipWith(Flux.just("test2")
			                 .hide()
			                 .doOnRequest(ref::set), 1);

	Assert.assertTrue(f instanceof FluxZip);
	FluxZip<?, ?> s = (FluxZip<?, ?>) f;
	Assert.assertTrue(s.sources != null);
	Assert.assertTrue(s.sources.length == 2);

	Flux<Tuple2<Integer, String>> ff = f.map(t -> Tuples.of(t.getT1()
	                                                         .getT1(),
			t.getT1()
			 .getT2() + t.getT2()));

	ff.subscribeWith(AssertSubscriber.create())
	  .assertValues(Tuples.of(1, "testtest2"))
	  .assertComplete();
	Assert.assertTrue(ref.get() == 1);
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:25,代码来源:FluxZipTest.java

示例15: pairWise2

import reactor.util.function.Tuple2; //导入依赖的package包/类
@Test
public void pairWise2() {
	Flux<Tuple2<Tuple2<Integer, String>, String>> f =
			Flux.zip(Arrays.asList(Flux.just(1), Flux.just("test")),
					obj -> Tuples.of((int) obj[0], (String) obj[1]))
			    .zipWith(Flux.just("test2"));

	Assert.assertTrue(f instanceof FluxZip);
	FluxZip<?, ?> s = (FluxZip<?, ?>) f;
	Assert.assertTrue(s.sources != null);
	Assert.assertTrue(s.sources.length == 2);

	Flux<Tuple2<Integer, String>> ff = f.map(t -> Tuples.of(t.getT1()
	                                                         .getT1(),
			t.getT1()
			 .getT2() + t.getT2()));

	ff.subscribeWith(AssertSubscriber.create())
	  .assertValues(Tuples.of(1, "testtest2"))
	  .assertComplete();
}
 
开发者ID:reactor,项目名称:reactor-core,代码行数:22,代码来源:FluxZipTest.java


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