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

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

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

Mono.ofType介绍

[英]Evaluate the emitted value against the given Class type. If the value matches the type, it is passed into the new Mono. Otherwise the value is ignored.
[中]

代码示例

代码示例来源:origin: reactor/reactor-core

@Test(expected = NullPointerException.class)
public void sourceNull2() {
  Mono.just(1)
    .ofType(null);
}

代码示例来源:origin: reactor/reactor-core

@Override
public StepVerifier.Step<T> then() {
  return step.consumeSubscriptionWith(s -> {
    //the current subscription
    Scannable lowest = Scannable.from(s);
    //attempt to go back to the leftmost parent to check the Context from its perspective
    Context c = Flux.<Scannable>
        fromStream(lowest.parents())
        .ofType(CoreSubscriber.class)
        .takeLast(1)
        .singleOrEmpty()
        //no parent? must be a ScalaSubscription or similar source
        .switchIfEmpty(
            Mono.just(lowest)
              //unless it is directly a CoreSubscriber, let's try to scan the leftmost, see if it has an ACTUAL
              .map(sc -> (sc instanceof CoreSubscriber) ?
                  sc :
                  sc.scanOrDefault(Scannable.Attr.ACTUAL, Scannable.from(null)))
              //we are ultimately only interested in CoreSubscribers' Context
              .ofType(CoreSubscriber.class)
        )
        .map(CoreSubscriber::currentContext)
        //if it wasn't a CoreSubscriber (eg. custom or vanilla Subscriber) there won't be a Context
        .block();
    this.contextExpectations.accept(c);
  });
}

代码示例来源:origin: reactor/reactor-core

@Test
public void errorOfType() {
  StepVerifier.create(Mono.just(1)
              .ofType(String.class))
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void normalOfType() {
  StepVerifier.create(Mono.just(1)
              .ofType(Number.class))
        .expectNext(1)
        .verifyComplete();
}

代码示例来源:origin: com.aol.cyclops/cyclops-reactor

/**
 * @param clazz
 * @return
 * @see reactor.core.publisher.Mono#ofType(java.lang.Class)
 */
public final <U> Mono<U> ofType(Class<U> clazz) {
  return boxed.ofType(clazz);
}
/**

代码示例来源:origin: apache/servicemix-bundles

@Override
public Mono<Object> resolveArgument(MethodParameter parameter, BindingContext bindingContext,
    ServerWebExchange exchange) {
  ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
  return exchange.getPrincipal()
    .ofType(Authentication.class)
    .flatMap( a -> {
      Object p = resolvePrincipal(parameter, a.getPrincipal());
      Mono<Object> principal = Mono.justOrEmpty(p);
      return adapter == null ? principal : Mono.just(adapter.fromPublisher(principal));
    });
}

代码示例来源:origin: org.springframework.security/spring-security-webflux

@Override
public Mono<Object> resolveArgument(MethodParameter parameter, BindingContext bindingContext,
    ServerWebExchange exchange) {
  ReactiveAdapter adapter = getAdapterRegistry().getAdapter(parameter.getParameterType());
  return exchange.getPrincipal()
    .ofType(Authentication.class)
    .flatMap( a -> {
      Object p = resolvePrincipal(parameter, a.getPrincipal());
      Mono<Object> principal = Mono.justOrEmpty(p);
      return adapter == null ? principal : Mono.just(adapter.fromPublisher(principal));
    });
}

代码示例来源:origin: io.projectreactor/reactor-test

@Override
public StepVerifier.Step<T> then() {
  return step.consumeSubscriptionWith(s -> {
    //the current subscription
    Scannable lowest = Scannable.from(s);
    //attempt to go back to the leftmost parent to check the Context from its perspective
    Context c = Flux.<Scannable>
        fromStream(lowest.parents())
        .ofType(CoreSubscriber.class)
        .takeLast(1)
        .singleOrEmpty()
        //no parent? must be a ScalaSubscription or similar source
        .switchIfEmpty(
            Mono.just(lowest)
              //unless it is directly a CoreSubscriber, let's try to scan the leftmost, see if it has an ACTUAL
              .map(sc -> (sc instanceof CoreSubscriber) ?
                  sc :
                  sc.scanOrDefault(Scannable.Attr.ACTUAL, Scannable.from(null)))
              //we are ultimately only interested in CoreSubscribers' Context
              .ofType(CoreSubscriber.class)
        )
        .map(CoreSubscriber::currentContext)
        //if it wasn't a CoreSubscriber (eg. custom or vanilla Subscriber) there won't be a Context
        .block();
    this.contextExpectations.accept(c);
  });
}

相关文章

Mono类方法