reactor.core.publisher.Mono.justOrEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(784)

本文整理了Java中reactor.core.publisher.Mono.justOrEmpty()方法的一些代码示例,展示了Mono.justOrEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.justOrEmpty()方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:justOrEmpty

Mono.justOrEmpty介绍

[英]Create a new Mono that emits the specified item if non null otherwise only emits onComplete.
[中]创建一个新的Mono,该Mono在非null时发出指定项,否则仅发出onComplete。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<? extends Principal> principal() {
  return Mono.justOrEmpty(this.principal);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<WebSession> session() {
  return Mono.justOrEmpty(this.session);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * <p>By default this simply delegates to {@link #resolveArgumentValue} for
 * synchronous resolution.
 */
@Override
default Mono<Object> resolveArgument(
    MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {
  return Mono.justOrEmpty(resolveArgumentValue(parameter, bindingContext, exchange));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<? extends Principal> principal() {
  return Mono.justOrEmpty(this.principal);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected final Mono<Object> resolveName(String name, MethodParameter param, ServerWebExchange exchange) {
  return Mono.justOrEmpty(resolveNamedValue(name, param, exchange));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<WebSession> session() {
  return Mono.justOrEmpty(this.session);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public Mono<View> resolveViewName(String viewName, Locale locale) {
    View view = this.views.get(viewName);
    return Mono.justOrEmpty(view);
  }
}

代码示例来源:origin: codecentric/spring-boot-admin

@Override
public Mono<Instance> find(InstanceId id) {
  return Mono.defer(() -> Mono.justOrEmpty(this.snapshots.get(id)));
}

代码示例来源:origin: spring-projects/spring-security

@Override
@SuppressWarnings("unchecked")
public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId, Authentication principal,
    ServerWebExchange exchange) {
  Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty");
  Assert.notNull(exchange, "exchange cannot be null");
  return exchange.getSession()
    .map(this::getAuthorizedClients)
    .flatMap(clients -> Mono.justOrEmpty((T) clients.get(clientRegistrationId)));
}

代码示例来源:origin: spring-projects/spring-security

@Override
public <T extends OAuth2AuthorizedClient> Mono<T> loadAuthorizedClient(String clientRegistrationId, String principalName) {
  Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty");
  Assert.hasText(principalName, "principalName cannot be empty");
  return (Mono<T>) getIdentifier(clientRegistrationId, principalName)
      .flatMap(identifier -> Mono.justOrEmpty(this.authorizedClients.get(identifier)));
}

代码示例来源:origin: codecentric/spring-boot-admin

@Override
public Mono<Instance> find(InstanceId id) {
  //hmm a simple reduce doesn't return empty when not found...
  return eventStore.find(id).collect((Supplier<AtomicReference<Instance>>) AtomicReference::new, (ref, event) -> {
    Instance instance = ref.get() != null ? ref.get() : Instance.create(id);
    ref.set(instance.apply(event));
  }).flatMap(ref -> Mono.justOrEmpty(ref.get()));
}

代码示例来源:origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
private <T> Mono<Void> write(T value, @Nullable MediaType contentType, ServerWebExchange exchange) {
  Publisher<T> input = Mono.justOrEmpty(value);
  ResolvableType elementType = ResolvableType.forClass(value.getClass());
  return ((HttpMessageWriter<T>) this.writer).write(
      input, elementType, contentType, exchange.getResponse(),
      Hints.from(Hints.LOG_PREFIX_HINT, exchange.getLogPrefix()));
}

代码示例来源:origin: spring-projects/spring-security

private Mono<Map<String, OAuth2AuthorizationRequest>> getStateToAuthorizationRequest(ServerWebExchange exchange, boolean create) {
  Assert.notNull(exchange, "exchange cannot be null");
  return getSessionAttributes(exchange)
    .doOnNext(sessionAttrs -> {
      if (create) {
        sessionAttrs.putIfAbsent(this.sessionAttributeName, new HashMap<String, OAuth2AuthorizationRequest>());
      }
    })
    .flatMap(sessionAttrs -> Mono.justOrEmpty(this.sessionAttrsMapStateToAuthorizationRequest(sessionAttrs)));
}

代码示例来源:origin: spring-projects/spring-security

@Override
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
  Optional<OAuth2AuthorizedClient> attribute = request.attribute(OAUTH2_AUTHORIZED_CLIENT_ATTR_NAME)
      .map(OAuth2AuthorizedClient.class::cast);
  return Mono.justOrEmpty(attribute)
      .flatMap(authorizedClient -> authorizedClient(request, next, authorizedClient))
      .map(authorizedClient -> bearer(request, authorizedClient))
      .flatMap(next::exchange)
      .switchIfEmpty(next.exchange(request));
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<Object> getHandlerInternal(ServerWebExchange exchange) {
  PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();
  Object handler;
  try {
    handler = lookupHandler(lookupPath, exchange);
  }
  catch (Exception ex) {
    return Mono.error(ex);
  }
  return Mono.justOrEmpty(handler);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public Mono<Object> resolveArgument(
    MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {
  NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
  MethodParameter nestedParameter = parameter.nestedIfOptional();
  Object resolvedName = resolveStringValue(namedValueInfo.name);
  if (resolvedName == null) {
    return Mono.error(new IllegalArgumentException(
        "Specified name must not resolve to null: [" + namedValueInfo.name + "]"));
  }
  Model model = bindingContext.getModel();
  return resolveName(resolvedName.toString(), nestedParameter, exchange)
      .flatMap(arg -> {
        if ("".equals(arg) && namedValueInfo.defaultValue != null) {
          arg = resolveStringValue(namedValueInfo.defaultValue);
        }
        arg = applyConversion(arg, namedValueInfo, parameter, bindingContext, exchange);
        handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange);
        return Mono.justOrEmpty(arg);
      })
      .switchIfEmpty(getDefaultValue(
          namedValueInfo, parameter, bindingContext, model, exchange));
}

代码示例来源:origin: spring-projects/spring-security

private Mono<OAuth2AuthorizedClient> authorizedClient(ClientRequest request, ExchangeFunction next) {
  OAuth2AuthorizedClient authorizedClientFromAttrs = oauth2AuthorizedClient(request);
  return Mono.justOrEmpty(authorizedClientFromAttrs)
      .switchIfEmpty(Mono.defer(() -> loadAuthorizedClient(request)))
      .flatMap(authorizedClient -> refreshIfNecessary(request, next, authorizedClient));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Look up a handler method for the given request.
 * @param exchange the current exchange
 */
@Override
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
  this.mappingRegistry.acquireReadLock();
  try {
    HandlerMethod handlerMethod;
    try {
      handlerMethod = lookupHandlerMethod(exchange);
    }
    catch (Exception ex) {
      return Mono.error(ex);
    }
    if (handlerMethod != null) {
      handlerMethod = handlerMethod.createWithResolvedBean();
    }
    return Mono.justOrEmpty(handlerMethod);
  }
  finally {
    this.mappingRegistry.releaseReadLock();
  }
}

代码示例来源:origin: spring-projects/spring-framework

private Mono<?> prepareAttributeMono(String attributeName, ResolvableType attributeType,
    BindingContext context, ServerWebExchange exchange) {
  Object attribute = context.getModel().asMap().get(attributeName);
  if (attribute == null) {
    attribute = findAndRemoveReactiveAttribute(context.getModel(), attributeName);
  }
  if (attribute == null) {
    return createAttribute(attributeName, attributeType.toClass(), context, exchange);
  }
  ReactiveAdapter adapterFrom = getAdapterRegistry().getAdapter(null, attribute);
  if (adapterFrom != null) {
    Assert.isTrue(!adapterFrom.isMultiValue(), "Data binding only supports single-value async types");
    return Mono.from(adapterFrom.toPublisher(attribute));
  }
  else {
    return Mono.justOrEmpty(attribute);
  }
}

代码示例来源:origin: spring-projects/spring-framework

});
return Mono.justOrEmpty(value);

相关文章

Mono类方法