本文整理了Java中reactor.core.publisher.Mono.fromSupplier()
方法的一些代码示例,展示了Mono.fromSupplier()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.fromSupplier()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:fromSupplier
[英]Create a Mono, producing its value using the provided Supplier. If the Supplier resolves to null, the resulting Mono completes empty.
[中]创建Mono,使用提供的供应商实现其价值。如果供应商解析为null,则生成的Mono将为空。
代码示例来源:origin: spring-projects/spring-framework
public Mono<WebSession> updateLastAccessTime(WebSession session) {
return Mono.fromSupplier(() -> {
Assert.isInstanceOf(InMemoryWebSession.class, session);
((InMemoryWebSession) session).updateLastAccessTime(this.clock.instant());
return session;
});
}
代码示例来源:origin: codecentric/spring-boot-admin
@Override
public Flux<Instance> findAll() {
return Mono.fromSupplier(this.snapshots::values).flatMapIterable(Function.identity());
}
代码示例来源:origin: org.springframework/spring-web
public Mono<WebSession> updateLastAccessTime(WebSession session) {
return Mono.fromSupplier(() -> {
Assert.isInstanceOf(InMemoryWebSession.class, session);
((InMemoryWebSession) session).updateLastAccessTime(this.clock.instant());
return session;
});
}
代码示例来源:origin: spring-projects/spring-security
@Override
public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId,
Authentication authentication, ServerWebExchange serverWebExchange) {
Assert.notNull(clientRegistrationId, "clientRegistrationId cannot be null");
Assert.isNull(serverWebExchange, "serverWebExchange must be null");
Assert.isTrue(isUnauthenticated(authentication), "The user " + authentication + " should not be authenticated");
return Mono.fromSupplier(() -> (T) this.clientRegistrationIdToAuthorizedClient.get(clientRegistrationId));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<WebSession> createWebSession() {
Instant now = this.clock.instant();
this.expiredSessionChecker.checkIfNecessary(now);
return Mono.fromSupplier(() -> new InMemoryWebSession(now));
}
代码示例来源:origin: org.springframework/spring-web
@Override
public Mono<WebSession> createWebSession() {
Instant now = this.clock.instant();
this.expiredSessionChecker.checkIfNecessary(now);
return Mono.fromSupplier(() -> new InMemoryWebSession(now));
}
代码示例来源:origin: codecentric/spring-boot-admin
protected Mono<ClientResponse> forward(String instanceId,
URI uri,
HttpMethod method,
HttpHeaders headers,
Supplier<BodyInserter<?, ? super ClientHttpRequest>> bodyInserter) {
log.trace("Proxy-Request for instance {} with URL '{}'", instanceId, uri);
return registry.getInstance(InstanceId.of(instanceId))
.flatMap(instance -> forward(instance, uri, method, headers, bodyInserter))
.switchIfEmpty(Mono.fromSupplier(() -> ClientResponse.create(HttpStatus.SERVICE_UNAVAILABLE, strategies).build()));
}
代码示例来源:origin: reactor/reactor-core
@Test(expected = RuntimeException.class)
public void onMonoErrorSupplierOnBlock() {
Mono.fromSupplier(() -> {
throw new RuntimeException("test");
})
.block();
}
}
代码示例来源:origin: lettuce-io/lettuce-core
private Mono<TraceContext> withTraceContext() {
return Tracing.getContext()
.switchIfEmpty(Mono.fromSupplier(() -> clientResources.tracing().initialTraceContextProvider()))
.flatMap(TraceContextProvider::getTraceContextLater).defaultIfEmpty(TraceContext.EMPTY);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void onMonoSuccessSupplierOnBlock() {
assertThat(Mono.fromSupplier(() -> "test")
.block()).isEqualToIgnoringCase("test");
}
代码示例来源:origin: spring-projects/spring-security
private Mono<OAuth2AuthorizedClient> authorizedClient(ClientRequest request, ExchangeFunction next, OAuth2AuthorizedClient authorizedClient) {
ClientRegistration clientRegistration = authorizedClient.getClientRegistration();
if (isClientCredentialsGrantType(clientRegistration) && hasTokenExpired(authorizedClient)) {
// Client credentials grant do not have refresh tokens but can expire so we need to get another one
return Mono.fromSupplier(() -> authorizeWithClientCredentials(clientRegistration, request.attributes()));
} else if (shouldRefreshToken(authorizedClient)) {
return authorizeWithRefreshToken(request, next, authorizedClient);
}
return Mono.just(authorizedClient);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Resolve the default value, if any.
*/
private Mono<Object> getDefaultValue(NamedValueInfo namedValueInfo, MethodParameter parameter,
BindingContext bindingContext, Model model, ServerWebExchange exchange) {
return Mono.fromSupplier(() -> {
Object value = null;
if (namedValueInfo.defaultValue != null) {
value = resolveStringValue(namedValueInfo.defaultValue);
}
else if (namedValueInfo.required && !parameter.isOptional()) {
handleMissingValue(namedValueInfo.name, parameter, exchange);
}
value = handleNullValue(namedValueInfo.name, value, parameter.getNestedParameterType());
value = applyConversion(value, namedValueInfo, parameter, bindingContext, exchange);
handleResolvedValue(value, namedValueInfo.name, parameter, model, exchange);
return value;
});
}
代码示例来源:origin: reactor/reactor-core
@Test
public void supplierThrows() {
StepVerifier.create(Mono.fromSupplier(() -> {
throw new RuntimeException("forced failure");
}))
.verifyErrorMessage("forced failure");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalSupplyingNull() {
StepVerifier.create(Mono.fromSupplier(() -> null))
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void supplierCancel(){
StepVerifier.create(Mono.fromSupplier(() -> "test"))
.thenCancel()
.verify();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normalSupplyingNullBackpressuredShortcuts() {
StepVerifier.create(Mono.fromSupplier(() -> null), 0)
.expectSubscription()
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void asyncSupplyingNull() {
StepVerifier.create(Mono.fromSupplier(() -> null)
.subscribeOn(Schedulers.single()), 1)
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void normal() {
AtomicInteger n = new AtomicInteger();
Mono<Integer> m = Mono.fromSupplier(n::incrementAndGet);
m.subscribeWith(AssertSubscriber.create())
.assertValues(1)
.assertComplete();
m.subscribeWith(AssertSubscriber.create())
.assertValues(2)
.assertComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void asyncSupplyingNullBackpressuredShortcuts() {
StepVerifier.create(Mono.fromSupplier(() -> null)
.subscribeOn(Schedulers.single()), 0)
.expectSubscription()
.verifyComplete();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void classic() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Mono.fromSupplier(() -> 1)
.subscribeOn(Schedulers.fromExecutorService(ForkJoinPool.commonPool()))
.subscribe(ts);
ts.await(Duration.ofSeconds(5));
ts.assertValueCount(1)
.assertNoError()
.assertComplete();
}
内容来源于网络,如有侵权,请联系作者删除!